summaryrefslogtreecommitdiff
path: root/src/resources/db
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2018-02-10 05:09:16 +0300
committerAndrei Karas <akaras@inbox.ru>2018-02-11 04:28:43 +0300
commitce34b402281f75cb1e9d214c925382fdc522455b (patch)
tree6d2cb57028ad67449da2ab4f95ef7f562d1d4823 /src/resources/db
parent29181589eb79d3afdf337e2517b4fa43d8bbdd59 (diff)
downloadmv-ce34b402281f75cb1e9d214c925382fdc522455b.tar.gz
mv-ce34b402281f75cb1e9d214c925382fdc522455b.tar.bz2
mv-ce34b402281f75cb1e9d214c925382fdc522455b.tar.xz
mv-ce34b402281f75cb1e9d214c925382fdc522455b.zip
Move reading and combining item stats into separate file.
Diffstat (limited to 'src/resources/db')
-rw-r--r--src/resources/db/itemdb.cpp36
-rw-r--r--src/resources/db/itemfielddb.cpp12
-rw-r--r--src/resources/db/itemfielddb.h8
-rw-r--r--src/resources/db/itemoptiondb.cpp10
4 files changed, 20 insertions, 46 deletions
diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp
index d0889a808..fcb0d5651 100644
--- a/src/resources/db/itemdb.cpp
+++ b/src/resources/db/itemdb.cpp
@@ -48,6 +48,7 @@
#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/foreach.h"
+#include "utils/itemxmlutils.h"
#include "utils/stdmove.h"
#include "utils/stringmap.h"
@@ -130,33 +131,6 @@ static std::string useButton2FromItemType(const ItemDbTypeT &type)
return std::string();
}
-static void readFields(std::string &effect,
- XmlNodeConstPtr node,
- const ItemFieldDb::FieldInfos &fields)
-{
- if (translator == nullptr)
- return;
-
- FOR_EACH (ItemFieldDb::FieldInfos::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())
- 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()));
- }
-}
-
static void initStatic()
{
mConstructed = true;
@@ -311,9 +285,9 @@ void ItemDB::loadXmlFile(const std::string &fileName,
return;
}
- const ItemFieldDb::FieldInfos &requiredFields =
+ const ItemFieldInfos &requiredFields =
ItemFieldDb::getRequiredFields();
- const ItemFieldDb::FieldInfos &addFields =
+ const ItemFieldInfos &addFields =
ItemFieldDb::getAddFields();
for_each_xml_child_node(node, rootNode)
@@ -526,8 +500,8 @@ void ItemDB::loadXmlFile(const std::string &fileName,
}
std::string effect;
- readFields(effect, node, requiredFields);
- readFields(effect, node, addFields);
+ readItemStatsString(effect, node, requiredFields);
+ readItemStatsString(effect, node, addFields);
std::string temp = XML::langProperty(node, "effect", "");
if (!effect.empty() && !temp.empty())
effect.append(" / ");
diff --git a/src/resources/db/itemfielddb.cpp b/src/resources/db/itemfielddb.cpp
index 231582458..76ad26036 100644
--- a/src/resources/db/itemfielddb.cpp
+++ b/src/resources/db/itemfielddb.cpp
@@ -33,8 +33,8 @@
namespace
{
- ItemFieldDb::FieldInfos mRequiredInfos;
- ItemFieldDb::FieldInfos mAddInfos;
+ ItemFieldInfos mRequiredInfos;
+ ItemFieldInfos mAddInfos;
bool mLoaded = false;
} // namespace
@@ -52,8 +52,8 @@ void ItemFieldDb::load()
}
static void loadFields(XmlNodeConstPtr groupNode,
- ItemFieldDb::FieldInfos &fields1,
- ItemFieldDb::FieldInfos &fields2)
+ ItemFieldInfos &fields1,
+ ItemFieldInfos &fields2)
{
for_each_xml_child_node(node, groupNode)
{
@@ -142,12 +142,12 @@ void ItemFieldDb::unload()
mLoaded = false;
}
-const ItemFieldDb::FieldInfos &ItemFieldDb::getRequiredFields()
+const ItemFieldInfos &ItemFieldDb::getRequiredFields()
{
return mRequiredInfos;
}
-const ItemFieldDb::FieldInfos &ItemFieldDb::getAddFields()
+const ItemFieldInfos &ItemFieldDb::getAddFields()
{
return mAddInfos;
}
diff --git a/src/resources/db/itemfielddb.h b/src/resources/db/itemfielddb.h
index bd05aad7f..8d88fef84 100644
--- a/src/resources/db/itemfielddb.h
+++ b/src/resources/db/itemfielddb.h
@@ -23,6 +23,8 @@
#include "enums/simpletypes/skiperror.h"
+#include "resources/itemfieldinfos.h"
+
#include <map>
#include <string>
@@ -39,11 +41,9 @@ namespace ItemFieldDb
void loadXmlFile(const std::string &fileName,
const SkipError skipError);
- typedef std::map<std::string, ItemFieldType*> FieldInfos;
-
- const FieldInfos &getRequiredFields();
+ const ItemFieldInfos &getRequiredFields();
- const FieldInfos &getAddFields();
+ const ItemFieldInfos &getAddFields();
} // namespace ItemFieldDb
#endif // RESOURCES_DB_ITEMFIELDDB_H
diff --git a/src/resources/db/itemoptiondb.cpp b/src/resources/db/itemoptiondb.cpp
index 204fafb34..e983cd801 100644
--- a/src/resources/db/itemoptiondb.cpp
+++ b/src/resources/db/itemoptiondb.cpp
@@ -51,14 +51,14 @@ void ItemOptionDb::load()
static void addFieldByName(STD_VECTOR<ItemFieldType*> &options,
XmlNodeConstPtr node,
- const ItemFieldDb::FieldInfos &fields,
+ const ItemFieldInfos &fields,
const char *const name)
{
std::string value = XML::getProperty(node, name, "");
if (value.empty())
return;
- FOR_EACH (ItemFieldDb::FieldInfos::const_iterator, it, fields)
+ FOR_EACH (ItemFieldInfos::const_iterator, it, fields)
{
const std::string fieldName = (*it).first;
if (fieldName == value)
@@ -71,7 +71,7 @@ static void addFieldByName(STD_VECTOR<ItemFieldType*> &options,
static void readOptionFields(STD_VECTOR<ItemFieldType*> &options,
XmlNodeConstPtr node,
- const ItemFieldDb::FieldInfos &fields)
+ const ItemFieldInfos &fields)
{
addFieldByName(options, node, fields, "field");
for (int f = 0; f < 15; f ++)
@@ -104,9 +104,9 @@ void ItemOptionDb::loadXmlFile(const std::string &fileName,
return;
}
- const ItemFieldDb::FieldInfos &requiredFields =
+ const ItemFieldInfos &requiredFields =
ItemFieldDb::getRequiredFields();
- const ItemFieldDb::FieldInfos &addFields =
+ const ItemFieldInfos &addFields =
ItemFieldDb::getAddFields();
for_each_xml_child_node(node, rootNode)