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