summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--po/POTFILES.in2
-rw-r--r--src/resources/itemdb.cpp62
3 files changed, 43 insertions, 24 deletions
diff --git a/ChangeLog b/ChangeLog
index e99e7a56..79ce3ed6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -23,6 +23,9 @@
attacktype field.
* src/resources/iteminfo.h, src/resources/itemdb.cpp: Removed unused
slot field.
+ * src/resources/itemdb.cpp: Added automatic generation of description
+ strings for item effects.
+ * po/POTFILES.in: Marked effect strings as translatable.
2007-10-15 Bjørn Lindeijer <bjorn@lindeijer.nl>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index c3bba7b9..35f07dba 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -20,4 +20,4 @@ src/gui/setup_audio.cpp
src/gui/setup.cpp
src/gui/setup_joystick.cpp
src/gui/setup_video.cpp
-
+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)