diff options
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/colordb.cpp | 77 | ||||
-rw-r--r-- | src/resources/colordb.h | 32 | ||||
-rw-r--r-- | src/resources/itemdb.cpp | 7 | ||||
-rw-r--r-- | src/resources/iteminfo.cpp | 26 | ||||
-rw-r--r-- | src/resources/iteminfo.h | 16 |
5 files changed, 145 insertions, 13 deletions
diff --git a/src/resources/colordb.cpp b/src/resources/colordb.cpp index c35cec95e..dce051403 100644 --- a/src/resources/colordb.cpp +++ b/src/resources/colordb.cpp @@ -20,6 +20,7 @@ #include "resources/colordb.h" +#include "client.h" #include "log.h" #include "utils/xml.h" @@ -28,9 +29,10 @@ namespace { - ColorDB::Colors mColors; + ColorDB::Colors mHairColors; bool mLoaded = false; std::string mFail = "#ffffff"; + ColorDB::ColorLists mColorLists; } void ColorDB::load() @@ -38,6 +40,13 @@ void ColorDB::load() if (mLoaded) unload(); + loadHair(); + if (serverVersion >= 1) + loadColorLists(); +} + +void ColorDB::loadHair() +{ XML::Document *doc = new XML::Document("hair.xml"); xmlNodePtr root = doc->rootNode(); bool hairXml = true; @@ -55,7 +64,7 @@ void ColorDB::load() if (!root || !xmlStrEqual(root->name, BAD_CAST "colors")) { logger->log1("ColorDB: Failed to find any color files."); - mColors[0] = mFail; + mHairColors[0] = mFail; mLoaded = true; delete doc; @@ -69,10 +78,10 @@ void ColorDB::load() { int id = XML::getProperty(node, "id", 0); - if (mColors.find(id) != mColors.end()) + if (mHairColors.find(id) != mHairColors.end()) logger->log("ColorDB: Redefinition of dye ID %d", id); - mColors[id] = hairXml ? + mHairColors[id] = hairXml ? XML::getProperty(node, "value", "#FFFFFF") : XML::getProperty(node, "dye", "#FFFFFF"); } @@ -83,22 +92,60 @@ void ColorDB::load() mLoaded = true; } +void ColorDB::loadColorLists() +{ + XML::Document *doc = new XML::Document("itemcolors.xml"); + xmlNodePtr root = doc->rootNode(); + if (!root) + return; + + for_each_xml_child_node(node, root) + { + if (xmlStrEqual(node->name, BAD_CAST "list")) + { + std::string name = XML::getProperty(node, "name", ""); + if (name.empty()) + continue; + + std::map <int, ItemColor> colors; + ColorListsIterator it = mColorLists.find(name); + + if (it != mColorLists.end()) + colors = it->second; + + for_each_xml_child_node(colorNode, node) + { + if (xmlStrEqual(colorNode->name, BAD_CAST "color")) + { + ItemColor c(XML::getProperty(colorNode, "id", -1), + XML::getProperty(colorNode, "name", ""), + XML::getProperty(colorNode, "value", "")); + if (c.id > -1) + colors[c.id] = c; + } + } + mColorLists[name] = colors; + } + } +} + void ColorDB::unload() { logger->log1("Unloading color database..."); - mColors.clear(); + mHairColors.clear(); + mColorLists.clear(); mLoaded = false; } -std::string &ColorDB::get(int id) +std::string &ColorDB::getHairColor(int id) { if (!mLoaded) load(); - ColorIterator i = mColors.find(id); + ColorIterator i = mHairColors.find(id); - if (i == mColors.end()) + if (i == mHairColors.end()) { logger->log("ColorDB: Error, unknown dye ID# %d", id); return mFail; @@ -109,7 +156,17 @@ std::string &ColorDB::get(int id) } } -int ColorDB::size() +int ColorDB::getHairSize() { - return static_cast<int>(mColors.size()); + return static_cast<int>(mHairColors.size()); +} + +std::map <int, ColorDB::ItemColor> *ColorDB::getColorsList(std::string name) +{ + std::map <int, ItemColor> colors; + ColorListsIterator it = mColorLists.find(name); + + if (it != mColorLists.end()) + return &it->second; + return 0; } diff --git a/src/resources/colordb.h b/src/resources/colordb.h index 72d34afe8..fb0da0036 100644 --- a/src/resources/colordb.h +++ b/src/resources/colordb.h @@ -29,23 +29,51 @@ */ namespace ColorDB { + class ItemColor + { + public: + ItemColor() + { } + ItemColor(int id, std::string name, std::string color) + { + this->id = id; + this->name = name; + this->color = color; + } + + int id; + std::string name; + std::string color; + }; + /** * Loads the color data from <code>colors.xml</code>. */ void load(); /** + * Loads the color data from <code>colors.xml</code>. + */ + void loadHair(); + + void loadColorLists(); + + /** * Clear the color data */ void unload(); - std::string &get(int id); + std::string &getHairColor(int id); + + int getHairSize(); - int size(); + std::map <int, ItemColor> *getColorsList(std::string name); // Color DB typedef std::map<int, std::string> Colors; typedef Colors::iterator ColorIterator; + typedef std::map <std::string, std::map <int, ItemColor> > ColorLists; + typedef ColorLists::iterator ColorListsIterator; } #endif diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 418bfb848..4ba254cf3 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -22,6 +22,7 @@ #include "resources/itemdb.h" +#include "client.h" #include "log.h" #include "resources/iteminfo.h" @@ -207,6 +208,11 @@ void ItemDB::load() std::string drawBefore = XML::getProperty(node, "drawBefore", ""); std::string drawAfter = XML::getProperty(node, "drawAfter", ""); std::string removeSprite = XML::getProperty(node, "removeSprite", ""); + std::string colors; + if (serverVersion >= 1) + colors = XML::getProperty(node, "colors", ""); + else + colors = ""; std::string tags[3]; tags[0] = XML::getProperty(node, "tag", @@ -266,6 +272,7 @@ void ItemDB::load() itemInfo->setDrawBefore(parseSpriteName(drawBefore)); itemInfo->setDrawAfter(parseSpriteName(drawAfter)); itemInfo->setDrawPriority(drawPriority); + itemInfo->setColorsList(colors); std::string effect; for (int i = 0; i < int(sizeof(fields) / sizeof(fields[0])); ++i) diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index 255a9a7b3..990c78f45 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -81,3 +81,29 @@ std::map<int, int> &ItemInfo::addReplaceSprite(int sprite) } return it->second; } + +void ItemInfo::setColorsList(std::string name) +{ + if (name.empty()) + { + mColors = 0; + mColorList = ""; + } + else + { + mColors = ColorDB::getColorsList(name); + mColorList = name; + } +} + +std::string ItemInfo::getDyeColorsString(int color) const +{ + if (!mColors || mColorList.empty()) + return ""; + + std::map <int, ColorDB::ItemColor>::iterator it = mColors->find(color); + if (it == mColors->end()) + return ""; + + return it->second.color; +}
\ No newline at end of file diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 5ea537fae..297c1b036 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -25,6 +25,7 @@ #include "being.h" +#include "resources/colordb.h" #include "resources/spritedef.h" #include <map> @@ -111,7 +112,9 @@ class ItemInfo mDrawPriority(0), mIsRemoveSprites(false), mAttackAction(SpriteAction::INVALID), - mAttackRange(0) + mAttackRange(0), + mColors(0), + mColorList("") { } @@ -231,6 +234,15 @@ class ItemInfo std::map<int, std::map<int, int> > getSpriteToItemReplaceMap() const { return mSpriteToItemReplaceMap; } + std::string getDyeString(int color) const; + + std::string getDyeColorsString(int color) const; + + void setColorsList(std::string name); + + bool isHaveColors() + { return !mColorList.empty(); } + protected: SpriteDisplay mDisplay; /**< Display info (like icon) */ std::string mName; @@ -265,6 +277,8 @@ class ItemInfo /** Stores the names of sounds to be played at certain event. */ std::map < EquipmentSoundEvent, std::vector<std::string> > mSounds; std::map <int, int> mTags; + std::map <int, ColorDB::ItemColor> *mColors; + std::string mColorList; }; #endif |