Fix a bug in palette that kept it from being idempotent.
This commit is contained in:
parent
986b2612d4
commit
37b007d79c
5 changed files with 21 additions and 10 deletions
2
Makefile
2
Makefile
|
|
@ -48,7 +48,7 @@ else
|
||||||
endif
|
endif
|
||||||
|
|
||||||
debug: build
|
debug: build
|
||||||
gdb --nx -x .gdbinit --ex run --args builddir/zedcaster
|
gdb --nx -x .gdbinit --ex run --args builddir/runtests
|
||||||
|
|
||||||
debug_run: build
|
debug_run: build
|
||||||
gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args builddir/zedcaster
|
gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args builddir/zedcaster
|
||||||
|
|
|
||||||
22
palette.cpp
22
palette.cpp
|
|
@ -16,6 +16,10 @@ namespace palette {
|
||||||
|
|
||||||
static PaletteMgr COLOR;
|
static PaletteMgr COLOR;
|
||||||
|
|
||||||
|
bool initialized() {
|
||||||
|
return COLOR.initialized;
|
||||||
|
}
|
||||||
|
|
||||||
void init(const string &json_file) {
|
void init(const string &json_file) {
|
||||||
if(!COLOR.initialized) {
|
if(!COLOR.initialized) {
|
||||||
COLOR.initialized = true;
|
COLOR.initialized = true;
|
||||||
|
|
@ -41,18 +45,18 @@ namespace palette {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for(auto [color_path, ref] : COLOR.pending_refs) {
|
for(auto [color_path, ref] : COLOR.pending_refs) {
|
||||||
dbc::check(COLOR.palettes.contains(ref),
|
dbc::check(COLOR.palettes.contains(ref),
|
||||||
fmt::format("In {} you have {} referring to {} but {} doesn't exist.",
|
fmt::format("In {} you have {} referring to {} but {} doesn't exist.",
|
||||||
COLOR.config, color_path, ref, ref));
|
COLOR.config, color_path, ref, ref));
|
||||||
dbc::check(!COLOR.palettes.contains(color_path),
|
dbc::check(!COLOR.palettes.contains(color_path),
|
||||||
fmt::format("Color {} with ref {} is duplicated.", color_path, ref));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
namespace palette {
|
namespace palette {
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
|
bool initialized();
|
||||||
void init(const std::string &config="palette");
|
void init(const std::string &config="palette");
|
||||||
|
|
||||||
sf::Color get(const string &key);
|
sf::Color get(const string &key);
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
#include "animation.hpp"
|
#include "animation.hpp"
|
||||||
#include "components.hpp"
|
#include "components.hpp"
|
||||||
#include "ai.hpp"
|
#include "ai.hpp"
|
||||||
|
#include "palette.hpp"
|
||||||
|
|
||||||
using namespace combat;
|
using namespace combat;
|
||||||
using namespace boss;
|
using namespace boss;
|
||||||
|
|
@ -100,6 +101,7 @@ TEST_CASE("boss/systems.cpp works", "[combat-battle]") {
|
||||||
components::init();
|
components::init();
|
||||||
sfml::Backend backend;
|
sfml::Backend backend;
|
||||||
guecs::init(&backend);
|
guecs::init(&backend);
|
||||||
|
|
||||||
ai::reset();
|
ai::reset();
|
||||||
ai::init("ai");
|
ai::init("ai");
|
||||||
animation::init();
|
animation::init();
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,10 @@ using namespace fmt;
|
||||||
|
|
||||||
TEST_CASE("color palette test", "[color-palette]") {
|
TEST_CASE("color palette test", "[color-palette]") {
|
||||||
palette::init();
|
palette::init();
|
||||||
|
REQUIRE(palette::initialized() == true);
|
||||||
|
// confirm it's idempotent
|
||||||
|
palette::init();
|
||||||
|
|
||||||
sf::Color expect{10, 10, 10, 255};
|
sf::Color expect{10, 10, 10, 255};
|
||||||
|
|
||||||
auto gui_text = palette::get("gui/theme:dark_dark");
|
auto gui_text = palette::get("gui/theme:dark_dark");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue