diff options
author | Andrei Karas <akaras@inbox.ru> | 2018-03-02 05:48:13 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2018-03-03 01:13:59 +0300 |
commit | f18d40351434f7baff2ddf1d34933c19cada5dba (patch) | |
tree | 7461cb0d74fe9049b9393e4def7a343ca55a17b0 /src/utils/itemxmlutils.cpp | |
parent | d7f491da52e985ea50464804d342d9d45ae407f7 (diff) | |
download | plus-f18d40351434f7baff2ddf1d34933c19cada5dba.tar.gz plus-f18d40351434f7baff2ddf1d34933c19cada5dba.tar.bz2 plus-f18d40351434f7baff2ddf1d34933c19cada5dba.tar.xz plus-f18d40351434f7baff2ddf1d34933c19cada5dba.zip |
Add support for item stat ranges.
Example:
...
hp="10-15"
mp="1-2"
...
Diffstat (limited to 'src/utils/itemxmlutils.cpp')
-rw-r--r-- | src/utils/itemxmlutils.cpp | 76 |
1 files changed, 52 insertions, 24 deletions
diff --git a/src/utils/itemxmlutils.cpp b/src/utils/itemxmlutils.cpp index 5dc68b249..8ecbeeda6 100644 --- a/src/utils/itemxmlutils.cpp +++ b/src/utils/itemxmlutils.cpp @@ -29,6 +29,52 @@ #include "debug.h" +static bool readField(ItemFieldInfos::const_iterator it, + XmlNodeConstPtr node, + std::string &combined) +{ + const std::string fieldName = (*it).first; + const ItemFieldType *const field = (*it).second; + + std::string value = XML::getProperty(node, + fieldName.c_str(), + ""); + if (value.empty()) + return false; + + StringVect tokens; + splitToStringVector(tokens, + value, + '-'); + if (tokens.size() > 1) + { + std::string value1; + std::string value2; + if (field->sign) + { + value1 = std::string("+").append(tokens[0]); + value2 = std::string("+").append(tokens[1]); + } + else + { + value1 = tokens[0]; + value2 = tokens[1]; + } + value = strprintf("%s - %s", + value1.c_str(), + value2.c_str()); + } + else + { + if (field->sign) + value = std::string("+").append(value); + } + const std::string format = translator->getStr(field->description); + combined = strprintf(format.c_str(), + value.c_str()); + return true; +} + void readItemStatsString(std::string &effect, XmlNodeConstPtr node, const ItemFieldInfos &fields) @@ -41,21 +87,12 @@ void readItemStatsString(std::string &effect, FOR_EACH (ItemFieldInfos::const_iterator, it, fields) { - const std::string fieldName = (*it).first; - const ItemFieldType *const field = (*it).second; - - std::string value = XML::getProperty(node, - fieldName.c_str(), - ""); - if (value.empty()) + std::string field; + if (!readField(it, node, field)) continue; if (!effect.empty()) effect.append(" / "); - if (field->sign && isDigit(value)) - value = std::string("+").append(value); - const std::string format = translator->getStr(field->description); - effect.append(strprintf(format.c_str(), - value.c_str())); + effect.append(field); } } @@ -71,18 +108,9 @@ void readItemStatsVector(STD_VECTOR<std::string> &effect, FOR_EACH (ItemFieldInfos::const_iterator, it, fields) { - const std::string fieldName = (*it).first; - const ItemFieldType *const field = (*it).second; - - std::string value = XML::getProperty(node, - fieldName.c_str(), - ""); - if (value.empty()) + std::string field; + if (!readField(it, node, field)) continue; - if (field->sign && isDigit(value)) - value = std::string("+").append(value); - const std::string format = translator->getStr(field->description); - effect.push_back(strprintf(format.c_str(), - value.c_str())); + effect.push_back(field); } } |