From fcd3680c3b15b139a6c552e05519e133989d4616 Mon Sep 17 00:00:00 2001 From: Pentalimbed Date: Mon, 14 Oct 2024 04:01:44 +0100 Subject: [PATCH] chore: serialize ImVec to array instead of object because: 1. it's less cloggy 2. it follows the same format as d3d vecs 3. serializations should be placed in Util --- src/Menu.cpp | 12 ------------ src/Util.cpp | 22 ++++++++++++++++++++++ src/Util.h | 5 +++++ 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/Menu.cpp b/src/Menu.cpp index b51db2c91..7877483a3 100644 --- a/src/Menu.cpp +++ b/src/Menu.cpp @@ -21,18 +21,6 @@ #include "Streamline.h" #include "Upscaling.h" -NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT( - ImVec2, - x, - y) - -NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT( - ImVec4, - x, - y, - z, - w) - NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT( Menu::ThemeSettings, FontScale, diff --git a/src/Util.cpp b/src/Util.cpp index 342ae8b65..f5b112afb 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -466,4 +466,26 @@ namespace nlohmann std::array temp = j; v = { temp[0], temp[1], temp[2], temp[3] }; } + + void to_json(json& j, const ImVec2& v) + { + j = json{ v.x, v.y }; + } + + void from_json(const json& j, ImVec2& v) + { + std::array temp = j; + v = { temp[0], temp[1] }; + } + + void to_json(json& j, const ImVec4& v) + { + j = json{ v.x, v.y, v.z, v.w }; + } + + void from_json(const json& j, ImVec4& v) + { + std::array temp = j; + v = { temp[0], temp[1], temp[2], temp[3] }; + } } \ No newline at end of file diff --git a/src/Util.h b/src/Util.h index dfa0e8359..79eceadd1 100644 --- a/src/Util.h +++ b/src/Util.h @@ -143,4 +143,9 @@ namespace nlohmann void from_json(const json& j, float3& v); void to_json(json& j, const float4& v); void from_json(const json& j, float4& v); + + void to_json(json& j, const ImVec2& v); + void from_json(const json& j, ImVec2& v); + void to_json(json& j, const ImVec4& v); + void from_json(const json& j, ImVec4& v); }; \ No newline at end of file