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
Circle.cpp
Go to the documentation of this file.
1
7
8#include <nlohmann/json.hpp>
9
10#include "Circle.hpp"
11
12namespace galaxy
13{
14 namespace components
15 {
17 : Serializable {}
18 {
19 }
20
21 Circle::Circle(const nlohmann::json& json)
22 : Serializable {}
23 {
24 deserialize(json);
25 }
26
28 : Serializable {}
29 {
30 this->m_shape = std::move(c.m_shape);
31 }
32
34 {
35 if (this != &c)
36 {
37 this->m_shape = std::move(c.m_shape);
38 }
39
40 return *this;
41 }
42
44 {
45 }
46
47 nlohmann::json Circle::serialize()
48 {
49 nlohmann::json json = "{}"_json;
50
51 json["fragments"] = m_shape.fragments();
52 json["radius"] = m_shape.radius();
53 json["colour"]["r"] = m_shape.m_colour.r<std::uint8_t>();
54 json["colour"]["g"] = m_shape.m_colour.g<std::uint8_t>();
55 json["colour"]["b"] = m_shape.m_colour.b<std::uint8_t>();
56 json["colour"]["a"] = m_shape.m_colour.a<std::uint8_t>();
57
58 return json;
59 }
60
61 void Circle::deserialize(const nlohmann::json& json)
62 {
63 const auto& col = json.at("colour");
64 m_shape.m_colour.set_r(col.at("r").get<std::uint8_t>());
65 m_shape.m_colour.set_g(col.at("g").get<std::uint8_t>());
66 m_shape.m_colour.set_b(col.at("b").get<std::uint8_t>());
67 m_shape.m_colour.set_a(col.at("a").get<std::uint8_t>());
68
69 m_shape.create(json.at("fragments"), json.at("radius"));
70 }
71 } // namespace components
72} // namespace galaxy
graphics::Circle m_shape
Shape.
Definition Circle.hpp:81
Circle & operator=(Circle &&)
Move assignment operator.
Definition Circle.cpp:33
virtual ~Circle()
Destructor.
Definition Circle.cpp:43
nlohmann::json serialize() override
Serializes object.
Definition Circle.cpp:47
void deserialize(const nlohmann::json &json) override
Deserializes from object.
Definition Circle.cpp:61
Timer.hpp galaxy.
Definition Async.hpp:17