diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-07-10 15:28:55 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-07-10 17:53:10 +0300 |
commit | 82de3bbe7580f65bf808c4fd48706fa9e0512a65 (patch) | |
tree | 04888a460088a1e497985939147ce782fdc05375 /src | |
parent | 79005bb9b669c9f879fec8e15776a3846e82ec96 (diff) | |
download | manaverse-82de3bbe7580f65bf808c4fd48706fa9e0512a65.tar.gz manaverse-82de3bbe7580f65bf808c4fd48706fa9e0512a65.tar.bz2 manaverse-82de3bbe7580f65bf808c4fd48706fa9e0512a65.tar.xz manaverse-82de3bbe7580f65bf808c4fd48706fa9e0512a65.zip |
add support for signed and string attribute values in items.xml.
Diffstat (limited to 'src')
-rw-r--r-- | src/resources/itemdb.cpp | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index ff417d36e..a7310036d 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -56,19 +56,29 @@ static void loadOrderSprite(ItemInfo *const itemInfo, const XmlNodePtr node, static int parseSpriteName(const std::string &name); static int parseDirectionName(const std::string &name); -static const char *const fields[][2] = +namespace { - // TRANSLATORS: item info label - { "attack", N_("Attack %s") }, - // TRANSLATORS: item info label - { "defense", N_("Defense %s") }, - // TRANSLATORS: item info label - { "hp", N_("HP %s") }, - // TRANSLATORS: item info label - { "mp", N_("MP %s") }, - // TRANSLATORS: item info label - { "level", N_("Level %s") } -}; + struct FieldType + { + const char *name; + const char *description; + const bool sign; + }; + + static const FieldType fields[] = + { + // TRANSLATORS: item info label + { "attack", N_("Attack %s"), true }, + // TRANSLATORS: item info label + { "defense", N_("Defense %s"), true }, + // TRANSLATORS: item info label + { "hp", N_("HP %s"), true }, + // TRANSLATORS: item info label + { "mp", N_("MP %s"), true }, + // TRANSLATORS: item info label + { "level", N_("Level %s"), false } + }; +} // namespace static std::vector<ItemDB::Stat> extraStats; @@ -344,14 +354,15 @@ void ItemDB::loadXmlFile(const std::string &fileName, int &tagNum) std::string effect; for (size_t i = 0; i < sizeof(fields) / sizeof(fields[0]); ++ i) { - std::string value = XML::getProperty(node, fields[i][0], ""); + std::string value = XML::getProperty(node, fields[i].name, ""); if (value.empty()) continue; if (!effect.empty()) effect.append(" / "); - if (isDigit(value)) + if (fields[i].sign && isDigit(value)) value = "+" + value; - effect.append(strprintf(gettext(fields[i][1]), value.c_str())); + effect.append(strprintf(gettext(fields[i].description), + value.c_str())); } FOR_EACH (std::vector<Stat>::const_iterator, it, extraStats) { |