Fix a bug in palette that kept it from being idempotent.

This commit is contained in:
Zed A. Shaw 2025-12-12 11:41:57 -05:00
parent 986b2612d4
commit 37b007d79c
5 changed files with 21 additions and 10 deletions

View file

@ -16,6 +16,10 @@ namespace palette {
static PaletteMgr COLOR;
bool initialized() {
return COLOR.initialized;
}
void init(const string &json_file) {
if(!COLOR.initialized) {
COLOR.initialized = true;
@ -41,18 +45,18 @@ namespace palette {
}
}
}
}
for(auto [color_path, ref] : COLOR.pending_refs) {
dbc::check(COLOR.palettes.contains(ref),
fmt::format("In {} you have {} referring to {} but {} doesn't exist.",
COLOR.config, color_path, ref, ref));
dbc::check(!COLOR.palettes.contains(color_path),
fmt::format("Color {} with ref {} is duplicated.", color_path, ref));
for(auto [color_path, ref] : COLOR.pending_refs) {
dbc::check(COLOR.palettes.contains(ref),
fmt::format("In {} you have {} referring to {} but {} doesn't exist.",
COLOR.config, color_path, ref, ref));
dbc::check(!COLOR.palettes.contains(color_path),
fmt::format("Color {} with ref {} is duplicated.", color_path, ref));
auto color = COLOR.palettes.at(ref);
auto color = COLOR.palettes.at(ref);
COLOR.palettes.try_emplace(color_path, color);
COLOR.palettes.try_emplace(color_path, color);
}
}
}