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
Transform.cpp
Go to the documentation of this file.
1
7
8#include <nlohmann/json.hpp>
9
10#include "Transform.hpp"
11
12namespace galaxy
13{
14 namespace components
15 {
17 : Serializable {}
18 {
19 }
20
21 Transform::Transform(const nlohmann::json& json)
22 : Serializable {}
23 {
24 deserialize(json);
25 }
26
28 : Serializable {}
29 {
30 }
31
33 {
34 if (this != &t)
35 {
36 this->m_tf = std::move(t.m_tf);
37 }
38
39 return *this;
40 }
41
45
46 nlohmann::json Transform::serialize()
47 {
48 nlohmann::json json = "{}"_json;
49
50 json["pos"]["x"] = m_tf.get_pos().x;
51 json["pos"]["y"] = m_tf.get_pos().y;
52 json["rotation"] = m_tf.get_rotation();
53 json["scale"]["x"] = m_tf.get_scale().x;
54 json["scale"]["y"] = m_tf.get_scale().y;
55 json["origin"]["x"] = m_tf.get_origin().x;
56 json["origin"]["y"] = m_tf.get_origin().y;
57
58 return json;
59 }
60
61 void Transform::deserialize(const nlohmann::json& json)
62 {
63 const auto& pos = json.at("pos");
64 m_tf.set_pos(pos.at("x"), pos.at("y"));
65
66 m_tf.set_rotation(json.at("rotation"));
67
68 const auto& scale = json.at("scale");
69 m_tf.set_scale_horizontal(scale.at("x"));
70 m_tf.set_scale_vertical(scale.at("y"));
71
72 const auto& origin = json.at("origin");
73 m_tf.set_origin(origin.at("x"), origin.at("y"));
74 }
75 } // namespace components
76} // namespace galaxy
Defines the 2D transformation of an entity.
Definition Transform.hpp:22
void deserialize(const nlohmann::json &json) override
Deserializes from object.
Definition Transform.cpp:61
graphics::Transform m_tf
Transformation object.
Definition Transform.hpp:81
virtual ~Transform()
Destructor.
Definition Transform.cpp:42
nlohmann::json serialize() override
Serializes object.
Definition Transform.cpp:46
Transform & operator=(Transform &&)
Move assignment operator.
Definition Transform.cpp:32
Timer.hpp galaxy.
Definition Async.hpp:17