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