FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
arbitraryJsonTypes.inl
1/*
2 * Copyright 2024 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17namespace fge
18{
19
20template<class T>
21void to_json(nlohmann::json& j, fge::Rect<T> const& p)
22{
23 j = nlohmann::json{{"x", p._x}, {"y", p._y}, {"w", p._width}, {"h", p._height}};
24}
25template<class T>
26void from_json(nlohmann::json const& j, fge::Rect<T>& p)
27{
28 j.at("x").get_to(p._x);
29 j.at("y").get_to(p._y);
30 j.at("w").get_to(p._width);
31 j.at("h").get_to(p._height);
32}
33
34template<class T>
35void to_json(nlohmann::json& j, fge::Vector2<T> const& p)
36{
37 j = nlohmann::json{{"x", p.x}, {"y", p.y}};
38}
39template<class T>
40void from_json(nlohmann::json const& j, fge::Vector2<T>& p)
41{
42 j.at("x").get_to(p.x);
43 j.at("y").get_to(p.y);
44}
45
46template<class T>
47void to_json(nlohmann::json& j, fge::Vector3<T> const& p)
48{
49 j = nlohmann::json{{"x", p.x}, {"y", p.y}, {"z", p.z}};
50}
51template<class T>
52void from_json(nlohmann::json const& j, fge::Vector3<T>& p)
53{
54 j.at("x").get_to(p.x);
55 j.at("y").get_to(p.y);
56 j.at("z").get_to(p.z);
57}
58
59inline void to_json(nlohmann::json& j, fge::Color const& p)
60{
61 j = p.toInteger();
62}
63inline void from_json(nlohmann::json const& j, fge::Color& p)
64{
65 uint32_t color{0};
66 j.get_to(color);
67 p = fge::Color{color};
68}
69
70} // namespace fge
71
72namespace glm
73{
74
75template<class T>
76void to_json(nlohmann::json& j, glm::vec<2, T> const& p)
77{
78 j = nlohmann::json{{"x", p.x}, {"y", p.y}};
79}
80template<class T>
81void from_json(nlohmann::json const& j, glm::vec<2, T>& p)
82{
83 j.at("x").get_to(p.x);
84 j.at("y").get_to(p.y);
85}
86
87template<class T>
88void to_json(nlohmann::json& j, glm::vec<3, T> const& p)
89{
90 j = nlohmann::json{{"x", p.x}, {"y", p.y}, {"z", p.z}};
91}
92template<class T>
93void from_json(nlohmann::json const& j, glm::vec<3, T>& p)
94{
95 j.at("x").get_to(p.x);
96 j.at("y").get_to(p.y);
97 j.at("z").get_to(p.z);
98}
99
100} // namespace glm
101
102namespace tiny_utf8
103{
104
105inline void to_json(nlohmann::json& j, tiny_utf8::string const& p)
106{
107 j = p.c_str();
108}
109inline void from_json(nlohmann::json const& j, tiny_utf8::string& p)
110{
111 std::string str;
112 j.get_to(str);
113 p = tiny_utf8::string{std::move(str)};
114}
115
116} // namespace tiny_utf8
Definition C_color.hpp:35
Definition C_rect.hpp:36