summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/actorsprite.cpp2
-rw-r--r--src/being.cpp3
-rw-r--r--src/resources/beinginfo.cpp21
-rw-r--r--src/resources/beinginfo.h6
-rw-r--r--src/resources/monsterdb.cpp4
-rw-r--r--src/utils/stringutils.cpp30
-rw-r--r--src/utils/stringutils.h3
-rw-r--r--src/utils/stringutils_unittest.cc14
8 files changed, 81 insertions, 2 deletions
diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp
index 6875936c4..09d924070 100644
--- a/src/actorsprite.cpp
+++ b/src/actorsprite.cpp
@@ -234,7 +234,7 @@ void ActorSprite::setupSpriteDisplay(const SpriteDisplay &display,
if (!*it)
continue;
const std::string file = paths.getStringValue("sprites").append(
- combineDye2((*it)->sprite, color));
+ combineDye3((*it)->sprite, color));
const int variant = (*it)->variant;
addSprite(AnimatedSprite::delayedLoad(file, variant));
diff --git a/src/being.cpp b/src/being.cpp
index e0d849ce3..67a44c6cf 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -242,7 +242,8 @@ void Being::setSubtype(const uint16_t subtype, const uint8_t look)
if (mInfo)
{
setName(mInfo->getName());
- setupSpriteDisplay(mInfo->getDisplay());
+ setupSpriteDisplay(mInfo->getDisplay(), true, 0,
+ mInfo->getColor(mLook));
mYDiff = mInfo->getSortOffsetY();
}
}
diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp
index b1d6c1d0c..361dead4d 100644
--- a/src/resources/beinginfo.cpp
+++ b/src/resources/beinginfo.cpp
@@ -46,6 +46,7 @@ BeingInfo::BeingInfo() :
| Map::BLOCKMASK_MONSTER | Map::BLOCKMASK_AIR
| Map::BLOCKMASK_WATER),
mBlockType(Map::BLOCKTYPE_CHARACTER),
+ mColors(nullptr),
mTargetOffsetX(0),
mTargetOffsetY(0),
mMaxHP(0),
@@ -151,3 +152,23 @@ void BeingInfo::init()
empty->mMissEffectId = paths.getIntValue("missEffectId");
}
}
+
+void BeingInfo::setColorsList(const std::string &name)
+{
+ if (name.empty())
+ mColors = nullptr;
+ else
+ mColors = ColorDB::getColorsList(name);
+}
+
+std::string BeingInfo::getColor(const int idx) const
+{
+ if (!mColors)
+ return std::string();
+
+ const std::map <int, ColorDB::ItemColor>::const_iterator
+ it = mColors->find(idx);
+ if (it == mColors->end())
+ return std::string();
+ return it->second.color;
+}
diff --git a/src/resources/beinginfo.h b/src/resources/beinginfo.h
index e62dda149..d94e3db30 100644
--- a/src/resources/beinginfo.h
+++ b/src/resources/beinginfo.h
@@ -25,6 +25,7 @@
#include "actorsprite.h"
+#include "resources/colordb.h"
#include "resources/cursor.h"
#include "resources/soundinfo.h"
@@ -207,6 +208,10 @@ class BeingInfo final
void setHeight(const int n)
{ mHeight = n; }
+ void setColorsList(const std::string &name);
+
+ std::string getColor(const int idx) const;
+
static void init();
static void clear();
@@ -220,6 +225,7 @@ class BeingInfo final
Attacks mAttacks;
unsigned char mWalkMask;
Map::BlockType mBlockType;
+ const std::map <int, ColorDB::ItemColor> *mColors;
int mTargetOffsetX;
int mTargetOffsetY;
int mMaxHP;
diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp
index 3d6473fd6..9e8da1b44 100644
--- a/src/resources/monsterdb.cpp
+++ b/src/resources/monsterdb.cpp
@@ -112,12 +112,16 @@ void MonsterDB::loadXmlFile(const std::string &fileName)
currentInfo->setMaxHP(XML::getProperty(monsterNode, "maxHP", 0));
+
currentInfo->setSortOffsetY(XML::getProperty(
monsterNode, "sortOffsetY", 0));
currentInfo->setDeadSortOffsetY(XML::getProperty(
monsterNode, "deadSortOffsetY", 31));
+ currentInfo->setColorsList(XML::getProperty(monsterNode,
+ "colors", ""));
+
unsigned char block = 0;
std::string walkStr = XML::getProperty(
monsterNode, "walkType", "walk");
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index a07cd1a96..a0e31f06d 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -508,6 +508,36 @@ std::string combineDye2(std::string file, const std::string &dye)
}
}
+std::string combineDye3(std::string file, const std::string &dye)
+{
+ if (dye.empty())
+ return file;
+
+ const size_t pos = file.find_last_of("|");
+ if (pos != std::string::npos)
+ {
+ const std::string dye1 = file.substr(pos + 1);
+ std::string str;
+ file = file.substr(0, pos);
+ const std::list<std::string> list1 = splitToStringList(dye1, ';');
+ const std::list<std::string> list2 = splitToStringList(dye, ';');
+ for (std::list<std::string>::const_iterator it1 = list1.begin(),
+ it2 = list2.begin(), it1_end = list1.end(), it2_end = list2.end();
+ it1 != it1_end && it2 != it2_end; ++it1, ++it2)
+ {
+ str.append(*it1).append(":").append(*it2).append(";");
+ }
+ return file.append("|").append(str);
+ }
+ else
+ {
+ if (dye.empty() || file.empty())
+ return file;
+ else
+ return file.append("|").append(dye);
+ }
+}
+
std::string packList(const std::list<std::string> &list)
{
std::list<std::string>::const_iterator i = list.begin();
diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h
index eae73ce40..96645261b 100644
--- a/src/utils/stringutils.h
+++ b/src/utils/stringutils.h
@@ -198,6 +198,9 @@ std::string combineDye(std::string file, const std::string &dye) A_WARN_UNUSED;
std::string combineDye2(std::string file,
const std::string &dye) A_WARN_UNUSED;
+std::string combineDye3(std::string file,
+ const std::string &dye) A_WARN_UNUSED;
+
std::string packList(const std::list<std::string> &list) A_WARN_UNUSED;
std::list<std::string> unpackList(const std::string &str) A_WARN_UNUSED;
diff --git a/src/utils/stringutils_unittest.cc b/src/utils/stringutils_unittest.cc
index d3d274597..75f4f2f35 100644
--- a/src/utils/stringutils_unittest.cc
+++ b/src/utils/stringutils_unittest.cc
@@ -372,6 +372,20 @@ TEST(stringuntils, combineDye2)
combineDye2("test.xml|#43413d,59544f,7a706c;#123456", "W;B"));
}
+TEST(stringuntils, combineDye3)
+{
+ EXPECT_EQ("", combineDye3("", ""));
+ EXPECT_EQ("test", combineDye3("test", ""));
+ EXPECT_EQ("", combineDye3("", "line"));
+ EXPECT_EQ("test.xml|123", combineDye3("test.xml", "123"));
+ EXPECT_EQ("test.xml|#43413d,59544f,7a706c",
+ combineDye3("test.xml|#43413d,59544f,7a706c", ""));
+ EXPECT_EQ("test.xml|#43413d,59544f,7a706c:W;",
+ combineDye3("test.xml|#43413d,59544f,7a706c", "W"));
+ EXPECT_EQ("test.xml|#43413d,59544f,7a706c:W;#123456:B;",
+ combineDye3("test.xml|#43413d,59544f,7a706c;#123456", "W;B"));
+}
+
TEST(stringuntils, packList1)
{
std::list <std::string> list;