galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
Polyline.cpp
Go to the documentation of this file.
1
7
8#include <nlohmann/json.hpp>
9
10#include "Polyline.hpp"
11
12namespace galaxy
13{
14 namespace components
15 {
17 : Serializable {}
18 {
19 }
20
21 Polyline::Polyline(const nlohmann::json& json)
22 : Serializable {}
23 {
24 deserialize(json);
25 }
26
28 : Serializable {}
29 {
30 this->m_shape = std::move(p.m_shape);
31 }
32
34 {
35 if (this != &p)
36 {
37 this->m_shape = std::move(p.m_shape);
38 }
39
40 return *this;
41 }
42
46
47 nlohmann::json Polyline::serialize()
48 {
49 nlohmann::json json = "{}"_json;
50
51 json["colour"]["r"] = m_shape.m_colour.r<std::uint8_t>();
52 json["colour"]["g"] = m_shape.m_colour.g<std::uint8_t>();
53 json["colour"]["b"] = m_shape.m_colour.b<std::uint8_t>();
54 json["colour"]["a"] = m_shape.m_colour.a<std::uint8_t>();
55
56 json["points"] = nlohmann::json::array();
57 for (const auto& point : m_shape.points())
58 {
59 auto obj = nlohmann::json::object();
60 obj["x"] = point.x;
61 obj["y"] = point.y;
62
63 json["points"].push_back(obj);
64 }
65
66 return json;
67 }
68
69 void Polyline::deserialize(const nlohmann::json& json)
70 {
71 const auto& col = json.at("colour");
72 m_shape.m_colour.set_r(col.at("r").get<std::uint8_t>());
73 m_shape.m_colour.set_g(col.at("g").get<std::uint8_t>());
74 m_shape.m_colour.set_b(col.at("b").get<std::uint8_t>());
75 m_shape.m_colour.set_a(col.at("a").get<std::uint8_t>());
76
77 meta::vector<glm::vec2> points;
78
79 const auto& pa = json.at("points");
80 for (const auto& point : pa)
81 {
82 points.emplace_back(point.at("x"), point.at("y"));
83 }
84
85 m_shape.create(points);
86 }
87 } // namespace components
88} // namespace galaxy
nlohmann::json serialize() override
Serializes object.
Definition Polyline.cpp:47
virtual ~Polyline()
Destructor.
Definition Polyline.cpp:43
void deserialize(const nlohmann::json &json) override
Deserializes from object.
Definition Polyline.cpp:69
Polyline & operator=(Polyline &&)
Move assignment operator.
Definition Polyline.cpp:33
graphics::Polyline m_shape
Shape.
Definition Polyline.hpp:81
Timer.hpp galaxy.
Definition Async.hpp:17