YAGE  v0.3.1
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 /* ----------------------------------------------------------------------------
2  * spritesheet.h
3  *
4  * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com>
5  * MIT License, see LICENSE file for more details.
6  * ----------------------------------------------------------------------------
7  */
8 
12 #ifndef YAGE_SPRITESHEET_H
13 #define YAGE_SPRITESHEET_H
14 
15 #include "texture.h"
16 
17 #include <rapidjson/reader.h>
18 
19 #include <map>
20 #include <string>
21 
22 namespace yage
23 {
24 
25 namespace details
26 {
27 
28 struct Coordinate {
29  int x;
30  int y;
31  int width;
32  int height;
33 
34  Coordinate() = default;
35 
36  Coordinate(int x_i, int y_i, int width_i, int height_i)
37  : x(x_i), y(y_i), width(width_i), height(height_i)
38  {
39  }
40 };
41 
42 typedef std::map<std::string, details::Coordinate> SpriteMap;
43 
44 } // namespace details
45 
47 {
48 public:
49  SpriteSheet(std::string pngFileName, std::string jsonFileName);
50 
51  void sprite(std::string spriteName) const;
52  std::string fileContent(std::string jsonFileName) const;
53 
54 private:
57 
58  details::SpriteMap parseJson(int &width, int &height,
59  std::string jsonContent) const;
60 };
61 
62 } // namespace yage
63 
64 #endif
Definition: spritesheet.h:46
Coordinate(int x_i, int y_i, int width_i, int height_i)
Definition: spritesheet.h:36
SpriteSheet(std::string pngFileName, std::string jsonFileName)
Definition: spritesheet.cpp:29
int x
Definition: spritesheet.h:29
std::map< std::string, details::Coordinate > SpriteMap
Definition: spritesheet.h:42
Texture texture_
Definition: spritesheet.h:55
int width
Definition: spritesheet.h:31
void sprite(std::string spriteName) const
int height
Definition: spritesheet.h:32
std::string fileContent(std::string jsonFileName) const
Definition: spritesheet.cpp:42
Definition: texture.h:17
Definition: spritesheet.h:28
int y
Definition: spritesheet.h:30
details::SpriteMap parseJson(int &width, int &height, std::string jsonContent) const
Definition: spritesheet.cpp:52
details::SpriteMap fileLocations_
Definition: spritesheet.h:56