diff options
author | Ira Rice <irarice@gmail.com> | 2009-03-26 19:09:31 -0600 |
---|---|---|
committer | Ira Rice <irarice@gmail.com> | 2009-03-26 19:09:31 -0600 |
commit | 1a9d402bec2fd8166ce50e30a71ba0cf2f27281a (patch) | |
tree | e012433f561406ebd67d685f205c86c1c13681b3 /src/resources/dye.cpp | |
parent | 2ec46b9a6e5ca1beb043da00cf2bb9d34722ec72 (diff) | |
download | mana-1a9d402bec2fd8166ce50e30a71ba0cf2f27281a.tar.gz mana-1a9d402bec2fd8166ce50e30a71ba0cf2f27281a.tar.bz2 mana-1a9d402bec2fd8166ce50e30a71ba0cf2f27281a.tar.xz mana-1a9d402bec2fd8166ce50e30a71ba0cf2f27281a.zip |
Some code style commits influenced by TMW commit
1715d0afe44a282a356ca88e47c92ec556f094dd
Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src/resources/dye.cpp')
-rw-r--r-- | src/resources/dye.cpp | 54 |
1 files changed, 38 insertions, 16 deletions
diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp index 38249ddb..35a8ca89 100644 --- a/src/resources/dye.cpp +++ b/src/resources/dye.cpp @@ -29,33 +29,42 @@ DyePalette::DyePalette(const std::string &description) { int size = description.length(); - if (size == 0) return; - if (description[0] != '#') - { + if (size == 0 || description[0] != '#') // TODO: load palette from file. return; - } 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; } @@ -114,21 +123,26 @@ Dye::Dye(const std::string &description) for (int i = 0; i < 7; ++i) mDyePalettes[i] = 0; - if (description.empty()) return; + if (description.empty()) + return; std::string::size_type next_pos = 0, length = description.length(); do { 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; @@ -142,7 +156,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); @@ -157,7 +172,8 @@ Dye::~Dye() void Dye::update(int color[3]) const { int cmax = std::max(color[0], std::max(color[1], color[2])); - if (cmax == 0) return; + if (cmax == 0) + return; int cmin = std::min(color[0], std::min(color[1], color[2])); int intensity = color[0] + color[1] + color[2]; @@ -178,7 +194,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; + + if (next_pos == std::string::npos || palettes.empty()) + return; + ++next_pos; std::ostringstream s; @@ -188,7 +207,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 == 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); |