diff --git a/res/config.json b/res/config.json index b47bbe8..a6982e5 100644 --- a/res/config.json +++ b/res/config.json @@ -51,5 +51,19 @@ "path": "res/body/{color}.png", "pixel_width": 182, "origin": [ 98, 123 ] - } + }, + "colors": [ + "#C51111", + "#132ED1", + "#117F2D", + "#ED54BA", + "#EF7D0D", + "#F5F557", + "#3F474E", + "#D6E0F0", + "#6B2FBB", + "#71491E", + "#38FEDC", + "#50EF39" + ] } diff --git a/res_hq/config.json b/res_hq/config.json index 0d87d28..b7b62d9 100644 --- a/res_hq/config.json +++ b/res_hq/config.json @@ -51,5 +51,19 @@ "path": "res/body/{color}.png", "pixel_width": 182, "origin": [ 98, 123 ] - } + }, + "colors": [ + "#C51111", + "#132ED1", + "#117F2D", + "#ED54BA", + "#EF7D0D", + "#F5F557", + "#3F474E", + "#D6E0F0", + "#6B2FBB", + "#71491E", + "#38FEDC", + "#50EF39" + ] } diff --git a/source/resources/config.cpp b/source/resources/config.cpp index 956e971..bbf6977 100644 --- a/source/resources/config.cpp +++ b/source/resources/config.cpp @@ -67,6 +67,15 @@ resources::config::config() { if (m_maps.size() != 3) { throw std::runtime_error("expected 3 maps in config"); } + + const auto color_strings = config.at("colors").get>(); + for (const auto& color_string : color_strings) { + if (color_string.size() != 7 || color_string[0] != '#') { + throw std::runtime_error("expected color in form #RRGGBB"); + } + + m_colors.emplace_back(std::stol(color_string.substr(1), nullptr, 16)); + } } const config &config::instance() { @@ -126,4 +135,13 @@ std::string config::get_body_path(int color) { return fmt::format(instance().m_body.path, fmt::arg("color", color)); } +std::optional config::try_get_color(int color_id) { + const auto& colors = instance().m_colors; + if (color_id >= colors.size()) { + return std::nullopt; + } + + return colors[color_id]; +} + } // namespace resources diff --git a/source/resources/config.hpp b/source/resources/config.hpp index afb1139..afa335c 100644 --- a/source/resources/config.hpp +++ b/source/resources/config.hpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace resources { @@ -31,6 +32,7 @@ class config { texture_config m_player; texture_config m_ghost; texture_config m_body; + std::vector m_colors; config(); @@ -53,6 +55,8 @@ class config { static std::string get_player_path(int color); static std::string get_ghost_path(int color); static std::string get_body_path(int color); + + static std::optional try_get_color(int color_id); }; } // namespace resources diff --git a/source/ui/utils.cpp b/source/ui/utils.cpp index 0c1e587..5e37271 100644 --- a/source/ui/utils.cpp +++ b/source/ui/utils.cpp @@ -1,5 +1,7 @@ #include "utils.hpp" +#include + namespace ui::utils { const char* get_map_name(int map_id) { @@ -12,21 +14,8 @@ const char* get_map_name(int map_id) { } ImColor ui::utils::convert_color(int color_id) { - switch (color_id) { - case 0: return ImColor(0xC5, 0x11, 0x11); - case 1: return ImColor(0x13, 0x2E, 0xD1); - case 2: return ImColor(0x11, 0x7F, 0x2D); - case 3: return ImColor(0xED, 0x54, 0xBA); - case 4: return ImColor(0xEF, 0x7D, 0x0D); - case 5: return ImColor(0xF5, 0xF5, 0x57); - case 6: return ImColor(0x3F, 0x47, 0x4E); - case 7: return ImColor(0xD6, 0xE0, 0xF0); - case 8: return ImColor(0x6B, 0x2F, 0xBB); - case 9: return ImColor(0x71, 0x49, 0x1E); - case 10: return ImColor(0x38, 0xFE, 0xDC); - case 11: return ImColor(0x50, 0xEF, 0x39); - default: return ImColor(); - } + const auto color = resources::config::try_get_color(color_id); + return color ? ImColor(*color) : ImColor(); } } // namespace ui::utils