forked from Mirrorlandia_minetest/minetest
Convert CraftItems directly to the name pointed by alias; necessary due to lua definition table
This commit is contained in:
parent
2b8b2a4f30
commit
4ad8891e05
@ -88,12 +88,7 @@ public:
|
|||||||
virtual const CraftItemDefinition* getCraftItemDefinition(const std::string &itemname_) const
|
virtual const CraftItemDefinition* getCraftItemDefinition(const std::string &itemname_) const
|
||||||
{
|
{
|
||||||
// Convert name according to possible alias
|
// Convert name according to possible alias
|
||||||
std::string itemname = itemname_;
|
std::string itemname = getAlias(itemname_);
|
||||||
std::map<std::string, std::string>::const_iterator i;
|
|
||||||
i = m_aliases.find(itemname);
|
|
||||||
if(i != m_aliases.end()){
|
|
||||||
itemname = i->second;
|
|
||||||
}
|
|
||||||
// Get the definition
|
// Get the definition
|
||||||
core::map<std::string, CraftItemDefinition*>::Node *n;
|
core::map<std::string, CraftItemDefinition*>::Node *n;
|
||||||
n = m_item_definitions.find(itemname);
|
n = m_item_definitions.find(itemname);
|
||||||
@ -108,6 +103,14 @@ public:
|
|||||||
return "";
|
return "";
|
||||||
return def->imagename;
|
return def->imagename;
|
||||||
}
|
}
|
||||||
|
virtual std::string getAlias(const std::string &name) const
|
||||||
|
{
|
||||||
|
std::map<std::string, std::string>::const_iterator i;
|
||||||
|
i = m_aliases.find(name);
|
||||||
|
if(i != m_aliases.end())
|
||||||
|
return i->second;
|
||||||
|
return name;
|
||||||
|
}
|
||||||
virtual bool registerCraftItem(std::string itemname, const CraftItemDefinition &def)
|
virtual bool registerCraftItem(std::string itemname, const CraftItemDefinition &def)
|
||||||
{
|
{
|
||||||
infostream<<"registerCraftItem: registering CraftItem \""<<itemname<<"\""<<std::endl;
|
infostream<<"registerCraftItem: registering CraftItem \""<<itemname<<"\""<<std::endl;
|
||||||
|
@ -49,6 +49,7 @@ public:
|
|||||||
virtual ~ICraftItemDefManager(){}
|
virtual ~ICraftItemDefManager(){}
|
||||||
virtual const CraftItemDefinition* getCraftItemDefinition(const std::string &itemname) const=0;
|
virtual const CraftItemDefinition* getCraftItemDefinition(const std::string &itemname) const=0;
|
||||||
virtual std::string getImagename(const std::string &itemname) const =0;
|
virtual std::string getImagename(const std::string &itemname) const =0;
|
||||||
|
virtual std::string getAlias(const std::string &name) const =0;
|
||||||
|
|
||||||
virtual void serialize(std::ostream &os)=0;
|
virtual void serialize(std::ostream &os)=0;
|
||||||
};
|
};
|
||||||
|
@ -354,6 +354,15 @@ bool ToolItem::isKnown() const
|
|||||||
CraftItem
|
CraftItem
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
CraftItem::CraftItem(IGameDef *gamedef, std::string subname, u16 count):
|
||||||
|
InventoryItem(gamedef, count)
|
||||||
|
{
|
||||||
|
// Convert directly to the correct name through aliases.
|
||||||
|
// This is necessary because CraftItem callbacks are stored in
|
||||||
|
// Lua refenced by their correct name
|
||||||
|
m_subname = gamedef->cidef()->getAlias(subname);
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef SERVER
|
#ifndef SERVER
|
||||||
video::ITexture * CraftItem::getImage() const
|
video::ITexture * CraftItem::getImage() const
|
||||||
{
|
{
|
||||||
|
@ -238,11 +238,7 @@ private:
|
|||||||
class CraftItem : public InventoryItem
|
class CraftItem : public InventoryItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CraftItem(IGameDef *gamedef, std::string subname, u16 count):
|
CraftItem(IGameDef *gamedef, std::string subname, u16 count);
|
||||||
InventoryItem(gamedef, count)
|
|
||||||
{
|
|
||||||
m_subname = subname;
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
Implementation interface
|
Implementation interface
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user