Yet Another Game Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
spritesheet.h
Go to the documentation of this file.
1 
9 
11 #ifndef YAGE_SPRITESHEET_H
12 #define YAGE_SPRITESHEET_H
13 
18 #include "../data/texture.h"
19 #include "../util/noncopyable.h"
20 
21 #include <rapidjson/reader.h>
22 
23 #include <map>
24 #include <string>
25 
26 namespace yage
27 {
28 
29 namespace details
30 {
31 
32 struct Coordinate {
33  int x;
34  int y;
35  int width;
36  int height;
37 
38  Coordinate() = default;
39 
40  Coordinate(int x_i, int y_i, int width_i, int height_i)
41  : x(x_i), y(y_i), width(width_i), height(height_i)
42  {
43  }
44 };
45 
46 typedef std::map<std::string, details::Coordinate> SpriteMap;
47 
48 } // namespace details
49 
50 class SpriteSheet : public NonCopyable
51 {
52 public:
53  SpriteSheet() = default;
54  SpriteSheet(std::string pngFileName, std::string jsonFileName);
55 
56  void sprite(std::string spriteName) const;
57  std::string fileContent(std::string jsonFileName) const;
58 
59 private:
60  Texture texture_;
61  details::SpriteMap fileLocations_;
62 
63  details::SpriteMap parseJson(int &width, int &height,
64  std::string jsonContent) const;
65 };
66 
67 } // namespace yage
68 
69 #endif
Definition: spritesheet.h:50
Coordinate(int x_i, int y_i, int width_i, int height_i)
Definition: spritesheet.h:40
int x
Definition: spritesheet.h:33
SpriteSheet()=default
Definition: noncopyable.h:7
std::map< std::string, details::Coordinate > SpriteMap
Definition: spritesheet.h:46
int width
Definition: spritesheet.h:35
void sprite(std::string spriteName) const
int height
Definition: spritesheet.h:36
Definition: texture.h:17
Definition: spritesheet.h:32
int y
Definition: spritesheet.h:34
std::string fileContent(std::string jsonFileName) const
Definition: spritesheet.cpp:47