summaryrefslogtreecommitdiff
path: root/src/resources/spritedef.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-03-27 23:17:55 +0300
committerAndrei Karas <akaras@inbox.ru>2012-03-27 23:17:55 +0300
commit930eeae09a3a7dc31c047d199c77ef9e284d37ba (patch)
tree733dce14ac39bf3eab15a5cf3e210238adde9447 /src/resources/spritedef.cpp
parent762280b60344ac6e7652e4b34b9614ca18693ddd (diff)
downloadmv-930eeae09a3a7dc31c047d199c77ef9e284d37ba.tar.gz
mv-930eeae09a3a7dc31c047d199c77ef9e284d37ba.tar.bz2
mv-930eeae09a3a7dc31c047d199c77ef9e284d37ba.tar.xz
mv-930eeae09a3a7dc31c047d199c77ef9e284d37ba.zip
Extend sequence animation tag. Allow set in attribute value any frame numbers.
Examples what doing same: <sequence start="55" end="60" delay="75" /> <sequence value="55-60" delay="75" /> <sequence value="55,56,57,58,59,60" delay="75" /> Other examples: <sequence value="55,p,56,p,58,p,59,p,60" delay="75" /> p mean pause.
Diffstat (limited to 'src/resources/spritedef.cpp')
-rw-r--r--src/resources/spritedef.cpp118
1 files changed, 98 insertions, 20 deletions
diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp
index a4ebc6f7e..95e05de93 100644
--- a/src/resources/spritedef.cpp
+++ b/src/resources/spritedef.cpp
@@ -304,13 +304,7 @@ void SpriteDef::loadAnimation(XmlNodePtr animationNode,
{
const int start = XML::getProperty(frameNode, "start", -1);
const int end = XML::getProperty(frameNode, "end", -1);
-
- if (start < 0 || end < 0)
- {
- logger->log1("No valid value for 'start' or 'end'");
- continue;
- }
-
+ const std::string value = XML::getProperty(frameNode, "value", "");
int repeat = XML::getProperty(frameNode, "repeat", 1);
if (repeat < 1)
@@ -319,25 +313,47 @@ void SpriteDef::loadAnimation(XmlNodePtr animationNode,
continue;
}
- while (repeat > 0)
+ if (value.empty())
{
- int pos = start;
- while (end >= pos)
+ if (addSequence(start, end, delay, offsetX, offsetY,
+ variant_offset, repeat, rand, imageSet, animation))
{
- Image *img = imageSet->get(pos + variant_offset);
+ continue;
+ }
- if (!img)
+ }
+ else
+ {
+ std::vector<std::string> vals;
+ splitToStringVector(vals, value, ',');
+ std::vector<std::string>::const_iterator it = vals.begin();
+ std::vector<std::string>::const_iterator it_end = vals.end();
+ for (; it != it_end; ++ it)
+ {
+ std::string str = *it;
+ size_t idx = str.find("-");
+ if (str == "p")
{
- logger->log("No image at index %d",
- pos + variant_offset);
- pos ++;
- continue;
+ animation->addPause(delay, rand);
+ }
+ else if (idx != std::string::npos)
+ {
+ int v1 = atoi(str.substr(0, idx).c_str());
+ int v2 = atoi(str.substr(idx + 1).c_str());
+ addSequence(v1, v2, delay, offsetX, offsetY,
+ variant_offset, repeat, rand, imageSet, animation);
+ }
+ else
+ {
+ Image *img = imageSet->get(atoi(
+ str.c_str()) + variant_offset);
+ if (img)
+ {
+ animation->addFrame(img, delay,
+ offsetX, offsetY, rand);
+ }
}
-
- animation->addFrame(img, delay, offsetX, offsetY, rand);
- pos ++;
}
- repeat --;
}
}
else if (xmlNameEqual(frameNode, "pause"))
@@ -461,3 +477,65 @@ void SpriteDef::addAction(unsigned hp, std::string name, Action *action)
(*mActions[hp])[name] = action;
}
+
+bool SpriteDef::addSequence(int start, int end, int delay,
+ int offsetX, int offsetY, int variant_offset,
+ int repeat, int rand, ImageSet *imageSet,
+ Animation *animation)
+{
+ if (start < 0 || end < 0)
+ {
+ logger->log1("No valid value for 'start' or 'end'");
+ return true;
+ }
+
+ if (start <= end)
+ {
+ while (repeat > 0)
+ {
+ int pos = start;
+ while (end >= pos)
+ {
+ Image *img = imageSet->get(pos + variant_offset);
+
+ if (!img)
+ {
+ logger->log("No image at index %d",
+ pos + variant_offset);
+ pos ++;
+ continue;
+ }
+
+ animation->addFrame(img, delay,
+ offsetX, offsetY, rand);
+ pos ++;
+ }
+ repeat --;
+ }
+ }
+ else
+ {
+ while (repeat > 0)
+ {
+ int pos = start;
+ while (end <= pos)
+ {
+ Image *img = imageSet->get(pos + variant_offset);
+
+ if (!img)
+ {
+ logger->log("No image at index %d",
+ pos + variant_offset);
+ pos ++;
+ continue;
+ }
+
+ animation->addFrame(img, delay,
+ offsetX, offsetY, rand);
+ pos --;
+ }
+ repeat --;
+ }
+ }
+ return false;
+}