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
float radius() const
Get radius.
Definition Circle.cpp:88
float fragments() const
Get fragments.
Definition Circle.cpp:83
void create(const float fragments, const float radius)
Create the circle.
Definition Circle.cpp:52
void set_g(const std::uint8_t g)
Green.
Definition Colour.cpp:86
R r() const
Get red.
B b() const
Get blue.
void set_r(const std::uint8_t r)
Red.
Definition Colour.cpp:68
G g() const
Get green.
void set_b(const std::uint8_t b)
Blue.
Definition Colour.cpp:104
void set_a(const std::uint8_t a)
Alpha.
Definition Colour.cpp:122
A a() const
Get alpha.
Colour m_colour
Used by all primitives.
Definition Shape.hpp:84
Animated.cpp galaxy.
Definition Animated.cpp:16