#include "compat/assert.hpp" #include #include #include #include namespace nlohmann { template requires std::is_integral_v struct adl_serializer> final { static void to_json(json& j, const Magnum::Math::Vector2& val) { char buf[64]; using type = std::conditional_t, std::intmax_t, std::uintmax_t>; constexpr auto format_string = std::is_signed_v ? "%jd x %jd" : "%ju x %ju"; snprintf(buf, sizeof(buf), format_string, (type)val[0], (type)val[1]); j = buf; } static void from_json(const json& j, Magnum::Math::Vector2& val) { std::string str = j; using type = std::conditional_t, std::intmax_t, std::uintmax_t>; constexpr auto format_string = std::is_signed_v ? "%jd x %jd%n" : "%ju x %ju%n"; type x = 0, y = 0; int n = 0; int ret = std::sscanf(str.data(), format_string, &x, &y, &n); if (ret != 2 || (std::size_t)n != str.size() || x != (t)x || y != (t)y) fm_abort("failed to parse Vector2 '%s'", str.data()); val = { (t)x, (t)y }; } }; } // namespace nlohmann