From c4315a7afafcc9adff945b5e63800340f6c2c008 Mon Sep 17 00:00:00 2001 From: darkrose Date: Fri, 1 Jun 2012 23:10:53 +1000 Subject: [PATCH] Strip unneeded variables from NodeMetadata --- src/content_nodemeta.cpp | 16 +++++++------- src/game.cpp | 41 +++++++++++++++------------------- src/nodemetadata.cpp | 18 +-------------- src/nodemetadata.h | 46 -------------------------------------- src/scriptapi.cpp | 48 ++++++++-------------------------------- 5 files changed, 36 insertions(+), 133 deletions(-) diff --git a/src/content_nodemeta.cpp b/src/content_nodemeta.cpp index 1ade1ee7..18690612 100644 --- a/src/content_nodemeta.cpp +++ b/src/content_nodemeta.cpp @@ -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;]" diff --git a/src/game.cpp b/src/game.cpp index 8440801b..69fc601c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -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"<getString("formspec") == "hack:sign_text_input" && !random_input) + { + infostream<<"Launching metadata text input"<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"<getInventoryDrawSpecString() != "" && !random_input) + else if(meta && meta->getString("formspec") != "" && !random_input) { infostream<<"Launching custom inventory view"<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"<getText()); - - (new GUITextInputMenu(guienv, guiroot, -1, - &g_menumgr, dest, - wtext))->drop(); - } - #else - if(0) /* do nothing */; - #endif // Otherwise report right click to server else { diff --git a/src/nodemetadata.cpp b/src/nodemetadata.cpp index c76ad1f4..0b63d777 100644 --- a/src/nodemetadata.cpp +++ b/src/nodemetadata.cpp @@ -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<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; } /* diff --git a/src/nodemetadata.h b/src/nodemetadata.h index 7fe5e2f5..e855eab9 100644 --- a/src/nodemetadata.h +++ b/src/nodemetadata.h @@ -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 m_stringvars; Inventory *m_inventory; - std::string m_inventorydrawspec; - std::string m_formspec; - std::string m_infotext; - bool m_allow_removal; }; diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 72a47308..07f8fda0 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -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} };