summaryrefslogtreecommitdiff
path: root/src/resources/db
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-08-15 13:58:32 +0300
committerAndrei Karas <akaras@inbox.ru>2015-08-16 01:52:14 +0300
commit41cc92f73e39cec5dfea6b1164176610cccc7df4 (patch)
tree22fd3d388084d2c61fe80f0441c3c30ab8ffd33c /src/resources/db
parent7aa637abc8b0bca35aacdb9492e65f557ed32038 (diff)
downloadplus-41cc92f73e39cec5dfea6b1164176610cccc7df4.tar.gz
plus-41cc92f73e39cec5dfea6b1164176610cccc7df4.tar.bz2
plus-41cc92f73e39cec5dfea6b1164176610cccc7df4.tar.xz
plus-41cc92f73e39cec5dfea6b1164176610cccc7df4.zip
Add strong typed int for item color.
Diffstat (limited to 'src/resources/db')
-rw-r--r--src/resources/db/colordb.cpp36
-rw-r--r--src/resources/db/colordb.h29
2 files changed, 37 insertions, 28 deletions
diff --git a/src/resources/db/colordb.cpp b/src/resources/db/colordb.cpp
index 1b636e407..62f7beef6 100644
--- a/src/resources/db/colordb.cpp
+++ b/src/resources/db/colordb.cpp
@@ -41,7 +41,7 @@ void ColorDB::load()
if (mLoaded)
unload();
- std::map<int, ItemColor> colors;
+ std::map<ItemColor, ItemColorData> colors;
ColorListsIterator it = mColorLists.find("hair");
if (it != mColorLists.end())
colors = it->second;
@@ -68,7 +68,7 @@ void ColorDB::load()
}
void ColorDB::loadHair(const std::string &fileName,
- std::map<int, ItemColor> &colors)
+ std::map<ItemColor, ItemColorData> &colors)
{
XML::Document *doc = new XML::Document(fileName,
UseResman_true,
@@ -78,8 +78,8 @@ void ColorDB::loadHair(const std::string &fileName,
if (!root || !xmlNameEqual(root, "colors"))
{
logger->log("ColorDB: Failed to find hair colors file.");
- if (colors.find(0) == colors.end())
- colors[0] = ItemColor(0, "", "");
+ if (colors.find(ItemColor_zero) == colors.end())
+ colors[ItemColor_zero] = ItemColorData(ItemColor_zero, "", "");
delete doc;
return;
}
@@ -95,12 +95,13 @@ void ColorDB::loadHair(const std::string &fileName,
}
else if (xmlNameEqual(node, "color"))
{
- const int id = XML::getProperty(node, "id", 0);
+ const ItemColor id = fromInt(XML::getProperty(
+ node, "id", 0), ItemColor);
if (colors.find(id) != colors.end())
- logger->log("ColorDB: Redefinition of dye ID %d", id);
+ logger->log("ColorDB: Redefinition of dye ID %d", toInt(id, int));
- colors[id] = ItemColor(id, XML::langProperty(node, "name", ""),
+ colors[id] = ItemColorData(id, XML::langProperty(node, "name", ""),
XML::getProperty(node, "value", "#FFFFFF"));
}
}
@@ -135,7 +136,7 @@ void ColorDB::loadColorLists(const std::string &fileName)
if (name.empty())
continue;
- std::map <int, ItemColor> colors;
+ std::map <ItemColor, ItemColorData> colors;
const ColorListsIterator it = mColorLists.find(name);
if (it != mColorLists.end())
@@ -145,11 +146,14 @@ void ColorDB::loadColorLists(const std::string &fileName)
{
if (xmlNameEqual(colorNode, "color"))
{
- ItemColor c(XML::getProperty(colorNode, "id", -1),
- XML::langProperty(colorNode, "name", ""),
- XML::getProperty(colorNode, "value", ""));
- if (c.id > -1)
- colors[c.id] = c;
+ const int id = XML::getProperty(colorNode, "id", -1);
+ if (id > -1)
+ {
+ ItemColorData c(fromInt(id, ItemColor),
+ XML::langProperty(colorNode, "name", ""),
+ XML::getProperty(colorNode, "value", ""));
+ colors[c.id] = c;
+ }
}
}
mColorLists[name] = colors;
@@ -166,7 +170,7 @@ void ColorDB::unload()
mLoaded = false;
}
-std::string &ColorDB::getHairColorName(const int id)
+std::string &ColorDB::getHairColorName(const ItemColor id)
{
if (!mLoaded)
load();
@@ -182,7 +186,7 @@ std::string &ColorDB::getHairColorName(const int id)
if (i == (*it).second.end())
{
- logger->log("ColorDB: Error, unknown dye ID# %d", id);
+ logger->log("ColorDB: Error, unknown dye ID# %d", toInt(id, int));
return mFail;
}
else
@@ -196,7 +200,7 @@ int ColorDB::getHairSize()
return mHairColorsSize;
}
-const std::map <int, ColorDB::ItemColor>
+const std::map <ItemColor, ColorDB::ItemColorData>
*ColorDB::getColorsList(const std::string &name)
{
const ColorListsIterator it = mColorLists.find(name);
diff --git a/src/resources/db/colordb.h b/src/resources/db/colordb.h
index c2923f382..6468b76e3 100644
--- a/src/resources/db/colordb.h
+++ b/src/resources/db/colordb.h
@@ -22,6 +22,8 @@
#ifndef RESOURCES_DB_COLORDB_H
#define RESOURCES_DB_COLORDB_H
+#include "enums/simpletypes/itemcolor.h"
+
#include <map>
#include <string>
@@ -32,24 +34,25 @@
*/
namespace ColorDB
{
- class ItemColor final
+ class ItemColorData final
{
public:
- ItemColor() :
- id(0),
+ ItemColorData() :
+ id(ItemColor_zero),
name(),
color()
{ }
- ItemColor(const int id0, const std::string &name0,
- const std::string &color0) :
+ ItemColorData(const ItemColor id0,
+ const std::string &name0,
+ const std::string &color0) :
id(id0),
name(name0),
color(color0)
{
}
- int id;
+ ItemColor id;
std::string name;
std::string color;
};
@@ -63,7 +66,7 @@ namespace ColorDB
* Loads the color data from <code>colors.xml</code>.
*/
void loadHair(const std::string &fileName,
- std::map<int, ItemColor> &colors);
+ std::map<ItemColor, ItemColorData> &colors);
void loadColorLists(const std::string &fileName);
@@ -72,17 +75,19 @@ namespace ColorDB
*/
void unload();
- std::string &getHairColorName(const int id) A_WARN_UNUSED;
+ std::string &getHairColorName(const ItemColor id) A_WARN_UNUSED;
int getHairSize() A_WARN_UNUSED;
- const std::map <int, ItemColor> *getColorsList(const std::string
- &name) A_WARN_UNUSED;
+ const std::map <ItemColor, ItemColorData> *getColorsList(const std::string
+ &name)
+ A_WARN_UNUSED;
// Color DB
- typedef std::map<int, ItemColor> Colors;
+ typedef std::map<ItemColor, ItemColorData> Colors;
typedef Colors::iterator ColorIterator;
- typedef std::map <std::string, std::map <int, ItemColor> > ColorLists;
+ typedef std::map <std::string, std::map <ItemColor, ItemColorData> >
+ ColorLists;
typedef ColorLists::iterator ColorListsIterator;
} // namespace ColorDB