Mana
Loading...
Searching...
No Matches
spritedef.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include "resources/imageset.h"
25
26#include "utils/xml.h"
27
28#include <map>
29#include <string>
30#include <vector>
31
32class Action;
33class ImageSet;
34
36{
37 std::string sprite;
38 int variant = 0;
39};
40
42{
43 std::string image;
44 std::vector<SpriteReference> sprites;
45 std::vector<std::string> particles;
46};
47
48/*
49 * Remember those are the main action.
50 * Action subtypes, e.g.: "attack_bow" are to be passed by items.xml after
51 * an ACTION_ATTACK call.
52 * Which ability to be use to to be passed with the USE_ABILITY call.
53 * Running, walking, ... is a sub-type of moving.
54 * ...
55 * Please don't add hard-coded subtypes here!
56 */
57namespace SpriteAction
58{
59 static const std::string DEFAULT = "stand";
60 static const std::string STAND = "stand";
61 static const std::string SIT = "sit";
62 static const std::string SLEEP = "sleep";
63 static const std::string DEAD = "dead";
64 static const std::string MOVE = "walk";
65 static const std::string ATTACK = "attack";
66 static const std::string HURT = "hurt";
67 static const std::string USE_ABILITY = "ability";
68 static const std::string CAST_MAGIC = "magic";
69 static const std::string USE_ITEM = "item";
70 static const std::string INVALID;
71}
72
82
86class SpriteDef : public Resource
87{
88 public:
92 static SpriteDef *load(const std::string &file, int variant);
93
97 Action *getAction(const std::string &action) const;
98
102 static SpriteDirection
103 makeSpriteDirection(const std::string &direction);
104
105 private:
107
108 ~SpriteDef() override;
109
113 void loadSprite(XML::Node spriteNode, int variant,
114 const std::string &palettes = std::string());
115
119 void loadImageSet(XML::Node node, const std::string &palettes);
120
124 void loadAction(XML::Node node, int variant_offset);
125
129 void loadAnimation(XML::Node animationNode,
130 Action *action, ImageSet *imageSet,
131 int variant_offset);
132
136 void includeSprite(XML::Node includeNode);
137
141 void substituteActions();
142
147 void substituteAction(std::string complete, std::string with);
148
149 std::map<std::string, ResourceRef<ImageSet>> mImageSets;
150 std::map<std::string, Action *> mActions;
151};
An action consists of several animations, one for each direction.
Definition action.h:32
Stores a set of subimages originating from a single image.
Definition imageset.h:34
A generic reference counted resource object.
Definition resource.h:31
Defines a class to load an animation.
Definition spritedef.h:87
void loadAnimation(XML::Node animationNode, Action *action, ImageSet *imageSet, int variant_offset)
Loads an animation element.
void loadAction(XML::Node node, int variant_offset)
Loads an action element.
void loadSprite(XML::Node spriteNode, int variant, const std::string &palettes=std::string())
Loads a sprite element.
void substituteActions()
Complete missing actions by copying existing ones.
Definition spritedef.cpp:99
std::map< std::string, Action * > mActions
Definition spritedef.h:150
std::map< std::string, ResourceRef< ImageSet > > mImageSets
Definition spritedef.h:149
~SpriteDef() override
void includeSprite(XML::Node includeNode)
Include another sprite into this one.
void loadImageSet(XML::Node node, const std::string &palettes)
Loads an imageset element.
static SpriteDirection makeSpriteDirection(const std::string &direction)
Converts a string into a SpriteDirection enum.
void substituteAction(std::string complete, std::string with)
When there are no animations defined for the action "complete", its animations become a copy of those...
Definition spritedef.cpp:87
static SpriteDef * load(const std::string &file, int variant)
Loads a sprite definition file.
Definition spritedef.cpp:54
Action * getAction(const std::string &action) const
Returns the specified action.
Definition spritedef.cpp:41
SpriteDirection
Definition spritedef.h:74
@ DIRECTION_INVALID
Definition spritedef.h:80
@ DIRECTION_DOWN
Definition spritedef.h:77
@ DIRECTION_LEFT
Definition spritedef.h:78
@ DIRECTION_UP
Definition spritedef.h:76
@ DIRECTION_DEFAULT
Definition spritedef.h:75
@ DIRECTION_RIGHT
Definition spritedef.h:79
std::string image
Definition spritedef.h:43
std::vector< SpriteReference > sprites
Definition spritedef.h:44
std::vector< std::string > particles
Definition spritedef.h:45
std::string sprite
Definition spritedef.h:37