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 /src/resources | |
parent | fba4289e53447a09dcf82211e2dab3563e2581f1 (diff) | |
download | plus-ad3ee95f90bfd368a511407c13718b900e44be0f.tar.gz plus-ad3ee95f90bfd368a511407c13718b900e44be0f.tar.bz2 plus-ad3ee95f90bfd368a511407c13718b900e44be0f.tar.xz plus-ad3ee95f90bfd368a511407c13718b900e44be0f.zip |
Move spritedirection into separate file.
Diffstat (limited to 'src/resources')
-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 |
7 files changed, 110 insertions, 77 deletions
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 |