summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources')
-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
-rw-r--r--src/resources/itemfieldinfos.h33
5 files changed, 53 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)
diff --git a/src/resources/itemfieldinfos.h b/src/resources/itemfieldinfos.h
new file mode 100644
index 000000000..c19a1837f
--- /dev/null
+++ b/src/resources/itemfieldinfos.h
@@ -0,0 +1,33 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2016-2018 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef RESOURCES_ITEMFIELDINFOS_H
+#define RESOURCES_ITEMFIELDINFOS_H
+
+#include <map>
+#include <string>
+
+#include "localconsts.h"
+
+struct ItemFieldType;
+
+typedef std::map<std::string, ItemFieldType*> ItemFieldInfos;
+
+#endif // RESOURCES_ITEMFIELDINFOS_H