Convert CraftItems directly to the name pointed by alias; necessary due to lua defini...
authorPerttu Ahola <celeron55@gmail.com>
Sat, 3 Dec 2011 23:16:22 +0000 (01:16 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Sat, 3 Dec 2011 23:16:22 +0000 (01:16 +0200)
src/craftitemdef.cpp
src/craftitemdef.h
src/inventory.cpp
src/inventory.h

index 8d4cbea3c45ba6d876bb221620b6ceb9d58a6449..4461e38a73d59cac097ba5c2113214754ba40b64 100644 (file)
@@ -88,12 +88,7 @@ public:
        virtual const CraftItemDefinition* getCraftItemDefinition(const std::string &itemname_) const
        {
                // Convert name according to possible alias
-               std::string itemname = itemname_;
-               std::map<std::string, std::string>::const_iterator i;
-               i = m_aliases.find(itemname);
-               if(i != m_aliases.end()){
-                       itemname = i->second;
-               }
+               std::string itemname = getAlias(itemname_);
                // Get the definition
                core::map<std::string, CraftItemDefinition*>::Node *n;
                n = m_item_definitions.find(itemname);
@@ -108,6 +103,14 @@ public:
                        return "";
                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)
        {
                infostream<<"registerCraftItem: registering CraftItem \""<<itemname<<"\""<<std::endl;
index ee3d97aecb75c4c47bd8b9abb4963ea9dc4aaaf7..b5d4b9348c0d73501b372e09bcbbae14d7242b54 100644 (file)
@@ -49,6 +49,7 @@ public:
        virtual ~ICraftItemDefManager(){}
        virtual const CraftItemDefinition* getCraftItemDefinition(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;
 };
index a913430e6a060d2ebf028e7d7286405dac6d07e2..e9600ece5c66733c66a9e0535ebf1e0ec89b3e77 100644 (file)
@@ -354,6 +354,15 @@ bool ToolItem::isKnown() const
        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
 video::ITexture * CraftItem::getImage() const
 {
index 3f3c5435b4cc5e10da98c1c6b93026209dc6e519..57af376501b4d5fec503518bf815cf0afaa7cc19 100644 (file)
@@ -238,11 +238,7 @@ private:
 class CraftItem : public InventoryItem
 {
 public:
-       CraftItem(IGameDef *gamedef, std::string subname, u16 count):
-               InventoryItem(gamedef, count)
-       {
-               m_subname = subname;
-       }
+       CraftItem(IGameDef *gamedef, std::string subname, u16 count);
        /*
                Implementation interface
        */