GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/sprite/spritedef.h Lines: 3 3 100.0 %
Date: 2017-11-29 Branches: 0 0 0.0 %

Line Branch Exec Source
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-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#ifndef RESOURCES_SPRITE_SPRITEDEF_H
24
#define RESOURCES_SPRITE_SPRITEDEF_H
25
26
#include "enums/resources/spritedirection.h"
27
28
#include "utils/xml.h"
29
30
#include <map>
31
#include <set>
32
33
class Action;
34
class Animation;
35
class ImageSet;
36
37
/**
38
 * Defines a class to load an animation.
39
 */
40
class SpriteDef final : public Resource
41
{
42
    public:
43
        A_DELETE_COPY(SpriteDef)
44
45
        /**
46
         * Loads a sprite definition file.
47
         */
48
        static SpriteDef *load(const std::string &file,
49
                               const int variant,
50
                               const bool prot) A_WARN_UNUSED;
51
52
        /**
53
         * Returns the specified action.
54
         */
55
        const Action *getAction(const std::string &action,
56
                                const unsigned num) const A_WARN_UNUSED;
57
58
        unsigned findNumber(const unsigned num) const A_WARN_UNUSED;
59
60
        /**
61
         * Converts a string into a SpriteDirection enum.
62
         */
63
        static SpriteDirection::Type
64
            makeSpriteDirection(const std::string &direction) A_WARN_UNUSED;
65
66
        void addAction(const unsigned hp, const std::string &name,
67
                       Action *const action);
68
69
        int calcMemoryLocal() const override final;
70
71
        int calcMemoryChilds(const int level) const override final;
72
73
        bool addSequence(const int start,
74
                         const int end,
75
                         const int delay,
76
                         const int offsetX,
77
                         const int offsetY,
78
                         const int variant_offset,
79
                         int repeat,
80
                         const int rand,
81
                         const ImageSet *const imageSet,
82
                         Animation *const animation) const;
83
84
    private:
85
        /**
86
         * Constructor.
87
         */
88
2310
        SpriteDef() :
89
            Resource(),
90
            mImageSets(),
91
            mActions(),
92
11550
            mProcessedFiles()
93
2310
        { }
94
95
        /**
96
         * Destructor.
97
         */
98
        ~SpriteDef();
99
100
        /**
101
         * Loads a sprite element.
102
         */
103
        void loadSprite(XmlNodeConstPtr spriteNode,
104
                        const int variant,
105
                        const std::string &palettes = "");
106
107
        /**
108
         * Loads an imageset element.
109
         */
110
        void loadImageSet(XmlNodeConstPtr node,
111
                          const std::string &palettes);
112
113
        /**
114
         * Loads an action element.
115
         */
116
        void loadAction(XmlNodeConstPtr node,
117
                        const int variant_offset);
118
119
        /**
120
         * Loads an animation element.
121
         */
122
        void loadAnimation(XmlNodeConstPtr animationNode,
123
                           Action *const action,
124
                           const ImageSet *const imageSet,
125
                           const int variant_offset) const;
126
127
        /**
128
         * Include another sprite into this one.
129
         */
130
        void includeSprite(XmlNodeConstPtr includeNode,
131
                           const int variant);
132
133
        const ImageSet *getImageSet(const std::string &imageSetName) const;
134
135
        /**
136
         * Complete missing actions by copying existing ones.
137
         */
138
        void substituteActions();
139
140
        /**
141
         * Fix bad timeout in last dead action frame
142
         */
143
        void fixDeadAction();
144
145
        /**
146
         * When there are no animations defined for the action "complete", its
147
         * animations become a copy of those of the action "with".
148
         */
149
        void substituteAction(const std::string &restrict complete,
150
                              const std::string &restrict with);
151
152
        typedef std::map<std::string, ImageSet*> ImageSets;
153
        typedef ImageSets::iterator ImageSetIterator;
154
        typedef ImageSets::const_iterator ImageSetCIterator;
155
        typedef std::map<std::string, Action*> ActionMap;
156
        typedef std::map<unsigned, ActionMap*> Actions;
157
        typedef Actions::const_iterator ActionsConstIter;
158
        typedef Actions::iterator ActionsIter;
159
        typedef Actions::const_iterator ActionsCIter;
160
161
        ImageSets mImageSets;
162
        Actions mActions;
163
        std::set<std::string> mProcessedFiles;
164
};
165
166
#endif  // RESOURCES_SPRITE_SPRITEDEF_H