From 677e019013c8500c6dd6198d370178fc982a7a22 Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Thu, 18 Oct 2007 20:38:53 +0000 Subject: Added automatic generation of description strings for item effects. --- src/resources/itemdb.cpp | 62 ++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 23 deletions(-) (limited to 'src/resources/itemdb.cpp') diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 10fd2697..49632279 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -33,6 +33,8 @@ #include "../log.h" #include "../utils/dtor.h" +#include "../utils/gettext.h" +#include "../utils/strprintf.h" #include "../utils/xml.h" namespace @@ -46,6 +48,14 @@ namespace static void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node); static void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node); +static char const *const fields[][2] = +{ + { "attack", N_("Attack %+d") }, + { "defense", N_("Defense %+d") }, + { "hp", N_("HP %+d") }, + { "mp", N_("MP %+d") } +}; + void ItemDB::load() { if (mLoaded) @@ -105,36 +115,42 @@ void ItemDB::load() std::string name = XML::getProperty(node, "name", ""); std::string image = XML::getProperty(node, "image", ""); std::string description = XML::getProperty(node, "description", ""); - std::string effect = XML::getProperty(node, "effect", ""); int weaponType = XML::getProperty(node, "weapon_type", 0); - if (id) + ItemInfo *itemInfo = new ItemInfo; + itemInfo->setImage(image); + itemInfo->setName(name.empty() ? "Unnamed" : name); + itemInfo->setDescription(description); + itemInfo->setType(type); + itemInfo->setView(view); + itemInfo->setWeight(weight); + itemInfo->setWeaponType(weaponType); + + std::string effect; + for (int i = 0; i < int(sizeof(fields) / sizeof(fields[0])); ++i) + { + int value = XML::getProperty(node, fields[i][0], 0); + if (!value) continue; + if (!effect.empty()) effect += " / "; + effect += strprintf(gettext(fields[i][1]), value); + } + itemInfo->setEffect(effect); + + + for_each_xml_child_node(itemChild, node) { - ItemInfo *itemInfo = new ItemInfo(); - itemInfo->setImage(image); - itemInfo->setName((name == "") ? "Unnamed" : name); - itemInfo->setDescription(description); - itemInfo->setEffect(effect); - itemInfo->setType(type); - itemInfo->setView(view); - itemInfo->setWeight(weight); - itemInfo->setWeaponType(weaponType); - - for_each_xml_child_node(itemChild, node) + if (xmlStrEqual(itemChild->name, BAD_CAST "sprite")) { - if (xmlStrEqual(itemChild->name, BAD_CAST "sprite")) - { - loadSpriteRef(itemInfo, itemChild); - } - else if (xmlStrEqual(itemChild->name, BAD_CAST "sound")) - { - loadSoundRef(itemInfo, itemChild); - } + loadSpriteRef(itemInfo, itemChild); + } + else if (xmlStrEqual(itemChild->name, BAD_CAST "sound")) + { + loadSoundRef(itemInfo, itemChild); } - - mItemInfos[id] = itemInfo; } + mItemInfos[id] = itemInfo; + #define CHECK_PARAM(param, error_value) \ if (param == error_value) \ logger->log("ItemDB: Missing " #param " attribute for item %i!",id) -- cgit v1.2.3-60-g2f50