Colors are now being loaded from assets/palette.json

This commit is contained in:
Zed A. Shaw 2025-07-17 10:50:09 -04:00
parent 48a7f72411
commit f4fa50a413
13 changed files with 113 additions and 52 deletions

View file

@ -9,11 +9,13 @@ namespace palette {
struct PaletteMgr {
std::unordered_map<string, sf::Color> palettes;
std::string config;
};
static PaletteMgr COLOR;
void init(const string &json_file) {
COLOR.config = json_file;
Config config(json_file);
json& colors = config.json();
@ -23,7 +25,7 @@ namespace palette {
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));
fmt::format("PALLETES config {} already has a color path {}", COLOR.config, color_path));
uint8_t alpha = rgba.size() == 3 ? 255 : (uint8_t)rgba[3];
@ -35,6 +37,17 @@ namespace palette {
}
sf::Color get(const string& key) {
dbc::check(COLOR.palettes.contains(key),
fmt::format("COLOR {} is missing from {}", key, COLOR.config));
return COLOR.palettes.at(key);
}
sf::Color get(const string& key, const string& value) {
std::string color{key + ":" + value};
dbc::check(COLOR.palettes.contains(color),
fmt::format("COLOR {} is missing from {}", color, COLOR.config));
return COLOR.palettes.at(color);
}
}