GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/sprite/spritedef.h Lines: 3 3 100.0 %
Date: 2021-03-17 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-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
27
#include "enums/resources/spritedirection.h"
28
29
#include "utils/xml.h"
30
31
#include <map>
32
#include <set>
33
34
class Action;
35
class Animation;
36
class ImageSet;
37
38
/**
39
 * Defines a class to load an animation.
40
 */
41
class SpriteDef final : public Resource
42
{
43
    public:
44
        A_DELETE_COPY(SpriteDef)
45
46
        /**
47
         * Loads a sprite definition file.
48
         */
49
        static SpriteDef *load(const std::string &file,
50
                               const int variant,
51
                               const bool prot) A_WARN_UNUSED;
52
53
        /**
54
         * Returns the specified action.
55
         */
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
61
        /**
62
         * Converts a string into a SpriteDirection enum.
63
         */
64
        static SpriteDirection::Type
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:
86
        /**
87
         * Constructor.
88
         */
89
1293
        SpriteDef() :
90
            Resource(),
91
            mImageSets(),
92
            mActions(),
93
6465
            mProcessedFiles()
94
1293
        { }
95
96
        /**
97
         * Destructor.
98
         */
99
        ~SpriteDef() override final;
100
101
        /**
102
         * Loads a sprite element.
103
         */
104
        void loadSprite(XmlNodeConstPtr spriteNode,
105
                        const int variant,
106
                        const std::string &palettes);
107
108
        /**
109
         * Loads an imageset element.
110
         */
111
        void loadImageSet(XmlNodeConstPtr node,
112
                          const std::string &palettes);
113
114
        /**
115
         * Loads an action element.
116
         */
117
        void loadAction(XmlNodeConstPtr node,
118
                        const int variant_offset);
119
120
        /**
121
         * Loads an animation element.
122
         */
123
        void loadAnimation(XmlNodeConstPtr animationNode,
124
                           Action *const action,
125
                           const ImageSet *const imageSet,
126
                           const int variant_offset) const;
127
128
        /**
129
         * Include another sprite into this one.
130
         */
131
        void includeSprite(XmlNodeConstPtr includeNode,
132
                           const int variant);
133
134
        const ImageSet *getImageSet(const std::string &imageSetName) const;
135
136
        /**
137
         * Complete missing actions by copying existing ones.
138
         */
139
        void substituteActions();
140
141
        /**
142
         * Fix bad timeout in last dead action frame
143
         */
144
        void fixDeadAction();
145
146
        /**
147
         * When there are no animations defined for the action "complete", its
148
         * animations become a copy of those of the action "with".
149
         */
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
162
        ImageSets mImageSets;
163
        Actions mActions;
164
        std::set<std::string> mProcessedFiles;
165
};
166
167
#endif  // RESOURCES_SPRITE_SPRITEDEF_H