NasNas
An intuitive and beginner friendly 2D game framework for C++
TiledMap.hpp
1 
6 #pragma once
7 
8 #include <string>
9 #include <vector>
10 
11 #include <SFML/System/Vector2.hpp>
12 
13 #include <NasNas/tilemapping/LayersContainer.hpp>
14 #include <NasNas/tilemapping/PropertiesContainer.hpp>
15 #include <NasNas/tilemapping/Tileset.hpp>
16 
17 namespace pugi {
18  class xml_document;
19 }
20 
21 namespace ns::tm {
22 
23  class TiledMap : public LayersContainer, public PropertiesContainer {
24  public:
25  TiledMap();
26 
27  auto loadFromFile(const std::string& file_name) -> bool;
28  auto loadFromString(const std::string& data) -> bool;
29 
30  auto getTMXFilePath() const -> const std::string&;
31 
32  auto getSize() const -> const sf::Vector2f&;
33  auto getGridSize() const -> const sf::Vector2u&;
34  auto getTileSize() const -> const sf::Vector2u&;
35 
36  auto allTilesets() const -> const std::vector<Tileset>&;
37  auto getTileTileset(unsigned int gid) const -> const Tileset&;
38 
39  void setCamera(const Camera& cam);
40 
41  void update();
42 
43  private:
44  void load(const pugi::xml_document& xml);
45 
46  std::string m_file_name;
47  std::string m_file_relative_path;
48 
49  sf::Vector2u m_gridsize;
50  sf::Vector2u m_tilesize;
51  sf::Vector2f m_size;
52 
53  std::vector<Tileset> m_tilesets;
54  std::vector<TilesetData> m_tilesets_data;
55 
56  const Camera* m_camera = nullptr;
57  };
58 
59 }