NasNas
An intuitive and beginner friendly 2D game framework for C++
LayersContainer.hpp
1 // Created by Modar Nasser on 01/07/2021.
2 
3 #pragma once
4 
5 #include <memory>
6 #include <string>
7 #include <vector>
8 #include <unordered_map>
9 
10 namespace pugi {
11  class xml_node;
12 }
13 namespace ns {
14  class Camera;
15 }
16 
17 namespace ns::tm {
18  class Layer;
19  class TileLayer;
20  class ObjectLayer;
21  class ImageLayer;
22  class GroupLayer;
23  class TiledMap;
24 
26  std::unordered_map<std::string, std::unique_ptr<TileLayer>> m_tilelayers;
27  std::unordered_map<std::string, std::unique_ptr<ObjectLayer>> m_objectlayers;
28  std::unordered_map<std::string, std::unique_ptr<ImageLayer>> m_imagelayers;
29  std::unordered_map<std::string, std::unique_ptr<GroupLayer>> m_grouplayers;
30  std::vector<Layer*> m_layers;
31 
32  public:
33  LayersContainer() = default;
34  virtual ~LayersContainer() = default;
35 
36  auto hasLayer(const std::string& name) const -> bool;
37  auto getTileLayer(const std::string& name) const -> TileLayer&;
38  auto getObjectLayer(const std::string& name) const -> ObjectLayer&;
39  auto getImageLayer(const std::string& name) const -> ImageLayer&;
40  auto getGroupLayer(const std::string& name) const -> GroupLayer&;
41 
42  void update(const Camera* cam);
43 
44  protected:
45  void parseLayers(const pugi::xml_node& xml_node, TiledMap* tiledmap);
46 
47  auto addTileLayer(const pugi::xml_node& xml_node, TiledMap* tiledmap) -> Layer*;
48  auto addObjectLayer(const pugi::xml_node& xml_node, TiledMap* tiledmap) -> Layer*;
49  auto addImageLayer(const pugi::xml_node& xml_node, TiledMap* tiledmap) -> Layer*;
50  auto addGroupLayer(const pugi::xml_node& xml_node, TiledMap* tiledmap) -> Layer*;
51 
52  auto allTileLayers() const -> const decltype(m_tilelayers)&;
53  auto allObjectLayers() const -> const decltype(m_objectlayers)&;
54  auto allImageLayers() const -> const decltype(m_imagelayers)&;
55  auto allGroupLayers() const -> const decltype(m_grouplayers)&;
56  auto allLayers() const -> const decltype(m_layers)&;
57  };
58 }