NasNas
An intuitive and beginner friendly 2D game framework for C++
ObjectLayer.hpp
1 
5 #pragma once
6 
7 #include <string>
8 #include <vector>
9 #include <unordered_map>
10 
11 #include <NasNas/tilemapping/Layer.hpp>
12 #include <NasNas/tilemapping/Object.hpp>
13 
14 namespace ns::tm {
15 
16  class ObjectLayer : public Layer {
17  public:
18  ObjectLayer(const pugi::xml_node& xml_node, TiledMap* tiledmap);
19 
20  auto getObjectsWithType(const std::string& type) const -> const std::vector<std::reference_wrapper<Object>>&;
21  auto getObjectsWithName(const std::string& name) const -> const std::vector<std::reference_wrapper<Object>>&;
22 
23  auto allPoints() const -> const std::vector<PointObject>&;
24  auto allRectangles() const -> const std::vector<RectangleObject>&;
25  auto allEllipses() const -> const std::vector<EllipseObject>&;
26  auto allPolylines() const -> const std::vector<PolylineObject>&;
27  auto allPolygons() const -> const std::vector<PolygonObject>&;
28 
29  auto getPoint(unsigned int id) const -> const PointObject&;
30  auto getRectangle(unsigned int id) const -> const RectangleObject&;
31  auto getEllipse(unsigned int id) const -> const EllipseObject&;
32  auto getPolyline(unsigned int id) const -> const PolylineObject&;
33  auto getPolygon(unsigned int id) const -> const PolygonObject&;
34 
35  private:
36  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
37 
38  sf::Color m_color = sf::Color(180, 180, 180);
39 
40  std::vector<PointObject> m_points;
41  std::vector<RectangleObject> m_rectangles;
42  std::vector<EllipseObject> m_ellipses;
43  std::vector<PolylineObject> m_polylines;
44  std::vector<PolygonObject> m_polygons;
45  std::vector<TileObject> m_tiles;
46 
47  std::vector<std::reference_wrapper<Object>> m_objects;
48  std::unordered_map<std::string, std::vector<std::reference_wrapper<Object>>> m_objects_by_type;
49  std::unordered_map<std::string, std::vector<std::reference_wrapper<Object>>> m_objects_by_name;
50  std::vector<std::reference_wrapper<Object>> m_empty_object_vector;
51  };
52 
53 }