blob: eed37708a3905b59b0108e69049a2d769029d060 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#pragma once
#include <Magnum/Magnum.h>
#include <Magnum/Math/Vector.h>
#include <Magnum/Math/Vector2.h>
#include <Magnum/Math/Vector3.h>
#include <Magnum/Math/Vector4.h>
#include <Magnum/Math/Color.h>
#include <nlohmann/json.hpp>
namespace nlohmann {
template<std::size_t N, typename T>
struct adl_serializer<Magnum::Math::Vector<N, T>> {
static void to_json(json& j, const Magnum::Math::Vector<N, T>& val)
{
std::array<T, N> array{};
for (std::size_t i = 0; i < N; i++)
array[i] = val[i];
j = array;
}
static void from_json(const json& j, Magnum::Math::Vector<N, T>& val)
{
std::array<T, N> array = j;
for (std::size_t i = 0; i < N; i++)
val[i] = array[i];
}
};
template<typename T> struct adl_serializer<Magnum::Math::Vector2<T>> : adl_serializer<Magnum::Math::Vector<2, T>> {};
template<typename T> struct adl_serializer<Magnum::Math::Vector3<T>> : adl_serializer<Magnum::Math::Vector<3, T>> {};
template<typename T> struct adl_serializer<Magnum::Math::Vector4<T>> : adl_serializer<Magnum::Math::Vector<4, T>> {};
template<typename T> struct adl_serializer<Magnum::Math::Color3<T>> : adl_serializer<Magnum::Math::Vector<3, T>> {};
template<typename T> struct adl_serializer<Magnum::Math::Color4<T>> : adl_serializer<Magnum::Math::Vector<4, T>> {};
} // namespace nlohmann
|