#pragma once #include "Config.h" #include "Utility/Yaml.hpp" #define enum_def(x, y) \ { \ x::y, #y \ } namespace YAML { using namespace openloco::config; template using convert_pair_vector = std::vector>; template struct convert_enum_base { static Node encode(const T& rhs) { for (const auto& e : convert::getEntries()) { if (rhs == e.first) { return Node(e.second); } } return Node(); } static bool decode(const Node& node, T& rhs) { if (node.IsScalar()) { auto sz = node.Scalar(); for (const auto& e : convert::getEntries()) { if (e.second == sz) { rhs = e.first; return true; } } } return false; } }; // resolution_t template<> struct convert { static Node encode(const resolution_t& rhs) { Node node; node["width"] = rhs.width; node["height"] = rhs.height; return node; } static bool decode(const Node& node, resolution_t& rhs) { if (node.IsMap()) { rhs.width = node["width"].as(); rhs.height = node["height"].as(); return true; } return false; } }; // screen_mode const convert_pair_vector screen_mode_entries = { enum_def(screen_mode, window), enum_def(screen_mode, fullscreen), enum_def(screen_mode, fullscreen_borderless), }; template<> struct convert : convert_enum_base { static const convert_pair_vector& getEntries() { return screen_mode_entries; } }; } #undef enum_def