Strip unneeded variables from NodeMetadata
parent
704782c95b
commit
c4315a7afa
|
@ -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;]"
|
||||
|
|
41
src/game.cpp
41
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"<<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
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue