1 | // SuperTux |
2 | // Copyright (C) 2006 Matthias Braun <matze@braunis.de> |
3 | // |
4 | // This program is free software: you can redistribute it and/or modify |
5 | // it under the terms of the GNU General Public License as published by |
6 | // the Free Software Foundation, either version 3 of the License, or |
7 | // (at your option) any later version. |
8 | // |
9 | // This program is distributed in the hope that it will be useful, |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | // GNU General Public License for more details. |
13 | // |
14 | // You should have received a copy of the GNU General Public License |
15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | |
17 | #ifndef HEADER_SUPERTUX_SPRITE_SPRITE_DATA_HPP |
18 | #define |
19 | |
20 | #include <map> |
21 | #include <string> |
22 | #include <vector> |
23 | |
24 | #include "video/surface_ptr.hpp" |
25 | |
26 | class ReaderMapping; |
27 | |
28 | class SpriteData final |
29 | { |
30 | public: |
31 | /** cur has to be a pointer to data in the form of ((hitbox 5 10 0 0) ...) */ |
32 | SpriteData(const ReaderMapping& cur); |
33 | |
34 | const std::string& get_name() const |
35 | { |
36 | return name; |
37 | } |
38 | |
39 | private: |
40 | friend class Sprite; |
41 | |
42 | struct Action |
43 | { |
44 | Action(); |
45 | |
46 | std::string name; |
47 | |
48 | /** Position correction */ |
49 | float x_offset; |
50 | float y_offset; |
51 | |
52 | /** Hitbox width */ |
53 | float hitbox_w; |
54 | |
55 | /** Hitbox height */ |
56 | float hitbox_h; |
57 | |
58 | /** Frames per second */ |
59 | float fps; |
60 | |
61 | /** Loops (-1 = looping endlessly) */ |
62 | int loops; |
63 | |
64 | /** Flag that gets set to true if the action |
65 | has custom loops defined */ |
66 | bool has_custom_loops; |
67 | |
68 | std::vector<SurfacePtr> surfaces; |
69 | }; |
70 | |
71 | typedef std::map <std::string, std::unique_ptr<Action> > Actions; |
72 | |
73 | void parse_action(const ReaderMapping& mapping); |
74 | /** Get an action */ |
75 | const Action* get_action(const std::string& act) const; |
76 | |
77 | Actions actions; |
78 | std::string name; |
79 | }; |
80 | |
81 | #endif |
82 | |
83 | /* EOF */ |
84 | |