From 423b55510aaf672663b68c8ecff1c3807b1671de Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 2 Feb 2012 23:33:29 +0300 Subject: Load hair colors from itemcolors.xml. Use also hair.xml for backward compotability. --- src/resources/colordb.cpp | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/resources/colordb.cpp b/src/resources/colordb.cpp index bce768d6d..2ddf27ac3 100644 --- a/src/resources/colordb.cpp +++ b/src/resources/colordb.cpp @@ -30,7 +30,7 @@ namespace { - ColorDB::Colors mHairColors; + int mHairColorsSize = 0; bool mLoaded = false; std::string mFail = "#ffffff"; ColorDB::ColorLists mColorLists; @@ -44,10 +44,22 @@ void ColorDB::load() loadHair(); if (serverVersion >= 1) loadColorLists(); + + ColorListsIterator it = mColorLists.find("hair"); + if (it != mColorLists.end()) + mHairColorsSize = (*it).second.size(); + else + mHairColorsSize = 0; } void ColorDB::loadHair() { + std::map colors; + ColorListsIterator it = mColorLists.find("hair"); + + if (it != mColorLists.end()) + colors = it->second; + XML::Document *doc = new XML::Document("hair.xml"); XmlNodePtr root = doc->rootNode(); bool hairXml = true; @@ -65,7 +77,7 @@ void ColorDB::loadHair() if (!root || !xmlNameEqual(root, "colors")) { logger->log1("ColorDB: Failed to find any color files."); - mHairColors[0] = ItemColor(0, "", ""); + colors[0] = ItemColor(0, "", ""); mLoaded = true; delete doc; @@ -80,16 +92,17 @@ void ColorDB::loadHair() { int id = XML::getProperty(node, "id", 0); - if (mHairColors.find(id) != mHairColors.end()) + if (colors.find(id) != colors.end()) logger->log("ColorDB: Redefinition of dye ID %d", id); - mHairColors[id] = ItemColor(id, XML::getProperty(node, "name", ""), + colors[id] = ItemColor(id, XML::getProperty(node, "name", ""), XML::getProperty(node, hairXml ? "value" : "dye", "#FFFFFF")); } } delete doc; + mColorLists["hair"] = colors; mLoaded = true; } @@ -138,7 +151,6 @@ void ColorDB::unload() { logger->log1("Unloading color database..."); - mHairColors.clear(); mColorLists.clear(); mLoaded = false; } @@ -148,9 +160,16 @@ std::string &ColorDB::getHairColor(int id) if (!mLoaded) load(); - ColorIterator i = mHairColors.find(id); + ColorListsIterator it = mColorLists.find("hair"); + if (it == mColorLists.end()) + { + logger->log1("ColorDB: Error, hair colors list empty"); + return mFail; + } - if (i == mHairColors.end()) + ColorIterator i = (*it).second.find(id); + + if (i == (*it).second.end()) { logger->log("ColorDB: Error, unknown dye ID# %d", id); return mFail; @@ -166,9 +185,16 @@ std::string &ColorDB::getHairColorName(int id) if (!mLoaded) load(); - ColorIterator i = mHairColors.find(id); + ColorListsIterator it = mColorLists.find("hair"); + if (it == mColorLists.end()) + { + logger->log1("ColorDB: Error, hair colors list empty"); + return mFail; + } + + ColorIterator i = (*it).second.find(id); - if (i == mHairColors.end()) + if (i == (*it).second.end()) { logger->log("ColorDB: Error, unknown dye ID# %d", id); return mFail; @@ -181,7 +207,7 @@ std::string &ColorDB::getHairColorName(int id) int ColorDB::getHairSize() { - return static_cast(mHairColors.size()); + return mHairColorsSize; } std::map *ColorDB::getColorsList(std::string name) -- cgit v1.2.3-70-g09d2