You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
974 B
41 lines
974 B
2 months ago
|
#include <fmt/core.h>
|
||
|
#include "palette.hpp"
|
||
|
#include "config.hpp"
|
||
|
#include "dbc.hpp"
|
||
|
|
||
|
namespace palette {
|
||
|
using std::string;
|
||
|
using nlohmann::json;
|
||
|
|
||
|
struct PaletteMgr {
|
||
|
std::unordered_map<string, sf::Color> 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);
|
||
|
}
|
||
|
}
|