summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-07-08 13:46:07 +0300
committerAndrei Karas <akaras@inbox.ru>2013-07-08 13:46:07 +0300
commit9e1c8b7ab5db33f544305c3b160ca65b6972370f (patch)
tree1bd1f627d3d58a874953149de001a770f7d9ea9e
parent857da1b7b4e0a2523947b6ec82746a559543f329 (diff)
downloadmv-9e1c8b7ab5db33f544305c3b160ca65b6972370f.tar.gz
mv-9e1c8b7ab5db33f544305c3b160ca65b6972370f.tar.bz2
mv-9e1c8b7ab5db33f544305c3b160ca65b6972370f.tar.xz
mv-9e1c8b7ab5db33f544305c3b160ca65b6972370f.zip
add ability to show stats from items.xml like strings.
-rw-r--r--src/net/eathena/generalhandler.cpp12
-rw-r--r--src/net/tmwa/generalhandler.cpp12
-rw-r--r--src/resources/itemdb.cpp27
-rw-r--r--src/utils/stringutils.cpp14
-rw-r--r--src/utils/stringutils.h2
-rw-r--r--src/utils/stringutils_unittest.cc13
6 files changed, 57 insertions, 23 deletions
diff --git a/src/net/eathena/generalhandler.cpp b/src/net/eathena/generalhandler.cpp
index b75044bb3..029b7fcd4 100644
--- a/src/net/eathena/generalhandler.cpp
+++ b/src/net/eathena/generalhandler.cpp
@@ -99,12 +99,12 @@ GeneralHandler::GeneralHandler() :
generalHandler = this;
std::vector<ItemDB::Stat> stats;
- stats.push_back(ItemDB::Stat("str", _("Strength %+d")));
- stats.push_back(ItemDB::Stat("agi", _("Agility %+d")));
- stats.push_back(ItemDB::Stat("vit", _("Vitality %+d")));
- stats.push_back(ItemDB::Stat("int", _("Intelligence %+d")));
- stats.push_back(ItemDB::Stat("dex", _("Dexterity %+d")));
- stats.push_back(ItemDB::Stat("luck", _("Luck %+d")));
+ stats.push_back(ItemDB::Stat("str", _("Strength %s")));
+ stats.push_back(ItemDB::Stat("agi", _("Agility %s")));
+ stats.push_back(ItemDB::Stat("vit", _("Vitality %s")));
+ stats.push_back(ItemDB::Stat("int", _("Intelligence %s")));
+ stats.push_back(ItemDB::Stat("dex", _("Dexterity %s")));
+ stats.push_back(ItemDB::Stat("luck", _("Luck %s")));
ItemDB::setStatsList(stats);
}
diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp
index fa625b76f..ba8f40551 100644
--- a/src/net/tmwa/generalhandler.cpp
+++ b/src/net/tmwa/generalhandler.cpp
@@ -102,17 +102,17 @@ GeneralHandler::GeneralHandler() :
std::vector<ItemDB::Stat> stats;
// TRANSLATORS: player stat
- stats.push_back(ItemDB::Stat("str", _("Strength %+d")));
+ stats.push_back(ItemDB::Stat("str", _("Strength %s")));
// TRANSLATORS: player stat
- stats.push_back(ItemDB::Stat("agi", _("Agility %+d")));
+ stats.push_back(ItemDB::Stat("agi", _("Agility %s")));
// TRANSLATORS: player stat
- stats.push_back(ItemDB::Stat("vit", _("Vitality %+d")));
+ stats.push_back(ItemDB::Stat("vit", _("Vitality %s")));
// TRANSLATORS: player stat
- stats.push_back(ItemDB::Stat("int", _("Intelligence %+d")));
+ stats.push_back(ItemDB::Stat("int", _("Intelligence %s")));
// TRANSLATORS: player stat
- stats.push_back(ItemDB::Stat("dex", _("Dexterity %+d")));
+ stats.push_back(ItemDB::Stat("dex", _("Dexterity %s")));
// TRANSLATORS: player stat
- stats.push_back(ItemDB::Stat("luck", _("Luck %+d")));
+ stats.push_back(ItemDB::Stat("luck", _("Luck %s")));
ItemDB::setStatsList(stats);
}
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index 379b79e58..ff417d36e 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -59,15 +59,15 @@ static int parseDirectionName(const std::string &name);
static const char *const fields[][2] =
{
// TRANSLATORS: item info label
- { "attack", N_("Attack %+d") },
+ { "attack", N_("Attack %s") },
// TRANSLATORS: item info label
- { "defense", N_("Defense %+d") },
+ { "defense", N_("Defense %s") },
// TRANSLATORS: item info label
- { "hp", N_("HP %+d") },
+ { "hp", N_("HP %s") },
// TRANSLATORS: item info label
- { "mp", N_("MP %+d") },
+ { "mp", N_("MP %s") },
// TRANSLATORS: item info label
- { "level", N_("Level %+d") }
+ { "level", N_("Level %s") }
};
static std::vector<ItemDB::Stat> extraStats;
@@ -344,21 +344,26 @@ void ItemDB::loadXmlFile(const std::string &fileName, int &tagNum)
std::string effect;
for (size_t i = 0; i < sizeof(fields) / sizeof(fields[0]); ++ i)
{
- const int value = XML::getProperty(node, fields[i][0], 0);
- if (!value)
+ std::string value = XML::getProperty(node, fields[i][0], "");
+ if (value.empty())
continue;
if (!effect.empty())
effect.append(" / ");
- effect.append(strprintf(gettext(fields[i][1]), value));
+ if (isDigit(value))
+ value = "+" + value;
+ effect.append(strprintf(gettext(fields[i][1]), value.c_str()));
}
FOR_EACH (std::vector<Stat>::const_iterator, it, extraStats)
{
- const int value = XML::getProperty(node, it->tag.c_str(), 0);
- if (!value)
+ std::string value = XML::getProperty(
+ node, it->tag.c_str(), "");
+ if (value.empty())
continue;
if (!effect.empty())
effect.append(" / ");
- effect.append(strprintf(it->format.c_str(), value));
+ if (isDigit(value))
+ value = "+" + value;
+ effect.append(strprintf(it->format.c_str(), value.c_str()));
}
std::string temp = XML::langProperty(node, "effect", "");
if (!effect.empty() && !temp.empty())
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index da3f8dd06..a54d9d5ab 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -697,3 +697,17 @@ std::string toStringPrint(const unsigned int val)
str[99] = 0;
return str;
}
+
+bool isDigit(const std::string &str)
+{
+ if (str.empty())
+ return false;
+ const size_t sz = str.size();
+ for (size_t f = 0; f < sz; f ++)
+ {
+ const char &chr = str[f];
+ if (chr < '0' || chr > '9')
+ return false;
+ }
+ return true;
+}
diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h
index 737b5c8f3..7f40b3673 100644
--- a/src/utils/stringutils.h
+++ b/src/utils/stringutils.h
@@ -230,4 +230,6 @@ std::string encodeLinkText(std::string data);
std::string decodeLinkText(std::string data);
+bool isDigit(const std::string &str);
+
#endif // UTILS_STRINGUTILS_H
diff --git a/src/utils/stringutils_unittest.cc b/src/utils/stringutils_unittest.cc
index 75f4f2f35..8f28f5c10 100644
--- a/src/utils/stringutils_unittest.cc
+++ b/src/utils/stringutils_unittest.cc
@@ -551,3 +551,16 @@ TEST(stringuntils, decodeLinkText)
str = decodeLinkText(str);
EXPECT_EQ(str, "test|line");
}
+
+TEST(stringuntils, isDigit)
+{
+ std::string str;
+
+ EXPECT_FALSE(isDigit(""));
+ EXPECT_TRUE(isDigit("1"));
+ EXPECT_TRUE(isDigit("123"));
+ EXPECT_FALSE(isDigit("+123"));
+ EXPECT_FALSE(isDigit("-123"));
+ EXPECT_FALSE(isDigit("1.23"));
+ EXPECT_FALSE(isDigit("12-34"));
+}