From c7607533ce5bbd4461f5804a2c88486b13c99b44 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Mon, 2 Dec 2024 17:02:59 -0500 Subject: [PATCH] A bit of a quick test for the GUI system, but not sure how to make this do more. --- gui.cpp | 5 ++--- gui.hpp | 2 +- main.cpp | 2 -- meson.build | 2 ++ tests/gui.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ tests/render.cpp | 3 ++- 6 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 tests/gui.cpp diff --git a/gui.cpp b/gui.cpp index 95c2c02..e8adf0f 100644 --- a/gui.cpp +++ b/gui.cpp @@ -252,8 +252,7 @@ void GUI::render_scene() { $renderer.display(); } -int GUI::main() { - // $sounds.play("ambient"); +int GUI::main(bool run_once) { create_renderer(); run_systems(); @@ -266,7 +265,7 @@ int GUI::main() { } std::this_thread::sleep_for(10ms); - } while($renderer.is_open()); + } while(!run_once && $renderer.is_open()); return 0; } diff --git a/gui.hpp b/gui.hpp index 5da2b65..bc7d739 100644 --- a/gui.hpp +++ b/gui.hpp @@ -69,5 +69,5 @@ public: void save_world(); void shake(); - int main(); + int main(bool run_once=false); }; diff --git a/main.cpp b/main.cpp index 70a10cf..9ade6f5 100644 --- a/main.cpp +++ b/main.cpp @@ -72,9 +72,7 @@ int main(int argc, char *argv[]) { _setmode(_fileno(stdout), _O_U16TEXT); #endif DinkyECS::World world; - Map game_map(GAME_MAP_X, GAME_MAP_Y); - save::load_configs(world); if(argc == 2) { diff --git a/meson.build b/meson.build index a832172..0e047df 100644 --- a/meson.build +++ b/meson.build @@ -33,6 +33,7 @@ runtests = executable('runtests', [ 'pathing.cpp', 'lights.cpp', 'systems.cpp', + 'gui.cpp', 'worldbuilder.cpp', 'tests/fsm.cpp', 'tests/dbc.cpp', @@ -48,6 +49,7 @@ runtests = executable('runtests', [ 'tests/sound.cpp', 'tests/pathing.cpp', 'tests/lighting.cpp', + 'tests/gui.cpp', 'tests/worldbuilder.cpp', ], dependencies: dependencies) diff --git a/tests/gui.cpp b/tests/gui.cpp new file mode 100644 index 0000000..60a20c7 --- /dev/null +++ b/tests/gui.cpp @@ -0,0 +1,41 @@ +#include +#include +#include "gui.hpp" +#include "map.hpp" +#include "dinkyecs.hpp" +#include "worldbuilder.hpp" +#include "save.hpp" +#include "systems.hpp" +#include "collider.hpp" +#include "components.hpp" + +using namespace fmt; +using namespace components; +using std::string; + +TEST_CASE("load a basic gui run but don't loop", "[render]") { + DinkyECS::World world; + save::load_configs(world); + Map game_map(40, 40); + WorldBuilder builder(game_map); + builder.generate(); + + const auto &config = world.get_the(); + // configure a player as a fact of the world + Player player{world.entity()}; + world.set_the(player); + + world.set(player.entity, {game_map.place_entity(0)}); + world.set(player.entity, {0, 0}); + world.set(player.entity, {100, 10}); + world.set(player.entity, {config.PLAYER_TILE}); + world.set(player.entity, {5}); + world.set(player.entity, {6,1}); + + spatial_map collider; + world.set_the(collider); + System::init_positions(world); + + GUI gui(world, game_map); + gui.main(true); // runs once +} diff --git a/tests/render.cpp b/tests/render.cpp index 45e350b..cc52dfb 100644 --- a/tests/render.cpp +++ b/tests/render.cpp @@ -47,7 +47,7 @@ TEST_CASE("can render a text", "[render]") { save::load_configs(world); const auto& config = world.get_the(); - Panel map_view(0, 0, 20, 5, true); + Panel map_view(0, 0, 20, 20, true); Map map(20,20); WorldBuilder builder(map); builder.generate(); @@ -72,6 +72,7 @@ TEST_CASE("can render a text", "[render]") { for(int i = 2; i < 14; i++) { renderer.resize_grid(i * 10, map_view); + map_canvas = Canvas(map_view.width * 2, map_view.height * 4); run_renderer(renderer, map_view); }