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/CMakeLists.txt | 2 ++ src/Makefile.am | 2 ++ src/resources/db/itemdb.cpp | 75 +++++------------------------------------ src/resources/itemtypemap.h | 32 ++++++++++++++++++ src/resources/itemtypemapdata.h | 50 +++++++++++++++++++++++++++ 5 files changed, 94 insertions(+), 67 deletions(-) create mode 100644 src/resources/itemtypemap.h create mode 100644 src/resources/itemtypemapdata.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index be8f2b5e3..d20f5a973 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -573,6 +573,8 @@ SET(SRCS resources/itemslot.h resources/itemsoundevent.h resources/itemtype.h + resources/itemtypemap.h + resources/itemtypemapdata.h resources/db/mapdb.cpp resources/db/mapdb.h resources/db/moddb.cpp diff --git a/src/Makefile.am b/src/Makefile.am index c4c0af6a5..a86814fd3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -698,6 +698,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ resources/itemslot.h \ resources/itemsoundevent.h \ resources/itemtype.h \ + resources/itemtypemap.h \ + resources/itemtypemapdata.h \ resources/db/mapdb.cpp \ resources/db/mapdb.h \ resources/db/moddb.cpp \ 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() 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 . + */ + +#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 . + */ + +#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 -- cgit v1.2.3-60-g2f50