#include #include "palette.hpp" #include "config.hpp" #include "dbc.hpp" namespace palette { using std::string; using nlohmann::json; struct PaletteMgr { std::unordered_map palettes; }; static PaletteMgr COLOR; void init(const string &json_file) { Config config(json_file); json& colors = config.json(); for(auto [key, value_specs] : colors.items()) { const string& base_key = key; for(auto [value, rgba] : value_specs.items()) { auto color_path = base_key + ":" + value; dbc::check(!COLOR.palettes.contains(color_path), fmt::format("PALLETES already has a color path {}", color_path)); uint8_t alpha = rgba.size() == 3 ? 255 : (uint8_t)rgba[3]; sf::Color color{rgba[0], rgba[1], rgba[2], alpha}; COLOR.palettes.try_emplace(color_path, color); } } } sf::Color get(const string& key) { return COLOR.palettes.at(key); } }