diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-05-19 15:21:11 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-05-19 15:21:11 +0300 |
commit | ad3ee95f90bfd368a511407c13718b900e44be0f (patch) | |
tree | f3f41b9802d684d784b7cef05e0d6ae2383b5e5b | |
parent | fba4289e53447a09dcf82211e2dab3563e2581f1 (diff) | |
download | mv-ad3ee95f90bfd368a511407c13718b900e44be0f.tar.gz mv-ad3ee95f90bfd368a511407c13718b900e44be0f.tar.bz2 mv-ad3ee95f90bfd368a511407c13718b900e44be0f.tar.xz mv-ad3ee95f90bfd368a511407c13718b900e44be0f.zip |
Move spritedirection into separate file.
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/animatedsprite.cpp | 4 | ||||
-rw-r--r-- | src/animatedsprite.h | 4 | ||||
-rw-r--r-- | src/being/being.cpp | 32 | ||||
-rw-r--r-- | src/being/being.h | 4 | ||||
-rw-r--r-- | src/being/compoundsprite.cpp | 2 | ||||
-rw-r--r-- | src/being/compoundsprite.h | 2 | ||||
-rw-r--r-- | src/imagesprite.h | 2 | ||||
-rw-r--r-- | src/resources/action.cpp | 15 | ||||
-rw-r--r-- | src/resources/action.h | 4 | ||||
-rw-r--r-- | src/resources/db/itemdb.cpp | 40 | ||||
-rw-r--r-- | src/resources/iteminfo.cpp | 40 | ||||
-rw-r--r-- | src/resources/spritedef.cpp | 27 | ||||
-rw-r--r-- | src/resources/spritedef.h | 18 | ||||
-rw-r--r-- | src/resources/spritedirection.h | 43 | ||||
-rw-r--r-- | src/sprite.h | 3 |
17 files changed, 139 insertions, 103 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e4c60fa76..22afcb8ed 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -600,6 +600,7 @@ SET(SRCS resources/spriteaction.h resources/spritedef.h resources/spritedef.cpp + resources/spritedirection.h resources/spritedisplay.h resources/spritereference.h resources/subimage.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 2d5a1f3e0..8d89bf185 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -708,6 +708,7 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ resources/spriteaction.h \ resources/spritedef.cpp \ resources/spritedef.h \ + resources/spritedirection.h \ resources/subimage.cpp \ resources/subimage.h \ resources/surfaceimagehelper.cpp \ diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index eacdd5e8d..a68cfcdd9 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -39,7 +39,7 @@ bool AnimatedSprite::mEnableCache = false; AnimatedSprite::AnimatedSprite(SpriteDef *const sprite): - mDirection(DIRECTION_DOWN), + mDirection(SpriteDirection::DOWN), mLastTime(0), mFrameIndex(0), mFrameTime(0), @@ -303,7 +303,7 @@ void AnimatedSprite::draw(Graphics *const graphics, posX + mFrame->offsetX, posY + mFrame->offsetY); } -bool AnimatedSprite::setSpriteDirection(const SpriteDirection direction) +bool AnimatedSprite::setSpriteDirection(const SpriteDirection::Type direction) { if (mDirection != direction) { diff --git a/src/animatedsprite.h b/src/animatedsprite.h index 4bef6face..2bf5815a0 100644 --- a/src/animatedsprite.h +++ b/src/animatedsprite.h @@ -78,7 +78,7 @@ class AnimatedSprite final : public Sprite const Image* getImage() const A_WARN_UNUSED; - bool setSpriteDirection(const SpriteDirection direction); + bool setSpriteDirection(const SpriteDirection::Type direction); int getNumberOfLayers() const A_WARN_UNUSED { return 1; } @@ -128,7 +128,7 @@ class AnimatedSprite final : public Sprite void setDelayLoad(const std::string &filename, const int variant); - SpriteDirection mDirection; /**< The sprite direction. */ + SpriteDirection::Type mDirection; /**< The sprite direction. */ int mLastTime; /**< The last time update was called. */ unsigned int mFrameIndex; /**< The index of the current frame. */ diff --git a/src/being/being.cpp b/src/being/being.cpp index 513fe9322..5eb26d1a3 100644 --- a/src/being/being.cpp +++ b/src/being/being.cpp @@ -154,7 +154,7 @@ Being::Being(const int id, mSubType(0xFFFF), mDirection(BeingDirection::DOWN), mDirectionDelayed(0), - mSpriteDirection(DIRECTION_DOWN), + mSpriteDirection(SpriteDirection::DOWN), mShowName(false), mIsGM(false), mType(type), @@ -1177,17 +1177,17 @@ void Being::setAction(const BeingAction::Action &action, const int attackId) int rotation; switch (mSpriteDirection) { - case DIRECTION_DOWN: + case SpriteDirection::DOWN: default: rotation = 0; break; - case DIRECTION_LEFT: + case SpriteDirection::LEFT: rotation = 90; break; - case DIRECTION_UP: + case SpriteDirection::UP: rotation = 180; break; - case DIRECTION_RIGHT: + case SpriteDirection::RIGHT: rotation = 270; break; } @@ -1262,32 +1262,32 @@ void Being::setDirection(const uint8_t direction) if (!mFaceDirection) mFaceDirection = direction; - SpriteDirection dir; + SpriteDirection::Type dir; if (mFaceDirection & BeingDirection::UP) { if (mFaceDirection & BeingDirection::LEFT) - dir = DIRECTION_UPLEFT; + dir = SpriteDirection::UPLEFT; else if (mFaceDirection & BeingDirection::RIGHT) - dir = DIRECTION_UPRIGHT; + dir = SpriteDirection::UPRIGHT; else - dir = DIRECTION_UP; + dir = SpriteDirection::UP; } else if (mFaceDirection & BeingDirection::DOWN) { if (mFaceDirection & BeingDirection::LEFT) - dir = DIRECTION_DOWNLEFT; + dir = SpriteDirection::DOWNLEFT; else if (mFaceDirection & BeingDirection::RIGHT) - dir = DIRECTION_DOWNRIGHT; + dir = SpriteDirection::DOWNRIGHT; else - dir = DIRECTION_DOWN; + dir = SpriteDirection::DOWN; } else if (mFaceDirection & BeingDirection::RIGHT) { - dir = DIRECTION_RIGHT; + dir = SpriteDirection::RIGHT; } else { - dir = DIRECTION_LEFT; + dir = SpriteDirection::LEFT; } mSpriteDirection = static_cast<uint8_t>(dir); @@ -2992,8 +2992,8 @@ void Being::setEmote(const uint8_t emotion, const int emote_time) if (mEmotionSprite) { mEmotionSprite->play(mSpriteAction); - mEmotionSprite->setSpriteDirection(static_cast<SpriteDirection>( - mSpriteDirection)); + mEmotionSprite->setSpriteDirection( + static_cast<SpriteDirection::Type>(mSpriteDirection)); } else { diff --git a/src/being/being.h b/src/being/being.h index 020c97e45..9ae57d545 100644 --- a/src/being/being.h +++ b/src/being/being.h @@ -492,8 +492,8 @@ class Being : public ActorSprite, public ConfigListener /** * Returns the direction the being is facing. */ - SpriteDirection getSpriteDirection() const A_WARN_UNUSED - { return static_cast<SpriteDirection>(mSpriteDirection); } + SpriteDirection::Type getSpriteDirection() const A_WARN_UNUSED + { return static_cast<SpriteDirection::Type>(mSpriteDirection); } void setPosition(const Vector &pos) override; diff --git a/src/being/compoundsprite.cpp b/src/being/compoundsprite.cpp index d355deafc..35599978b 100644 --- a/src/being/compoundsprite.cpp +++ b/src/being/compoundsprite.cpp @@ -196,7 +196,7 @@ const Image *CompoundSprite::getImage() const return mImage; } -bool CompoundSprite::setSpriteDirection(const SpriteDirection direction) +bool CompoundSprite::setSpriteDirection(const SpriteDirection::Type direction) { bool ret = false; FOR_EACH (SpriteIterator, it, mSprites) diff --git a/src/being/compoundsprite.h b/src/being/compoundsprite.h index b36da2d1f..05559045e 100644 --- a/src/being/compoundsprite.h +++ b/src/being/compoundsprite.h @@ -65,7 +65,7 @@ public: virtual const Image *getImage() const override final A_WARN_UNUSED; - virtual bool setSpriteDirection(const SpriteDirection direction) + virtual bool setSpriteDirection(const SpriteDirection::Type direction) override final; int getNumberOfLayers() const A_WARN_UNUSED; diff --git a/src/imagesprite.h b/src/imagesprite.h index fb542c951..7d936b7f7 100644 --- a/src/imagesprite.h +++ b/src/imagesprite.h @@ -58,7 +58,7 @@ public: const Image* getImage() const A_WARN_UNUSED { return mImage; } - bool setSpriteDirection(const SpriteDirection + bool setSpriteDirection(const SpriteDirection::Type direction A_UNUSED) override final { return false; } diff --git a/src/resources/action.cpp b/src/resources/action.cpp index cbcf4f72b..8576ffab8 100644 --- a/src/resources/action.cpp +++ b/src/resources/action.cpp @@ -39,20 +39,21 @@ Action::~Action() delete_all(mAnimations); } -const Animation *Action::getAnimation(SpriteDirection direction) const noexcept +const Animation *Action::getAnimation(SpriteDirection::Type direction) + const noexcept { Animations::const_iterator i = mAnimations.find(direction); if (i == mAnimations.end()) { - if (direction == DIRECTION_UPLEFT || direction == DIRECTION_UPRIGHT) + if (direction == SpriteDirection::UPLEFT || direction == SpriteDirection::UPRIGHT) { - direction = DIRECTION_UP; + direction = SpriteDirection::UP; } - else if (direction == DIRECTION_DOWNLEFT - || direction == DIRECTION_DOWNRIGHT) + else if (direction == SpriteDirection::DOWNLEFT + || direction == SpriteDirection::DOWNRIGHT) { - direction = DIRECTION_DOWN; + direction = SpriteDirection::DOWN; } i = mAnimations.find(direction); @@ -65,7 +66,7 @@ const Animation *Action::getAnimation(SpriteDirection direction) const noexcept return (i == mAnimations.end()) ? nullptr : i->second; } -void Action::setAnimation(const SpriteDirection direction, +void Action::setAnimation(const SpriteDirection::Type direction, Animation *const animation) noexcept { mAnimations[direction] = animation; diff --git a/src/resources/action.h b/src/resources/action.h index 64d8b40d8..2571508d3 100644 --- a/src/resources/action.h +++ b/src/resources/action.h @@ -43,10 +43,10 @@ class Action final ~Action(); - void setAnimation(const SpriteDirection direction, + void setAnimation(const SpriteDirection::Type direction, Animation *const animation) noexcept; - const Animation *getAnimation(SpriteDirection direction) const + const Animation *getAnimation(SpriteDirection::Type direction) const noexcept A_WARN_UNUSED; unsigned getNumber() const noexcept A_WARN_UNUSED diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp index 32b0ee67c..f20db0c76 100644 --- a/src/resources/db/itemdb.cpp +++ b/src/resources/db/itemdb.cpp @@ -690,40 +690,40 @@ int parseDirectionName(const std::string &name) if (name == "down") { if (serverVersion > 0) - id = DIRECTION_DOWN; + id = SpriteDirection::DOWN; else id = -2; } else if (name == "downleft" || name == "leftdown") { - id = DIRECTION_DOWNLEFT; + id = SpriteDirection::DOWNLEFT; } else if (name == "left") { - id = DIRECTION_LEFT; + id = SpriteDirection::LEFT; } else if (name == "upleft" || name == "leftup") { - id = DIRECTION_UPLEFT; + id = SpriteDirection::UPLEFT; } else if (name == "up") { if (serverVersion > 0) - id = DIRECTION_UP; + id = SpriteDirection::UP; else id = -3; } else if (name == "upright" || name == "rightup") { - id = DIRECTION_UPRIGHT; + id = SpriteDirection::UPRIGHT; } else if (name == "right") { - id = DIRECTION_RIGHT; + id = SpriteDirection::RIGHT; } else if (name == "downright" || name == "rightdown") { - id = DIRECTION_DOWNRIGHT; + id = SpriteDirection::DOWNRIGHT; } else if (name == "downall") { @@ -848,11 +848,11 @@ void loadReplaceSprite(ItemInfo *const itemInfo, case -2: { itemInfo->addReplaceSprite(parseSpriteName( - removeSprite), DIRECTION_DOWN); + removeSprite), SpriteDirection::DOWN); itemInfo->addReplaceSprite(parseSpriteName( - removeSprite), DIRECTION_DOWNLEFT); + removeSprite), SpriteDirection::DOWNLEFT); itemInfo->addReplaceSprite(parseSpriteName( - removeSprite), DIRECTION_DOWNRIGHT); + removeSprite), SpriteDirection::DOWNRIGHT); for_each_xml_child_node(itemNode, replaceNode) { @@ -861,17 +861,17 @@ void loadReplaceSprite(ItemInfo *const itemInfo, const int from = XML::getProperty(itemNode, "from", 0); const int to = XML::getProperty(itemNode, "to", 1); std::map<int, int> *mapList = itemInfo->addReplaceSprite( - parseSpriteName(removeSprite), DIRECTION_DOWN); + parseSpriteName(removeSprite), SpriteDirection::DOWN); if (mapList) (*mapList)[from] = to; mapList = itemInfo->addReplaceSprite(parseSpriteName( - removeSprite), DIRECTION_DOWNLEFT); + removeSprite), SpriteDirection::DOWNLEFT); if (mapList) (*mapList)[from] = to; mapList = itemInfo->addReplaceSprite(parseSpriteName( - removeSprite), DIRECTION_DOWNRIGHT); + removeSprite), SpriteDirection::DOWNRIGHT); if (mapList) (*mapList)[from] = to; } @@ -881,11 +881,11 @@ void loadReplaceSprite(ItemInfo *const itemInfo, case -3: { itemInfo->addReplaceSprite(parseSpriteName( - removeSprite), DIRECTION_UP); + removeSprite), SpriteDirection::UP); itemInfo->addReplaceSprite(parseSpriteName( - removeSprite), DIRECTION_UPLEFT); + removeSprite), SpriteDirection::UPLEFT); itemInfo->addReplaceSprite(parseSpriteName( - removeSprite), DIRECTION_UPRIGHT); + removeSprite), SpriteDirection::UPRIGHT); for_each_xml_child_node(itemNode, replaceNode) { @@ -894,17 +894,17 @@ void loadReplaceSprite(ItemInfo *const itemInfo, const int from = XML::getProperty(itemNode, "from", 0); const int to = XML::getProperty(itemNode, "to", 1); std::map<int, int> *mapList = itemInfo->addReplaceSprite( - parseSpriteName(removeSprite), DIRECTION_UP); + parseSpriteName(removeSprite), SpriteDirection::UP); if (mapList) (*mapList)[from] = to; mapList = itemInfo->addReplaceSprite(parseSpriteName( - removeSprite), DIRECTION_UPLEFT); + removeSprite), SpriteDirection::UPLEFT); if (mapList) (*mapList)[from] = to; mapList = itemInfo->addReplaceSprite(parseSpriteName( - removeSprite), DIRECTION_UPRIGHT); + removeSprite), SpriteDirection::UPRIGHT); if (mapList) (*mapList)[from] = to; } diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index a79a678e3..6dbb90d2a 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -249,11 +249,11 @@ const SpriteToItemMap *ItemInfo::getSpriteToItemReplaceMap(const int direction) SpriteToItemMap *const spMap = mSpriteToItemReplaceMap[direction]; if (spMap) return spMap; - if (direction == DIRECTION_UPLEFT || direction == DIRECTION_UPRIGHT) - return mSpriteToItemReplaceMap[DIRECTION_UP]; + if (direction == SpriteDirection::UPLEFT || direction == SpriteDirection::UPRIGHT) + return mSpriteToItemReplaceMap[SpriteDirection::UP]; - if (direction == DIRECTION_DOWNLEFT || direction == DIRECTION_DOWNRIGHT) - return mSpriteToItemReplaceMap[DIRECTION_DOWN]; + if (direction == SpriteDirection::DOWNLEFT || direction == SpriteDirection::DOWNRIGHT) + return mSpriteToItemReplaceMap[SpriteDirection::DOWN]; return nullptr; } @@ -276,16 +276,16 @@ void ItemInfo::setSpriteOrder(int *const ptr, } case -2: { - ptr[DIRECTION_DOWN] = n; - ptr[DIRECTION_DOWNLEFT] = n; - ptr[DIRECTION_DOWNRIGHT] = n; + ptr[SpriteDirection::DOWN] = n; + ptr[SpriteDirection::DOWNLEFT] = n; + ptr[SpriteDirection::DOWNRIGHT] = n; return; } case -3: { - ptr[DIRECTION_UP] = n; - ptr[DIRECTION_UPLEFT] = n; - ptr[DIRECTION_UPRIGHT] = n; + ptr[SpriteDirection::UP] = n; + ptr[SpriteDirection::UPLEFT] = n; + ptr[SpriteDirection::UPRIGHT] = n; return; } default: @@ -294,19 +294,19 @@ void ItemInfo::setSpriteOrder(int *const ptr, if (direction < 0 || direction >= 9) return; - if (direction == DIRECTION_UP) + if (direction == SpriteDirection::UP) { - if (ptr[DIRECTION_UPLEFT] == def) - ptr[DIRECTION_UPLEFT] = n; - if (ptr[DIRECTION_UPRIGHT] == def) - ptr[DIRECTION_UPRIGHT] = n; + if (ptr[SpriteDirection::UPLEFT] == def) + ptr[SpriteDirection::UPLEFT] = n; + if (ptr[SpriteDirection::UPRIGHT] == def) + ptr[SpriteDirection::UPRIGHT] = n; } - else if (direction == DIRECTION_DOWN) + else if (direction == SpriteDirection::DOWN) { - if (ptr[DIRECTION_DOWNLEFT] == def) - ptr[DIRECTION_DOWNLEFT] = n; - if (ptr[DIRECTION_DOWNRIGHT] == def) - ptr[DIRECTION_DOWNRIGHT] = n; + if (ptr[SpriteDirection::DOWNLEFT] == def) + ptr[SpriteDirection::DOWNLEFT] = n; + if (ptr[SpriteDirection::DOWNRIGHT] == def) + ptr[SpriteDirection::DOWNRIGHT] = n; } ptr[direction] = n; } diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index 10617b248..e7a751feb 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -281,9 +281,9 @@ void SpriteDef::loadAnimation(const XmlNodePtr animationNode, const std::string directionName = XML::getProperty(animationNode, "direction", ""); - const SpriteDirection directionType = makeSpriteDirection(directionName); + const SpriteDirection::Type directionType = makeSpriteDirection(directionName); - if (directionType == DIRECTION_INVALID) + if (directionType == SpriteDirection::INVALID) { logger->log("Warning: Unknown direction \"%s\" used in %s", directionName.c_str(), getIdPath().c_str()); @@ -462,28 +462,29 @@ SpriteDef::~SpriteDef() mImageSets.clear(); } -SpriteDirection SpriteDef::makeSpriteDirection(const std::string &direction) +SpriteDirection::Type SpriteDef::makeSpriteDirection(const std::string + &direction) { if (direction.empty() || direction == "default") - return DIRECTION_DEFAULT; + return SpriteDirection::DEFAULT; else if (direction == "up") - return DIRECTION_UP; + return SpriteDirection::UP; else if (direction == "left") - return DIRECTION_LEFT; + return SpriteDirection::LEFT; else if (direction == "right") - return DIRECTION_RIGHT; + return SpriteDirection::RIGHT; else if (direction == "down") - return DIRECTION_DOWN; + return SpriteDirection::DOWN; else if (direction == "upleft") - return DIRECTION_UPLEFT; + return SpriteDirection::UPLEFT; else if (direction == "upright") - return DIRECTION_UPRIGHT; + return SpriteDirection::UPRIGHT; else if (direction == "downleft") - return DIRECTION_DOWNLEFT; + return SpriteDirection::DOWNLEFT; else if (direction == "downright") - return DIRECTION_DOWNRIGHT; + return SpriteDirection::DOWNRIGHT; else - return DIRECTION_INVALID; + return SpriteDirection::INVALID; } void SpriteDef::addAction(const unsigned hp, const std::string &name, diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h index d20865c68..7e31fe1da 100644 --- a/src/resources/spritedef.h +++ b/src/resources/spritedef.h @@ -25,6 +25,8 @@ #include "resources/resource.h" +#include "resources/spritedirection.h" + #include "utils/stringvector.h" #include "utils/xml.h" @@ -36,20 +38,6 @@ class Action; class Animation; class ImageSet; -enum SpriteDirection -{ - DIRECTION_DEFAULT = 0, - DIRECTION_UP = 1, - DIRECTION_DOWN = 2, - DIRECTION_LEFT = 3, - DIRECTION_RIGHT = 4, - DIRECTION_UPLEFT = 5, - DIRECTION_UPRIGHT = 6, - DIRECTION_DOWNLEFT = 7, - DIRECTION_DOWNRIGHT = 8, - DIRECTION_INVALID -}; - /** * Defines a class to load an animation. */ @@ -76,7 +64,7 @@ class SpriteDef final : public Resource /** * Converts a string into a SpriteDirection enum. */ - static SpriteDirection + static SpriteDirection::Type makeSpriteDirection(const std::string &direction) A_WARN_UNUSED; void addAction(const unsigned hp, const std::string &name, diff --git a/src/resources/spritedirection.h b/src/resources/spritedirection.h new file mode 100644 index 000000000..17fd6e980 --- /dev/null +++ b/src/resources/spritedirection.h @@ -0,0 +1,43 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef RESOURCES_SPRITEDIRECTION_H +#define RESOURCES_SPRITEDIRECTION_H + +namespace SpriteDirection +{ + enum Type + { + DEFAULT = 0, + UP = 1, + DOWN = 2, + LEFT = 3, + RIGHT = 4, + UPLEFT = 5, + UPRIGHT = 6, + DOWNLEFT = 7, + DOWNRIGHT = 8, + INVALID + }; +} + +#endif // RESOURCES_SPRITEDIRECTION_H diff --git a/src/sprite.h b/src/sprite.h index 52ac535ca..a9dde8e2b 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -84,7 +84,8 @@ class Sprite * * @returns true if the sprite changed, false otherwise */ - virtual bool setSpriteDirection(const SpriteDirection direction) = 0; + virtual bool setSpriteDirection(const SpriteDirection::Type + direction) = 0; /** * Sets the alpha value of the animated sprite |