diff --git a/assets/config.json b/assets/config.json new file mode 100644 index 0000000..e1946c2 --- /dev/null +++ b/assets/config.json @@ -0,0 +1,18 @@ +{ + "map": { + "WALL_TILE": "█", + "FLOOR_TILE": "\u2849", + "PLAYER_TILE": "♣", + "ENEMY_TILE": "Ω", + "BG_TILE": "█" + }, + "enemies": { + + }, + "player": { + + }, + "type": { + "TEST": 1234 + } +} diff --git a/main.cpp b/main.cpp index bd4847e..0ff9ab9 100644 --- a/main.cpp +++ b/main.cpp @@ -54,6 +54,9 @@ void configure_world(DinkyECS::World &world, Map &game_map) { int main() { DinkyECS::World world; + Config config("./assets/config.json"); + world.set_the(config); + Map game_map(GAME_MAP_X, GAME_MAP_Y); game_map.generate(); diff --git a/meson.build b/meson.build index 59bc3ea..abed8bb 100644 --- a/meson.build +++ b/meson.build @@ -44,6 +44,7 @@ roguish = executable('roguish', [ 'systems.cpp', 'ansi_parser.cpp', 'render.cpp', + 'config.cpp', ], dependencies: dependencies) diff --git a/tests/ansi_parser.cpp b/tests/ansi_parser.cpp index b04a674..f882487 100644 --- a/tests/ansi_parser.cpp +++ b/tests/ansi_parser.cpp @@ -12,7 +12,6 @@ #include // for Full, Screen #include // for ColorSupport, Color, Palette16, Palette256, TrueColor - using namespace fmt; using namespace ftxui; @@ -56,12 +55,12 @@ TEST_CASE("test out ragel parser", "[gui]") { sf::Color default_bg(100,100,100); // this sets the Truecolor so need to do it first - ANSIParser parser(default_fg, default_bg); + ANSIParser ansi(default_fg, default_bg); std::string colors = generate_colors(); std::cout << colors; - bool good = parser.parse(colors, [&](sf::Color bgcolor, sf::Color color, wchar_t ch) { + bool good = ansi.parse(colors, [&](sf::Color bgcolor, sf::Color color, wchar_t ch) { bool correct_char = ch == '#' || ch == ' ' || ch == '\n' || ch == '\r'; REQUIRE(correct_char); }); diff --git a/tests/config.cpp b/tests/config.cpp index 681ea21..5ccdd85 100644 --- a/tests/config.cpp +++ b/tests/config.cpp @@ -33,11 +33,30 @@ TEST_CASE("basic configuration system", "[config]") { REQUIRE(test_obj["name"] == "Zed"); } -void test_func(Config &ref) { +void test_can_ref(Config &ref) { REQUIRE(ref["types"]["OBJECT"]["name"] == "Zed"); } +TEST_CASE("can get references of config", "[config]") { + Config config("./tests/config.json"); + test_can_ref(config); +} + TEST_CASE("store config in any", "[config]") { + auto as_any = std::make_any("./tests/config.json"); + + Config &cfg = std::any_cast(as_any); + REQUIRE(cfg["types"]["NUMBER"] == 1234); +} + +void test_will_live(DinkyECS::World &world) { Config config("./tests/config.json"); - test_func(config); + world.set_the(config); +} + +TEST_CASE("can go into a world", "[config]") { + DinkyECS::World world; + test_will_live(world); + Config &cfg = world.get_the(); + REQUIRE(cfg["types"]["NUMBER"] == 1234); }