summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/resources/dye.cpp16
-rw-r--r--src/resources/resourcemanager.cpp14
-rw-r--r--src/resources/resourcemanager.h3
-rw-r--r--src/resources/spritedef.cpp25
-rw-r--r--src/resources/spritedef.h3
5 files changed, 34 insertions, 27 deletions
diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp
index 3c4bfecc..c27f32c1 100644
--- a/src/resources/dye.cpp
+++ b/src/resources/dye.cpp
@@ -179,16 +179,18 @@ void Dye::update(int color[3]) const
void Dye::instantiate(std::string &target, std::string const &palettes)
{
- std::string::size_type last_pos = target.find('>');
- if (last_pos == std::string::npos || palettes.empty()) return;
- ++last_pos;
+ std::string::size_type next_pos = target.find('|');
+ if (next_pos == std::string::npos || palettes.empty()) return;
+ ++next_pos;
std::ostringstream s;
- std::string::size_type next_pos = 0, pal_pos = 0;
+ s << target.substr(0, next_pos);
+ std::string::size_type last_pos = target.length(), pal_pos = 0;
do
{
std::string::size_type pos = next_pos;
- next_pos = target.find_first_of(">;", pos);
+ next_pos = target.find(';', pos);
+ if (next_pos == std::string::npos) next_pos = last_pos;
if (next_pos == pos + 1)
{
std::string::size_type pal_next_pos = palettes.find(';');
@@ -196,6 +198,7 @@ void Dye::instantiate(std::string &target, std::string const &palettes)
if (pal_next_pos == std::string::npos)
{
s << palettes.substr(pal_pos);
+ s << target.substr(next_pos);
break;
}
s << palettes.substr(pal_pos, pal_next_pos - pal_pos);
@@ -213,8 +216,7 @@ void Dye::instantiate(std::string &target, std::string const &palettes)
s << target[next_pos];
++next_pos;
}
- while (next_pos != last_pos);
+ while (next_pos < last_pos);
- s << target.substr(next_pos);
target = s.str();
}
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 8079e424..3368d05b 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -225,12 +225,12 @@ struct DyedImageLoader
{
DyedImageLoader *l = static_cast< DyedImageLoader * >(v);
std::string path = l->path;
- std::string::size_type p = path.find('>');
+ std::string::size_type p = path.find('|');
Dye *d = NULL;
if (p != std::string::npos)
{
- d = new Dye(path.substr(0, p));
- path = path.substr(p + 1);
+ d = new Dye(path.substr(p + 1));
+ path = path.substr(0, p);
}
int fileSize;
void *buffer = l->manager->loadFile(path, fileSize);
@@ -276,19 +276,19 @@ ResourceManager::getImageSet(const std::string &imagePath, int w, int h)
struct SpriteDefLoader
{
- std::string path, palettes;
+ std::string path;
int variant;
static Resource *load(void *v)
{
SpriteDefLoader *l = static_cast< SpriteDefLoader * >(v);
- return SpriteDef::load(l->path, l->variant /*, l->palettes*/);
+ return SpriteDef::load(l->path, l->variant);
}
};
SpriteDef *ResourceManager::getSprite
- (std::string const &path, int variant, std::string const &palettes)
+ (std::string const &path, int variant)
{
- SpriteDefLoader l = { path, palettes, variant };
+ SpriteDefLoader l = { path, variant };
std::stringstream ss;
ss << path << "[" << variant << "]";
return static_cast<SpriteDef*>(get(ss.str(), SpriteDefLoader::load, &l));
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h
index eb883687..c52248b1 100644
--- a/src/resources/resourcemanager.h
+++ b/src/resources/resourcemanager.h
@@ -151,8 +151,7 @@ class ResourceManager
* Creates a sprite definition based on a given path and the supplied
* variant.
*/
- SpriteDef *getSprite(std::string const &path, int variant = 0,
- std::string const &palettes = std::string());
+ SpriteDef *getSprite(std::string const &path, int variant = 0);
/**
* Releases a resource, removing it from the set of loaded resources.
diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp
index 45a52d2e..de6f8d0b 100644
--- a/src/resources/spritedef.cpp
+++ b/src/resources/spritedef.cpp
@@ -25,14 +25,14 @@
#include "spritedef.h"
-#include "../log.h"
-
-#include "animation.h"
#include "action.h"
-#include "resourcemanager.h"
-#include "imageset.h"
+#include "animation.h"
+#include "dye.h"
#include "image.h"
+#include "imageset.h"
+#include "resourcemanager.h"
+#include "../log.h"
#include "../utils/xml.h"
Action*
@@ -53,7 +53,14 @@ SpriteDef *SpriteDef::load(std::string const &animationFile, int variant)
{
int size;
ResourceManager *resman = ResourceManager::getInstance();
- char *data = (char*) resman->loadFile(animationFile.c_str(), size);
+
+ std::string::size_type pos = animationFile.find('|');
+ std::string palettes;
+ if (pos != std::string::npos)
+ palettes = animationFile.substr(pos + 1);
+
+ char *data = (char*) resman->loadFile
+ (animationFile.substr(0, pos).c_str(), size);
if (!data) return NULL;
@@ -89,7 +96,7 @@ SpriteDef *SpriteDef::load(std::string const &animationFile, int variant)
{
if (xmlStrEqual(node->name, BAD_CAST "imageset"))
{
- def->loadImageSet(node);
+ def->loadImageSet(node, palettes);
}
else if (xmlStrEqual(node->name, BAD_CAST "action"))
{
@@ -125,13 +132,13 @@ void SpriteDef::substituteActions()
substituteAction(ACTION_DEAD, ACTION_HURT);
}
-void
-SpriteDef::loadImageSet(xmlNodePtr node)
+void SpriteDef::loadImageSet(xmlNodePtr node, std::string const &palettes)
{
int width = XML::getProperty(node, "width", 0);
int height = XML::getProperty(node, "height", 0);
std::string name = XML::getProperty(node, "name", "");
std::string imageSrc = XML::getProperty(node, "src", "");
+ Dye::instantiate(imageSrc, palettes);
ResourceManager *resman = ResourceManager::getInstance();
ImageSet *imageSet = resman->getImageSet(imageSrc, width, height);
diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h
index 121f23cc..4f316875 100644
--- a/src/resources/spritedef.h
+++ b/src/resources/spritedef.h
@@ -95,8 +95,7 @@ class SpriteDef : public Resource
/**
* Loads an imageset element.
*/
- void
- loadImageSet(xmlNodePtr node);
+ void loadImageSet(xmlNodePtr node, std::string const &palettes);
/**
* Loads an action element.