Tooltips: Unify the tooltip[] and list[] description tooltip display functions (...
[oweals/minetest.git] / src / nodemetadata.h
index acd45bdf9bde4f3b7c85a6029a84bb536bfe7c01..0d72485bcc8a0cca0399e987287596215440b29f 100644 (file)
@@ -20,11 +20,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #ifndef NODEMETADATA_HEADER
 #define NODEMETADATA_HEADER
 
-#include "irr_v3d.h"
-#include <string>
-#include <iostream>
-#include <vector>
-#include <map>
+#include "metadata.h"
+#include "util/cpp11_container.h"
 
 /*
        NodeMetadata stores arbitary amounts of data for special blocks.
@@ -36,38 +33,37 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 */
 
 class Inventory;
-class IGameDef;
+class IItemDefManager;
 
-class NodeMetadata
+class NodeMetadata : public Metadata
 {
 public:
-       NodeMetadata(IGameDef *gamedef);
+       NodeMetadata(IItemDefManager *item_def_mgr);
        ~NodeMetadata();
 
-       void serialize(std::ostream &os) const;
-       void deSerialize(std::istream &is);
+       void serialize(std::ostream &os, u8 version, bool disk=true) const;
+       void deSerialize(std::istream &is, u8 version);
 
        void clear();
+       bool empty() const;
 
-       // Generic key/value store
-       std::string getString(const std::string &name, unsigned short recursion = 0) const;
-       void setString(const std::string &name, const std::string &var);
-       // Support variable names in values
-       std::string resolveString(const std::string &str, unsigned short recursion = 0) const;
-       std::map<std::string, std::string> getStrings() const
+       // The inventory
+       Inventory *getInventory()
        {
-               return m_stringvars;
+               return m_inventory;
        }
 
-       // The inventory
-       Inventory* getInventory()
+       inline bool isPrivate(const std::string &name) const
        {
-               return m_inventory;
+               return m_privatevars.count(name) != 0;
        }
+       void markPrivate(const std::string &name, bool set);
 
 private:
-       std::map<std::string, std::string> m_stringvars;
+       int countNonPrivate() const;
+
        Inventory *m_inventory;
+       UNORDERED_SET<std::string> m_privatevars;
 };
 
 
@@ -80,8 +76,8 @@ class NodeMetadataList
 public:
        ~NodeMetadataList();
 
-       void serialize(std::ostream &os) const;
-       void deSerialize(std::istream &is, IGameDef *gamedef);
+       void serialize(std::ostream &os, u8 blockver, bool disk=true) const;
+       void deSerialize(std::istream &is, IItemDefManager *item_def_mgr);
 
        // Add all keys in this list to the vector keys
        std::vector<v3s16> getAllKeys();
@@ -95,8 +91,9 @@ public:
        void clear();
 
 private:
+       int countNonEmpty() const;
+
        std::map<v3s16, NodeMetadata *> m_data;
 };
 
 #endif
-