supertux
sprite_data.hpp
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 HEADER_SUPERTUX_SPRITE_SPRITE_DATA_HPP
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  friend class Sprite;
31 
32 public:
37  SpriteData(const ReaderMapping& mapping);
39  SpriteData(const std::string& image);
41  SpriteData();
42 
43  const std::string& get_name() const
44  {
45  return name;
46  }
47 
48 private:
49  struct Action
50  {
51  Action();
52 
53  std::string name;
54 
56  float x_offset;
57  float y_offset;
58 
60  float hitbox_w;
61 
63  float hitbox_h;
64 
66  bool hitbox_unisolid;
67 
69  float fps;
70 
72  int loops;
73 
75  int loop_frame;
76 
79  bool has_custom_loops;
80 
85  std::string family_name;
86 
87  std::vector<SurfacePtr> surfaces;
88  };
89 
90  typedef std::map<std::string, std::unique_ptr<Action> > Actions;
91 
92  static std::unique_ptr<Action> create_action_from_surface(SurfacePtr surface);
93 
94  void parse_action(const ReaderMapping& mapping);
96  const Action* get_action(const std::string& act) const;
97 
98 private:
99  Actions actions;
100  std::string name;
101 };
102 
103 #endif
104 
105 /* EOF */
Definition: sprite_data.hpp:28
Definition: sprite.hpp:26
const std::string & get_name() const
Get sprite&#39;s name.
Definition: sprite.hpp:89
Definition: reader_mapping.hpp:32
SpriteData()
Dummy texture sprite.
Definition: sprite_data.cpp:83