From 4ad8891e0586f60a642675cc4d04edc3cd84650b Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 4 Dec 2011 01:16:22 +0200 Subject: [PATCH] Convert CraftItems directly to the name pointed by alias; necessary due to lua definition table --- src/craftitemdef.cpp | 15 +++++++++------ src/craftitemdef.h | 1 + src/inventory.cpp | 9 +++++++++ src/inventory.h | 6 +----- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/craftitemdef.cpp b/src/craftitemdef.cpp index 8d4cbea3..4461e38a 100644 --- a/src/craftitemdef.cpp +++ b/src/craftitemdef.cpp @@ -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::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::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::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 \""<cidef()->getAlias(subname); +} + #ifndef SERVER video::ITexture * CraftItem::getImage() const { diff --git a/src/inventory.h b/src/inventory.h index 3f3c5435..57af3765 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -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 */ -- 2.30.2