diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-10-03 23:36:33 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-10-03 23:36:33 +0300 |
commit | c0739f1da1865cc1c9f54ba09fe23ac95bc99f7e (patch) | |
tree | 9d389e320b02132be645847a0afbdc1e75cc7bef | |
parent | 15f62e0e81649e9bda6a054d00a63a14972db8d5 (diff) | |
download | manaplus-c0739f1da1865cc1c9f54ba09fe23ac95bc99f7e.tar.gz manaplus-c0739f1da1865cc1c9f54ba09fe23ac95bc99f7e.tar.bz2 manaplus-c0739f1da1865cc1c9f54ba09fe23ac95bc99f7e.tar.xz manaplus-c0739f1da1865cc1c9f54ba09fe23ac95bc99f7e.zip |
Add support for set imageset by name for each tag in animation.
-rw-r--r-- | src/resources/sprite/spritedef.cpp | 41 | ||||
-rw-r--r-- | src/resources/sprite/spritedef.h | 3 |
2 files changed, 30 insertions, 14 deletions
diff --git a/src/resources/sprite/spritedef.cpp b/src/resources/sprite/spritedef.cpp index 037936dc3..85c5ba547 100644 --- a/src/resources/sprite/spritedef.cpp +++ b/src/resources/sprite/spritedef.cpp @@ -261,6 +261,20 @@ void SpriteDef::loadImageSet(const XmlNodePtr node, mImageSets[name] = imageSet; } +const ImageSet *SpriteDef::getImageSet(const std::string &imageSetName) const +{ + const ImageSetCIterator si = mImageSets.find(imageSetName); + if (si == mImageSets.end()) + { + reportAlways("%s: Imageset \"%s\" not defined in %s", + mSource.c_str(), + imageSetName.c_str(), + getIdPath().c_str()); + return nullptr; + } + return si->second; +} + void SpriteDef::loadAction(const XmlNodePtr node, const int variant_offset) { @@ -270,17 +284,7 @@ void SpriteDef::loadAction(const XmlNodePtr node, const std::string actionName = XML::getProperty(node, "name", ""); const std::string imageSetName = XML::getProperty(node, "imageset", ""); const unsigned hp = XML::getProperty(node, "hp", 100); - - const ImageSetIterator si = mImageSets.find(imageSetName); - if (si == mImageSets.end()) - { - reportAlways("%s: Imageset \"%s\" not defined in %s", - mSource.c_str(), - imageSetName.c_str(), - getIdPath().c_str()); - return; - } - const ImageSet *const imageSet = si->second; + const ImageSet *const imageSet = getImageSet(imageSetName); if (actionName == SpriteAction::INVALID) { @@ -313,10 +317,10 @@ void SpriteDef::loadAction(const XmlNodePtr node, void SpriteDef::loadAnimation(const XmlNodePtr animationNode, Action *const action, - const ImageSet *const imageSet, + const ImageSet *const imageSet0, const int variant_offset) const { - if (!action || !imageSet || !animationNode) + if (!action || !imageSet0 || !animationNode) return; const std::string directionName = @@ -341,6 +345,16 @@ void SpriteDef::loadAnimation(const XmlNodePtr animationNode, { const int delay = XML::getIntProperty( frameNode, "delay", 0, 0, 100000); + const std::string imageSetName = XML::getProperty(frameNode, + "imageset", + ""); + const ImageSet *imageSet = imageSet0; + if (!imageSetName.empty()) + { + imageSet = getImageSet(imageSetName); + if (imageSet == nullptr) + imageSet = imageSet; + } const int offsetX = XML::getProperty(frameNode, "offsetX", 0) + imageSet->getOffsetX() - imageSet->getWidth() / 2 + mapTileSize / 2; @@ -362,7 +376,6 @@ void SpriteDef::loadAnimation(const XmlNodePtr animationNode, } Image *const img = imageSet->get(index + variant_offset); - if (!img) { reportAlways("%s: No image at index %d at direction '%s'", diff --git a/src/resources/sprite/spritedef.h b/src/resources/sprite/spritedef.h index f9e33ee65..ff327b20b 100644 --- a/src/resources/sprite/spritedef.h +++ b/src/resources/sprite/spritedef.h @@ -130,6 +130,8 @@ class SpriteDef final : public Resource void includeSprite(const XmlNodePtr includeNode, const int variant); + const ImageSet *getImageSet(const std::string &imageSetName) const; + /** * Complete missing actions by copying existing ones. */ @@ -149,6 +151,7 @@ class SpriteDef final : public Resource typedef std::map<std::string, ImageSet*> ImageSets; typedef ImageSets::iterator ImageSetIterator; + typedef ImageSets::const_iterator ImageSetCIterator; typedef std::map<std::string, Action*> ActionMap; typedef std::map<unsigned, ActionMap*> Actions; typedef Actions::const_iterator ActionsConstIter; |