1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Node definition aliases

This commit is contained in:
Perttu Ahola 2011-12-03 23:50:31 +02:00
parent 6a5829788e
commit 4b00d4d9d2
5 changed files with 108 additions and 2 deletions

View file

@ -398,8 +398,18 @@ public:
{
return get(n.getContent());
}
virtual bool getId(const std::string &name, content_t &result) const
virtual bool getId(const std::string &name_, content_t &result) const
{
std::string name = name_;
// Convert name according to possible alias
std::map<std::string, std::string>::const_iterator i;
i = m_aliases.find(name);
if(i != m_aliases.end()){
/*infostream<<"ndef: alias active: "<<name<<" -> "<<i->second
<<std::endl;*/
name = i->second;
}
// Get id
return m_name_id_mapping.getId(name, result);
}
virtual content_t getId(const std::string &name) const
@ -438,6 +448,12 @@ public:
m_content_features[c] = def;
if(def.name != "")
m_name_id_mapping.set(c, def.name);
// Remove conflicting alias if it exists
bool alias_removed = (m_aliases.erase(def.name) != 0);
if(alias_removed)
infostream<<"ndef: erased alias "<<def.name
<<" because node was defined"<<std::endl;
}
virtual content_t set(const std::string &name,
const ContentFeatures &def)
@ -476,6 +492,19 @@ public:
f.material.diggability = DIGGABLE_NORMAL;
return set(name, f);
}
virtual void setAlias(const std::string &name,
const std::string &convert_to)
{
content_t id;
if(getId(name, id)){
infostream<<"ndef: not setting alias "<<name<<" -> "<<convert_to
<<": "<<name<<" is already defined"<<std::endl;
return;
}
infostream<<"ndef: setting alias "<<name<<" -> "<<convert_to
<<std::endl;
m_aliases[name] = convert_to;
}
virtual void updateTextures(ITextureSource *tsrc)
{
#ifndef SERVER
@ -639,8 +668,12 @@ public:
}
}
private:
// Features indexed by id
ContentFeatures m_content_features[MAX_CONTENT+1];
// A mapping for fast converting back and forth between names and ids
NameIdMapping m_name_id_mapping;
// Aliases for loading legacy crap
std::map<std::string, std::string> m_aliases;
};
IWritableNodeDefManager* createNodeDefManager()