From 284acf8f76bd2201bd64b847a2564206f77a4278 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 3 Jul 2014 14:43:03 +0300 Subject: Move item type mapping into separate file. --- src/resources/db/itemdb.cpp | 75 +++++---------------------------------------- 1 file changed, 8 insertions(+), 67 deletions(-) (limited to 'src/resources/db') diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp index c41fc07a5..f40fdbbd6 100644 --- a/src/resources/db/itemdb.cpp +++ b/src/resources/db/itemdb.cpp @@ -29,6 +29,7 @@ #include "resources/beingcommon.h" #include "resources/iteminfo.h" +#include "resources/itemtypemapdata.h" #include "resources/spritedirection.h" #include "resources/spritereference.h" @@ -114,75 +115,15 @@ void ItemDB::setStatsList(const std::vector &stats) static ItemType::Type itemTypeFromString(const std::string &name) { - if (name == "generic" || name == "other") + const size_t sz = sizeof(itemTypeMap) / sizeof(itemTypeMap[0]); + for (size_t f = 0; f < sz; f ++) { - return ItemType::UNUSABLE; - } - else if (name == "usable") - { - return ItemType::USABLE; - } - else if (name == "equip-1hand") - { - return ItemType::EQUIPMENT_ONE_HAND_WEAPON; - } - else if (name == "equip-2hand") - { - return ItemType::EQUIPMENT_TWO_HANDS_WEAPON; - } - else if (name == "equip-torso") - { - return ItemType::EQUIPMENT_TORSO; - } - else if (name == "equip-arms") - { - return ItemType::EQUIPMENT_ARMS; - } - else if (name == "equip-head") - { - return ItemType::EQUIPMENT_HEAD; - } - else if (name == "equip-legs") - { - return ItemType::EQUIPMENT_LEGS; - } - else if (name == "equip-shield") - { - return ItemType::EQUIPMENT_SHIELD; - } - else if (name == "equip-ring") - { - return ItemType::EQUIPMENT_RING; - } - else if (name == "equip-charm") - { - return ItemType::EQUIPMENT_CHARM; - } - else if (name == "equip-necklace" || name == "equip-neck") - { - return ItemType::EQUIPMENT_NECKLACE; - } - else if (name == "equip-feet") - { - return ItemType::EQUIPMENT_FEET; - } - else if (name == "equip-ammo") - { - return ItemType::EQUIPMENT_AMMO; - } - else if (name == "racesprite") - { - return ItemType::SPRITE_RACE; - } - else if (name == "hairsprite") - { - return ItemType::SPRITE_HAIR; - } - else - { - logger->log("Unknown item type: " + name); - return ItemType::UNUSABLE; + const ItemTypeMap &type = itemTypeMap[f]; + if (type.name == name) + return type.type; } + logger->log("Unknown item type: " + name); + return ItemType::UNUSABLE; } static void initStatic() -- cgit v1.2.3-70-g09d2