Strip unneeded variables from NodeMetadata
authordarkrose <lisa@ltmnet.com>
Fri, 1 Jun 2012 13:10:53 +0000 (23:10 +1000)
committerPerttu Ahola <celeron55@gmail.com>
Sun, 3 Jun 2012 19:31:00 +0000 (22:31 +0300)
src/content_nodemeta.cpp
src/game.cpp
src/nodemetadata.cpp
src/nodemetadata.h
src/scriptapi.cpp

index 1ade1ee76f12691f0a244d81798ae719d4be3abf..18690612d497ed611b71b802b9fd02c26337f268 100644 (file)
@@ -40,10 +40,10 @@ static bool content_nodemeta_deserialize_legacy_body(
                deSerializeLongString(is);  // m_text
                deSerializeString(is);  // m_owner
 
-               meta->setInfoText(deSerializeString(is));
-               meta->setInventoryDrawSpec(deSerializeString(is));
+               meta->setString("infotext",deSerializeString(is));
+               meta->setString("formspec",deSerializeString(is));
                readU8(is);  // m_allow_text_input
-               meta->setAllowRemoval(readU8(is) == 0);
+               readU8(is);  // m_allow_removal
                readU8(is);  // m_enforce_owner
 
                int num_vars = readU32(is);
@@ -57,14 +57,14 @@ static bool content_nodemeta_deserialize_legacy_body(
        else if(id == NODEMETA_SIGN) // SignNodeMetadata
        {
                meta->setString("text", deSerializeLongString(is));
-               meta->setInfoText("\"${text}\"");
-               meta->setFormSpec("field[text;;${text}]");
+               meta->setString("infotext","\"${text}\"");
+               meta->setString("formspec","field[text;;${text}]");
                return false;
        }
        else if(id == NODEMETA_CHEST) // ChestNodeMetadata
        {
                meta->getInventory()->deSerialize(is);
-               meta->setInventoryDrawSpec("invsize[8,9;]"
+               meta->setString("formspec","invsize[8,9;]"
                                "list[current_name;0;0,0;8,4;]"
                                "list[current_player;main;0,5;8,4;]");
                return false;
@@ -73,7 +73,7 @@ static bool content_nodemeta_deserialize_legacy_body(
        {
                meta->setString("owner", deSerializeString(is));
                meta->getInventory()->deSerialize(is);
-               meta->setInventoryDrawSpec("invsize[8,9;]"
+               meta->setString("formspec","invsize[8,9;]"
                                "list[current_name;0;0,0;8,4;]"
                                "list[current_player;main;0,5;8,4;]");
                return false;
@@ -94,7 +94,7 @@ static bool content_nodemeta_deserialize_legacy_body(
                is>>temp;
                meta->setString("src_time", ftos((float)temp/10));
 
-               meta->setInventoryDrawSpec("invsize[8,9;]"
+               meta->setString("formspec","invsize[8,9;]"
                        "list[current_name;fuel;2,3;1,1;]"
                        "list[current_name;src;2,1;1,1;]"
                        "list[current_name;dst;5,1;2,2;]"
index 8440801b72a44174ccccd39ae3275a9bfce69c56..69fc601c3815dcd76d849d3c3ca0f365104929a0 100644 (file)
@@ -2195,7 +2195,7 @@ void the_game(
                        ClientMap &map = client.getEnv().getClientMap();
                        NodeMetadata *meta = map.getNodeMetadata(nodepos);
                        if(meta){
-                               infotext = narrow_to_wide(meta->getInfoText());
+                               infotext = narrow_to_wide(meta->getString("infotext"));
                        } else {
                                MapNode n = map.getNode(nodepos);
                                if(nodedef->get(n).tname_tiles[0] == "unknown_block.png"){
@@ -2320,10 +2320,23 @@ void the_game(
                        {
                                infostream<<"Ground right-clicked"<<std::endl;
                                
+                               // sign special case, at least until formspec is properly implemented
+                               if(meta && meta->getString("formspec") == "hack:sign_text_input" && !random_input)
+                               {
+                                       infostream<<"Launching metadata text input"<<std::endl;
+                                       
+                                       // Get a new text for it
+
+                                       TextDest *dest = new TextDestNodeMetadata(nodepos, &client);
+
+                                       std::wstring wtext = narrow_to_wide(meta->getString("text"));
+
+                                       (new GUITextInputMenu(guienv, guiroot, -1,
+                                                       &g_menumgr, dest,
+                                                       wtext))->drop();
+                               }
                                // If metadata provides an inventory view, activate it
-                               errorstream<<"Need to implement metadata formspecs"<<std::endl;
-                               #if 0
-                               if(meta && meta->getInventoryDrawSpecString() != "" && !random_input)
+                               else if(meta && meta->getString("formspec") != "" && !random_input)
                                {
                                        infostream<<"Launching custom inventory view"<<std::endl;
 
@@ -2339,7 +2352,7 @@ void the_game(
                                        v2s16 invsize =
                                                GUIInventoryMenu::makeDrawSpecArrayFromString(
                                                        draw_spec,
-                                                       meta->getInventoryDrawSpecString(),
+                                                       meta->getString("formspec"),
                                                        inventoryloc);
 
                                        GUIInventoryMenu *menu =
@@ -2349,24 +2362,6 @@ void the_game(
                                        menu->setDrawSpec(draw_spec);
                                        menu->drop();
                                }
-                               // If metadata provides text input, activate text input
-                               else if(meta && meta->allowsTextInput() && !random_input)
-                               {
-                                       infostream<<"Launching metadata text input"<<std::endl;
-                                       
-                                       // Get a new text for it
-
-                                       TextDest *dest = new TextDestNodeMetadata(nodepos, &client);
-
-                                       std::wstring wtext = narrow_to_wide(meta->getText());
-
-                                       (new GUITextInputMenu(guienv, guiroot, -1,
-                                                       &g_menumgr, dest,
-                                                       wtext))->drop();
-                               }
-                               #else
-                               if(0) /* do nothing */;
-                               #endif
                                // Otherwise report right click to server
                                else
                                {
index c76ad1f4be4054ee02ab826c8edf8e1367a55fb5..0b63d7779c6fe56d2946c50d393aadb86e68f2e7 100644 (file)
@@ -31,11 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 NodeMetadata::NodeMetadata(IGameDef *gamedef):
        m_stringvars(),
-       m_inventory(new Inventory(gamedef->idef())),
-       m_inventorydrawspec(""),
-       m_formspec(""),
-       m_infotext(""),
-       m_allow_removal(true)
+       m_inventory(new Inventory(gamedef->idef()))
 {
 }
 
@@ -55,10 +51,6 @@ void NodeMetadata::serialize(std::ostream &os) const
        }
 
        m_inventory->serialize(os);
-       os<<serializeString(m_inventorydrawspec);
-       os<<serializeString(m_formspec);
-       os<<serializeString(m_infotext);
-       writeU8(os, m_allow_removal);
 }
 
 void NodeMetadata::deSerialize(std::istream &is)
@@ -72,20 +64,12 @@ void NodeMetadata::deSerialize(std::istream &is)
        }
 
        m_inventory->deSerialize(is);
-       m_inventorydrawspec = deSerializeString(is);
-       m_formspec = deSerializeString(is);
-       m_infotext = deSerializeString(is);
-       m_allow_removal = readU8(is);
 }
 
 void NodeMetadata::clear()
 {
        m_stringvars.clear();
        m_inventory->clear();
-       m_inventorydrawspec = "";
-       m_formspec = "";
-       m_infotext = "";
-       m_allow_removal = true;
 }
 
 /*
index 7fe5e2f504ee0c8c9cf4ce6212d106302e60f4df..e855eab9b4c3fa6a6d94beb0086548aabcfc90ec 100644 (file)
@@ -70,56 +70,10 @@ public:
        {
                return m_inventory;
        }
-       
-       // If non-empty, player can interact by using an inventory view
-       // See format in guiInventoryMenu.cpp.
-       std::string getInventoryDrawSpec() const
-       {
-               return m_inventorydrawspec;
-       }
-       void setInventoryDrawSpec(const std::string &text)
-       {
-               m_inventorydrawspec = text;
-       }
-       
-       // If non-empty, player can interact by using an form view
-       // See format in guiFormMenu.cpp.
-       std::string getFormSpec() const
-       {
-               return m_formspec;
-       }
-       void setFormSpec(const std::string &text)
-       {
-               m_formspec = text;
-       }
-       
-       // Called on client-side; shown on screen when pointed at
-       std::string getInfoText() const
-       {
-               return m_infotext;
-       }
-       void setInfoText(const std::string &text)
-       {
-               m_infotext = text;
-       }
-       
-       // Whether the related node and this metadata can be removed
-       bool getAllowRemoval() const
-       {
-               return m_allow_removal;
-       }
-       void setAllowRemoval(bool b)
-       {
-               m_allow_removal = b;
-       }
 
 private:
        std::map<std::string, std::string> m_stringvars;
        Inventory *m_inventory;
-       std::string m_inventorydrawspec;
-       std::string m_formspec;
-       std::string m_infotext;
-       bool m_allow_removal;
 };
 
 
index 72a47308341caf8b27dc80ba518ce5f8aa5fca16..07f8fda0d29e1fffbeb97bec5a3b62b3d9a2f809 100644 (file)
@@ -2098,7 +2098,7 @@ private:
                        lua_pushlstring(L, "", 0);
                        return 1;
                }
-               std::string str = meta->getInventoryDrawSpec();
+               std::string str = meta->getString("formspec");
                lua_pushlstring(L, str.c_str(), str.size());
                return 1;
        }
@@ -2112,9 +2112,9 @@ private:
                std::string str(s, len);
 
                NodeMetadata *meta = getmeta(ref, !str.empty());
-               if(meta == NULL || str == meta->getInventoryDrawSpec())
+               if(meta == NULL || str == meta->getString("formspec"))
                        return 0;
-               meta->setInventoryDrawSpec(str);
+               meta->setString("formspec",str);
                reportMetadataChange(ref);
                return 0;
        }
@@ -2129,7 +2129,7 @@ private:
                        lua_pushlstring(L, "", 0);
                        return 1;
                }
-               std::string str = meta->getFormSpec();
+               std::string str = meta->getString("formspec");
                lua_pushlstring(L, str.c_str(), str.size());
                return 1;
        }
@@ -2143,9 +2143,9 @@ private:
                std::string str(s, len);
 
                NodeMetadata *meta = getmeta(ref, !str.empty());
-               if(meta == NULL || str == meta->getFormSpec())
+               if(meta == NULL || str == meta->getString("formspec"))
                        return 0;
-               meta->setFormSpec(str);
+               meta->setString("formspec",str);
                reportMetadataChange(ref);
                return 0;
        }
@@ -2160,7 +2160,7 @@ private:
                        lua_pushlstring(L, "", 0);
                        return 1;
                }
-               std::string str = meta->getInfoText();
+               std::string str = meta->getString("infotext");
                lua_pushlstring(L, str.c_str(), str.size());
                return 1;
        }
@@ -2174,37 +2174,9 @@ private:
                std::string str(s, len);
 
                NodeMetadata *meta = getmeta(ref, !str.empty());
-               if(meta == NULL || str == meta->getInfoText())
+               if(meta == NULL || str == meta->getString("infotext"))
                        return 0;
-               meta->setInfoText(str);
-               reportMetadataChange(ref);
-               return 0;
-       }
-
-       // get_allow_removal(self)
-       static int l_get_allow_removal(lua_State *L)
-       {
-               NodeMetaRef *ref = checkobject(L, 1);
-
-               NodeMetadata *meta = getmeta(ref, false);
-               if(meta == NULL){
-                       lua_pushboolean(L, true);
-                       return 1;
-               }
-               lua_pushboolean(L, meta->getAllowRemoval());
-               return 1;
-       }
-
-       // set_allow_removal(self, flag)
-       static int l_set_allow_removal(lua_State *L)
-       {
-               NodeMetaRef *ref = checkobject(L, 1);
-               bool flag = lua_toboolean(L, 2);
-
-               NodeMetadata *meta = getmeta(ref, flag != true);
-               if(meta == NULL || flag == meta->getAllowRemoval())
-                       return 0;
-               meta->setAllowRemoval(flag);
+               meta->setString("infotext",str);
                reportMetadataChange(ref);
                return 0;
        }
@@ -2274,8 +2246,6 @@ const luaL_reg NodeMetaRef::methods[] = {
        method(NodeMetaRef, set_form_spec),
        method(NodeMetaRef, get_infotext),
        method(NodeMetaRef, set_infotext),
-       method(NodeMetaRef, get_allow_removal),
-       method(NodeMetaRef, set_allow_removal),
        {0,0}
 };