diff --git a/Makefile b/Makefile index 47b9365..af938f2 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ else endif debug: build - gdb --nx -x .gdbinit --ex run --args builddir/zedcaster + gdb --nx -x .gdbinit --ex run --args builddir/runtests debug_run: build gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args builddir/zedcaster diff --git a/palette.cpp b/palette.cpp index f40bd2d..3f64142 100644 --- a/palette.cpp +++ b/palette.cpp @@ -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); + } } } diff --git a/palette.hpp b/palette.hpp index ff70da7..9844924 100644 --- a/palette.hpp +++ b/palette.hpp @@ -4,6 +4,7 @@ namespace palette { using std::string; + bool initialized(); void init(const std::string &config="palette"); sf::Color get(const string &key); diff --git a/tests/battle.cpp b/tests/battle.cpp index b6572b8..49cd873 100644 --- a/tests/battle.cpp +++ b/tests/battle.cpp @@ -11,6 +11,7 @@ #include "animation.hpp" #include "components.hpp" #include "ai.hpp" +#include "palette.hpp" using namespace combat; using namespace boss; @@ -100,6 +101,7 @@ TEST_CASE("boss/systems.cpp works", "[combat-battle]") { components::init(); sfml::Backend backend; guecs::init(&backend); + ai::reset(); ai::init("ai"); animation::init(); diff --git a/tests/palette.cpp b/tests/palette.cpp index 988e565..9a28624 100644 --- a/tests/palette.cpp +++ b/tests/palette.cpp @@ -7,6 +7,10 @@ using namespace fmt; TEST_CASE("color palette test", "[color-palette]") { palette::init(); + REQUIRE(palette::initialized() == true); + // confirm it's idempotent + palette::init(); + sf::Color expect{10, 10, 10, 255}; auto gui_text = palette::get("gui/theme:dark_dark");