diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-07-03 14:43:03 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-07-03 14:43:03 +0300 |
commit | 284acf8f76bd2201bd64b847a2564206f77a4278 (patch) | |
tree | d562014465ae69782a7a081689ee5917812a5e55 /src/resources | |
parent | 5ccaffe607662610eb34d5a9043fb5fb7e068039 (diff) | |
download | manaplus-284acf8f76bd2201bd64b847a2564206f77a4278.tar.gz manaplus-284acf8f76bd2201bd64b847a2564206f77a4278.tar.bz2 manaplus-284acf8f76bd2201bd64b847a2564206f77a4278.tar.xz manaplus-284acf8f76bd2201bd64b847a2564206f77a4278.zip |
Move item type mapping into separate file.
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/db/itemdb.cpp | 75 | ||||
-rw-r--r-- | src/resources/itemtypemap.h | 32 | ||||
-rw-r--r-- | src/resources/itemtypemapdata.h | 50 |
3 files changed, 90 insertions, 67 deletions
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<ItemDB::Stat> &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() diff --git a/src/resources/itemtypemap.h b/src/resources/itemtypemap.h new file mode 100644 index 000000000..c8dc48197 --- /dev/null +++ b/src/resources/itemtypemap.h @@ -0,0 +1,32 @@ +/* + * The ManaPlus Client + * Copyright (C) 2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef RESOURCES_ITEMTYPEMAP_H +#define RESOURCES_ITEMTYPEMAP_H + +#include "localconsts.h" + +struct ItemTypeMap final +{ + std::string name; + ItemType::Type type; +}; + +#endif // RESOURCES_ITEMTYPEMAP_H diff --git a/src/resources/itemtypemapdata.h b/src/resources/itemtypemapdata.h new file mode 100644 index 000000000..c232dbe52 --- /dev/null +++ b/src/resources/itemtypemapdata.h @@ -0,0 +1,50 @@ +/* + * The ManaPlus Client + * Copyright (C) 2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef RESOURCES_ITEMTYPEMAPDATA_H +#define RESOURCES_ITEMTYPEMAPDATA_H + +#include "localconsts.h" + +#include "resources/itemtypemap.h" + +ItemTypeMap itemTypeMap[] = +{ + {"generic", ItemType::UNUSABLE}, + {"other", ItemType::UNUSABLE}, + {"usable", ItemType::USABLE}, + {"equip-1hand", ItemType::EQUIPMENT_ONE_HAND_WEAPON}, + {"equip-2hand", ItemType::EQUIPMENT_TWO_HANDS_WEAPON}, + {"equip-torso", ItemType::EQUIPMENT_TORSO}, + {"equip-arms", ItemType::EQUIPMENT_ARMS}, + {"equip-head", ItemType::EQUIPMENT_HEAD}, + {"equip-legs", ItemType::EQUIPMENT_LEGS}, + {"equip-shield", ItemType::EQUIPMENT_SHIELD}, + {"equip-ring", ItemType::EQUIPMENT_RING}, + {"equip-charm", ItemType::EQUIPMENT_CHARM}, + {"equip-necklace", ItemType::EQUIPMENT_NECKLACE}, + {"equip-neck", ItemType::EQUIPMENT_NECKLACE}, + {"equip-feet", ItemType::EQUIPMENT_FEET}, + {"equip-ammo", ItemType::EQUIPMENT_AMMO}, + {"racesprite", ItemType::SPRITE_RACE}, + {"hairsprite", ItemType::SPRITE_HAIR}, +}; + +#endif // RESOURCES_ITEMTYPEMAPDATA_H |