ManaPlus
spritedef.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef RESOURCES_SPRITE_SPRITEDEF_H
25 #define RESOURCES_SPRITE_SPRITEDEF_H
26 
28 
29 #include "utils/xml.h"
30 
31 #include <map>
32 #include <set>
33 
34 class Action;
35 class Animation;
36 class ImageSet;
37 
41 class SpriteDef final : public Resource
42 {
43  public:
45 
46 
49  static SpriteDef *load(const std::string &file,
50  const int variant,
51  const bool prot) A_WARN_UNUSED;
52 
56  const Action *getAction(const std::string &action,
57  const unsigned num) const A_WARN_UNUSED;
58 
59  unsigned findNumber(const unsigned num) const A_WARN_UNUSED;
60 
65  makeSpriteDirection(const std::string &direction) A_WARN_UNUSED;
66 
67  void addAction(const unsigned hp, const std::string &name,
68  Action *const action);
69 
70  int calcMemoryLocal() const override final;
71 
72  int calcMemoryChilds(const int level) const override final;
73 
74  bool addSequence(const int start,
75  const int end,
76  const int delay,
77  const int offsetX,
78  const int offsetY,
79  const int variant_offset,
80  int repeat,
81  const int rand,
82  const ImageSet *const imageSet,
83  Animation *const animation) const;
84 
85  private:
90  Resource(),
91  mImageSets(),
92  mActions(),
94  { }
95 
100 
104  void loadSprite(XmlNodeConstPtr spriteNode,
105  const int variant,
106  const std::string &palettes);
107 
111  void loadImageSet(XmlNodeConstPtr node,
112  const std::string &palettes);
113 
117  void loadAction(XmlNodeConstPtr node,
118  const int variant_offset);
119 
123  void loadAnimation(XmlNodeConstPtr animationNode,
124  Action *const action,
125  const ImageSet *const imageSet,
126  const int variant_offset) const;
127 
131  void includeSprite(XmlNodeConstPtr includeNode,
132  const int variant);
133 
134  const ImageSet *getImageSet(const std::string &imageSetName) const;
135 
139  void substituteActions();
140 
144  void fixDeadAction();
145 
150  void substituteAction(const std::string &restrict complete,
151  const std::string &restrict with);
152 
153  typedef std::map<std::string, ImageSet*> ImageSets;
154  typedef ImageSets::iterator ImageSetIterator;
155  typedef ImageSets::const_iterator ImageSetCIterator;
156  typedef std::map<std::string, Action*> ActionMap;
157  typedef std::map<unsigned, ActionMap*> Actions;
158  typedef Actions::const_iterator ActionsConstIter;
159  typedef Actions::iterator ActionsIter;
160  typedef Actions::const_iterator ActionsCIter;
161 
164  std::set<std::string> mProcessedFiles;
165 };
166 
167 #endif // RESOURCES_SPRITE_SPRITEDEF_H
Definition: action.h:41
void loadSprite(const xmlNodePtr spriteNode, const int variant, const std::string &palettes)
Definition: spritedef.cpp:205
const Action * getAction(const std::string &action, const unsigned num) const
Definition: spritedef.cpp:52
Actions::const_iterator ActionsCIter
Definition: spritedef.h:160
static SpriteDirection::Type makeSpriteDirection(const std::string &direction)
Definition: spritedef.cpp:551
void includeSprite(const xmlNodePtr includeNode, const int variant)
Definition: spritedef.cpp:487
void loadImageSet(const xmlNodePtr node, const std::string &palettes)
Definition: spritedef.cpp:238
std::map< std::string, ImageSet * > ImageSets
Definition: spritedef.h:153
std::set< std::string > mProcessedFiles
Definition: spritedef.h:164
const ImageSet * getImageSet(const std::string &imageSetName) const
Definition: spritedef.cpp:269
ImageSets::const_iterator ImageSetCIterator
Definition: spritedef.h:155
void fixDeadAction()
Definition: spritedef.cpp:136
void substituteActions()
Definition: spritedef.cpp:172
int calcMemoryLocal() const
Definition: spritedef.cpp:660
std::map< std::string, Action * > ActionMap
Definition: spritedef.h:156
unsigned findNumber(const unsigned num) const
Definition: spritedef.cpp:76
SpriteDef()
Definition: spritedef.h:89
ImageSets mImageSets
Definition: spritedef.h:162
void addAction(const unsigned hp, const std::string &name, Action *const action)
Definition: spritedef.cpp:576
int calcMemoryChilds(const int level) const
Definition: spritedef.cpp:674
void loadAnimation(const xmlNodePtr animationNode, Action *const action, const ImageSet *const imageSet, const int variant_offset) const
Definition: spritedef.cpp:327
static SpriteDef * load(const std::string &file, const int variant, const bool prot)
Definition: spritedef.cpp:90
Actions mActions
Definition: spritedef.h:163
bool addSequence(const int start, const int end, const int delay, const int offsetX, const int offsetY, const int variant_offset, int repeat, const int rand, const ImageSet *const imageSet, Animation *const animation) const
Definition: spritedef.cpp:586
Actions::iterator ActionsIter
Definition: spritedef.h:159
Actions::const_iterator ActionsConstIter
Definition: spritedef.h:158
void loadAction(const xmlNodePtr node, const int variant_offset)
Definition: spritedef.cpp:283
ImageSets::iterator ImageSetIterator
Definition: spritedef.h:154
void substituteAction(const std::string &complete, const std::string &with)
Definition: spritedef.cpp:155
#define restrict
Definition: localconsts.h:165
#define override
Definition: localconsts.h:47
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53