YAGE  v0.1.1
Yet Another Game Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends 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 
9 #ifndef YAGE_SPRITESHEET_H
10 #define YAGE_SPRITESHEET_H
11 
12 #include "texture.h"
13 
14 #include <rapidjson/reader.h>
15 
16 #include <map>
17 #include <string>
18 
19 namespace yage
20 {
21 
22 namespace details
23 {
24 
25 struct Coordinate {
26  int x;
27  int y;
28  int width;
29  int height;
30 
31  Coordinate() = default;
32 
33  Coordinate(int x_i, int y_i, int width_i, int height_i)
34  : x(x_i), y(y_i), width(width_i), height(height_i)
35  {
36  }
37 };
38 
39 typedef std::map<std::string, details::Coordinate> SpriteMap;
40 
41 } // namespace details
42 
44 {
45 public:
46  SpriteSheet(std::string pngFileName, std::string jsonFileName);
47 
48  void sprite(std::string spriteName) const;
49  std::string fileContent(std::string jsonFileName) const;
50 
51 private:
54 
55  details::SpriteMap parseJson(int &width, int &height, const std::string &jsonContent) const;
56 };
57 
58 } // namespace yage
59 
60 #endif
Definition: spritesheet.h:43
Coordinate(int x_i, int y_i, int width_i, int height_i)
Definition: spritesheet.h:33
SpriteSheet(std::string pngFileName, std::string jsonFileName)
Definition: spritesheet.cpp:26
int x
Definition: spritesheet.h:26
details::SpriteMap parseJson(int &width, int &height, const std::string &jsonContent) const
Definition: spritesheet.cpp:41
std::map< std::string, details::Coordinate > SpriteMap
Definition: spritesheet.h:39
Texture texture_
Definition: spritesheet.h:52
int width
Definition: spritesheet.h:28
void sprite(std::string spriteName) const
int height
Definition: spritesheet.h:29
std::string fileContent(std::string jsonFileName) const
Definition: spritesheet.cpp:31
Definition: texture.h:17
Definition: spritesheet.h:25
int y
Definition: spritesheet.h:27
details::SpriteMap fileLocations_
Definition: spritesheet.h:53