summaryrefslogtreecommitdiff
path: root/src/resources/dye.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-03-27 13:25:04 +0100
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-03-27 13:25:24 +0100
commitdd05447445dc1766e532130318af2cb6bb72a994 (patch)
treec8b2cbac64ccf9545a39c143088b57fe2cb8e678 /src/resources/dye.cpp
parent05e753294c1a603252d2eed4b1731c3f50543a7e (diff)
parent2aab736bc5d77ffda789d7de56cef100fac207e1 (diff)
downloadmana-client-dd05447445dc1766e532130318af2cb6bb72a994.tar.gz
mana-client-dd05447445dc1766e532130318af2cb6bb72a994.tar.bz2
mana-client-dd05447445dc1766e532130318af2cb6bb72a994.tar.xz
mana-client-dd05447445dc1766e532130318af2cb6bb72a994.zip
Merge branch 'aethyra/master'
Conflicts: src/beingmanager.cpp src/gui/confirm_dialog.cpp src/gui/inventorywindow.cpp src/gui/inventorywindow.h src/gui/label.cpp src/gui/label.h src/gui/popup.cpp src/gui/popup.h src/gui/scrollarea.cpp src/gui/skin.cpp src/gui/skin.h src/gui/speechbubble.cpp src/gui/window.cpp src/gui/window.h src/localplayer.h src/main.cpp src/net/ea/playerhandler.cpp src/resources/ambientoverlay.h src/resources/dye.cpp src/resources/imagewriter.cpp src/resources/itemdb.cpp src/shopitem.cpp
Diffstat (limited to 'src/resources/dye.cpp')
-rw-r--r--src/resources/dye.cpp37
1 files changed, 29 insertions, 8 deletions
diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp
index 7ba6689f..aa4d6835 100644
--- a/src/resources/dye.cpp
+++ b/src/resources/dye.cpp
@@ -39,23 +39,35 @@ DyePalette::DyePalette(const std::string &description)
int pos = 1;
for (;;)
{
- if (pos + 6 > size) break;
+ if (pos + 6 > size)
+ break;
+
int v = 0;
for (int i = 0; i < 6; ++i)
{
char c = description[pos + i];
int n;
- if ('0' <= c && c <= '9') n = c - '0';
- else if ('A' <= c && c <= 'F') n = c - 'A' + 10;
- else if ('a' <= c && c <= 'f') n = c - 'a' + 10;
- else goto error;
+
+ if ('0' <= c && c <= '9')
+ n = c - '0';
+ else if ('A' <= c && c <= 'F')
+ n = c - 'A' + 10;
+ else if ('a' <= c && c <= 'f')
+ n = c - 'a' + 10;
+ else
+ goto error;
+
v = (v << 4) | n;
}
Color c = { { v >> 16, v >> 8, v } };
mColors.push_back(c);
pos += 6;
- if (pos == size) return;
- if (description[pos] != ',') break;
+
+ if (pos == size)
+ return;
+ if (description[pos] != ',')
+ break;
+
++pos;
}
@@ -122,14 +134,18 @@ Dye::Dye(const std::string &description)
{
std::string::size_type pos = next_pos;
next_pos = description.find(';', pos);
+
if (next_pos == std::string::npos)
next_pos = length;
+
if (next_pos <= pos + 3 || description[pos + 1] != ':')
{
logger->log("Error, invalid dye: %s", description.c_str());
return;
}
+
int i = 0;
+
switch (description[pos])
{
case 'R': i = 0; break;
@@ -143,7 +159,8 @@ Dye::Dye(const std::string &description)
logger->log("Error, invalid dye: %s", description.c_str());
return;
}
- mDyePalettes[i] = new DyePalette(description.substr(pos + 2, next_pos - pos - 2));
+ mDyePalettes[i] = new DyePalette(description.substr(pos + 2,
+ next_pos - pos - 2));
++next_pos;
}
while (next_pos < length);
@@ -180,8 +197,10 @@ void Dye::update(int color[3]) const
void Dye::instantiate(std::string &target, const std::string &palettes)
{
std::string::size_type next_pos = target.find('|');
+
if (next_pos == std::string::npos || palettes.empty())
return;
+
++next_pos;
std::ostringstream s;
@@ -191,8 +210,10 @@ void Dye::instantiate(std::string &target, const std::string &palettes)
{
std::string::size_type pos = next_pos;
next_pos = target.find(';', pos);
+
if (next_pos == std::string::npos)
next_pos = last_pos;
+
if (next_pos == pos + 1 && pal_pos != std::string::npos)
{
std::string::size_type pal_next_pos = palettes.find(';', pal_pos);