nodemetadata.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #ifndef NODEMETADATA_HEADER
  17. #define NODEMETADATA_HEADER
  18. #include "irr_v3d.h"
  19. #include <string>
  20. #include <iostream>
  21. #include <map>
  22. /*
  23. NodeMetadata stores arbitary amounts of data for special blocks.
  24. Used for furnaces, chests and signs.
  25. There are two interaction methods: inventory menu and text input.
  26. Only one can be used for a single metadata, thus only inventory OR
  27. text input should exist in a metadata.
  28. */
  29. class Inventory;
  30. class IGameDef;
  31. class NodeMetadata
  32. {
  33. public:
  34. NodeMetadata(IGameDef *gamedef);
  35. ~NodeMetadata();
  36. void serialize(std::ostream &os) const;
  37. void deSerialize(std::istream &is);
  38. void clear();
  39. // Generic key/value store
  40. std::string getString(const std::string &name, unsigned short recursion = 0) const;
  41. void setString(const std::string &name, const std::string &var);
  42. // Support variable names in values
  43. std::string resolveString(const std::string &str, unsigned short recursion = 0) const;
  44. std::map<std::string, std::string> getStrings() const
  45. {
  46. return m_stringvars;
  47. }
  48. // The inventory
  49. Inventory* getInventory()
  50. {
  51. return m_inventory;
  52. }
  53. private:
  54. std::map<std::string, std::string> m_stringvars;
  55. Inventory *m_inventory;
  56. };
  57. /*
  58. List of metadata of all the nodes of a block
  59. */
  60. class NodeMetadataList
  61. {
  62. public:
  63. ~NodeMetadataList();
  64. void serialize(std::ostream &os) const;
  65. void deSerialize(std::istream &is, IGameDef *gamedef);
  66. // Get pointer to data
  67. NodeMetadata* get(v3s16 p);
  68. // Deletes data
  69. void remove(v3s16 p);
  70. // Deletes old data and sets a new one
  71. void set(v3s16 p, NodeMetadata *d);
  72. // Deletes all
  73. void clear();
  74. private:
  75. std::map<v3s16, NodeMetadata*> m_data;
  76. };
  77. #endif