diff options
author | Philipp Sehmisch <tmw@crushnet.org> | 2006-09-16 17:13:34 +0000 |
---|---|---|
committer | Philipp Sehmisch <tmw@crushnet.org> | 2006-09-16 17:13:34 +0000 |
commit | e9ce90588d9649084fbeac0ec016946ecdc0236b (patch) | |
tree | bda12c266e88bccd695380a527dd0f683ee5deba /src | |
parent | 3dd5378899a9bf12b3c17ff39d9390155a5a49d2 (diff) | |
download | mana-e9ce90588d9649084fbeac0ec016946ecdc0236b.tar.gz mana-e9ce90588d9649084fbeac0ec016946ecdc0236b.tar.bz2 mana-e9ce90588d9649084fbeac0ec016946ecdc0236b.tar.xz mana-e9ce90588d9649084fbeac0ec016946ecdc0236b.zip |
Fixed the crash when attacking without a weapon, some additional stability improvements and more descriptive variable names in the parsing algorithmn.
Diffstat (limited to 'src')
-rw-r--r-- | src/animatedsprite.cpp | 62 | ||||
-rw-r--r-- | src/animatedsprite.h | 6 |
2 files changed, 43 insertions, 25 deletions
diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index 269e1fe6..79aa189c 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -89,7 +89,7 @@ AnimatedSprite::AnimatedSprite(const std::string& animationFile, int variant): // get action else if (xmlStrEqual(node->name, BAD_CAST "action")) { - std::string name = getProperty(node, "name", ""); + std::string actionName = getProperty(node, "name", ""); std::string imageset = getProperty(node, "imageset", ""); if (mSpritesets.find(imageset) == mSpritesets.end()) { @@ -101,28 +101,24 @@ AnimatedSprite::AnimatedSprite(const std::string& animationFile, int variant): continue; } - Action *action = new Action(); - - action->setSpriteset(mSpritesets[imageset]); - SpriteAction actionname = makeSpriteAction(name); - if (actionname == ACTION_INVALID) + SpriteAction actionEnum = makeSpriteAction(actionName); + if (actionEnum == ACTION_INVALID) { - logger->log("Warning: Unknown action \"%s\" defined in %s", - name.c_str(), - animationFile.c_str()); + actionName.c_str(), + animationFile.c_str()); continue; } - else { - mActions[makeSpriteAction(name)] = action; + Action *action = new Action(); + action->setSpriteset(mSpritesets[imageset]); + mActions[actionEnum] = action; - // When first action set it as default direction - if (mActions.empty()) - { - mActions[ACTION_DEFAULT] = action; - } - }; + // When first action set it as default direction + if (mActions.empty()) + { + mActions[ACTION_DEFAULT] = action; + } // get animations @@ -134,9 +130,20 @@ AnimatedSprite::AnimatedSprite(const std::string& animationFile, int variant): if (!xmlStrEqual(animationNode->name, BAD_CAST "animation")) continue; - std::string dir = getProperty(animationNode, "direction", ""); + std::string directionName = getProperty(animationNode, "direction", ""); + + SpriteDirection directionEnum = makeSpriteDirection(directionName); + if (directionEnum == DIRECTION_INVALID) + { + logger->log("Warning: Unknown direction \"%s\" defined for action %s in %s", + directionName.c_str(), + actionName.c_str(), + animationFile.c_str()); + continue; + } + Animation *animation = new Animation(); - action->setAnimation(makeSpriteDirection(dir), animation); + action->setAnimation(directionEnum, animation); // Get animation phases for (xmlNodePtr phaseNode = animationNode->xmlChildrenNode; @@ -281,8 +288,11 @@ AnimatedSprite::play(SpriteAction action, int time) if (!mAction || !time) mSpeed = 1.0f; else { - int animationLength = mAction->getAnimation(mDirection)->getLength(); - mSpeed = (float) animationLength / time; + Animation* animation= mAction->getAnimation(mDirection); + if (animation) { + int animationLength = animation->getLength(); + mSpeed = (float) animationLength / time; + } } } @@ -391,7 +401,10 @@ AnimatedSprite::makeSpriteAction(const std::string& action) SpriteDirection AnimatedSprite::makeSpriteDirection(const std::string& direction) { - if (direction == "up") { + if (direction == "" || direction == "default") { + return DIRECTION_DEFAULT; + } + else if (direction == "up") { return DIRECTION_UP; } else if (direction == "left") { @@ -400,7 +413,10 @@ AnimatedSprite::makeSpriteDirection(const std::string& direction) else if (direction == "right") { return DIRECTION_RIGHT; } - else { + else if (direction == "down") { return DIRECTION_DOWN; } + else { + return DIRECTION_INVALID; + }; } diff --git a/src/animatedsprite.h b/src/animatedsprite.h index 7ca87237..ea661d94 100644 --- a/src/animatedsprite.h +++ b/src/animatedsprite.h @@ -56,10 +56,12 @@ enum SpriteAction enum SpriteDirection { - DIRECTION_DOWN = 0, + DIRECTION_DEFAULT = 0, + DIRECTION_DOWN, DIRECTION_UP, DIRECTION_LEFT, - DIRECTION_RIGHT + DIRECTION_RIGHT, + DIRECTION_INVALID }; /** |