diff --git a/gui.cpp b/gui.cpp index ca74125..95c2c02 100644 --- a/gui.cpp +++ b/gui.cpp @@ -52,10 +52,9 @@ GUI::GUI(DinkyECS::World &world, Map& game_map) : } void GUI::resize_map(int new_size) { - if($renderer.resize_grid(new_size, $map_view)) { + $renderer.resize_grid(new_size, $map_view); // set canvas to best size - $canvas = Canvas($map_view.width * 2, $map_view.height * 4); - } + $canvas = Canvas($map_view.width * 2, $map_view.height * 4); } void GUI::save_world() { diff --git a/meson.build b/meson.build index a567e33..a832172 100644 --- a/meson.build +++ b/meson.build @@ -32,6 +32,7 @@ runtests = executable('runtests', [ 'render.cpp', 'pathing.cpp', 'lights.cpp', + 'systems.cpp', 'worldbuilder.cpp', 'tests/fsm.cpp', 'tests/dbc.cpp', diff --git a/render.cpp b/render.cpp index d61074e..d6d29fc 100644 --- a/render.cpp +++ b/render.cpp @@ -44,7 +44,7 @@ sf::Sprite &SFMLRender::get_text_sprite(wchar_t tile) { } -bool SFMLRender::resize_grid(int new_size, Panel &panel_out) { +void SFMLRender::resize_grid(int new_size, Panel &panel_out) { auto glyph = $font.getGlyph($config.bg_tile, new_size, false); int view_x = std::ceil(($config.video_x - panel_out.x) / glyph.bounds.width); int view_y = std::ceil(($config.video_y - panel_out.y) / glyph.bounds.height); @@ -57,7 +57,6 @@ bool SFMLRender::resize_grid(int new_size, Panel &panel_out) { $bg_sprite = get_text_sprite($config.bg_tile); $bg_bounds = $bg_sprite.getLocalBounds(); panel_out.resize(view_x, view_y); - return true; } inline void configure_tile(const sf::Sprite &sprite, sf::FloatRect &sp_bounds, sf::FloatRect bg_bounds, float &width_delta, float &height_delta) { diff --git a/render.hpp b/render.hpp index 0848e61..1ab4bc2 100644 --- a/render.hpp +++ b/render.hpp @@ -50,7 +50,7 @@ struct SFMLRender { SFMLRender(SFMLRender &other) = delete; sf::Sprite &get_text_sprite(wchar_t tile); - bool resize_grid(int new_size, Panel &panel_out); + void resize_grid(int new_size, Panel &panel_out); void render_grid(const std::wstring &text, sf::Color default_fg, sf::Color default_bg, float x, float y); void render_text(const std::wstring &text, sf::Color default_fg, sf::Color default_bg, float x, float y); diff --git a/tests/render.cpp b/tests/render.cpp index e6b7ad5..45e350b 100644 --- a/tests/render.cpp +++ b/tests/render.cpp @@ -2,9 +2,17 @@ #include #include "render.hpp" #include "panel.hpp" +#include "map.hpp" +#include "worldbuilder.hpp" +#include "config.hpp" +#include "components.hpp" +#include "systems.hpp" +#include "save.hpp" using namespace ftxui; using namespace fmt; +using namespace components; +using namespace lighting; using std::string; void run_renderer(SFMLRender &renderer, Panel &panel) { @@ -15,11 +23,10 @@ void run_renderer(SFMLRender &renderer, Panel &panel) { renderer.draw(panel); } -TEST_CASE("can render a text or grid panel", "[render]") { +TEST_CASE("can render a text panel", "[render]") { SFMLRender renderer; Panel panel(0, 0, 20, 5); - Panel grid(200, 200, 20, 5, true); auto text_box = Renderer([]{ return hbox({ @@ -29,10 +36,44 @@ TEST_CASE("can render a text or grid panel", "[render]") { }); panel.set_renderer(text_box); - grid.set_renderer(text_box); - run_renderer(renderer, panel); - run_renderer(renderer, grid); + renderer.close(); +} + +TEST_CASE("can render a text", "[render]") { + SFMLRender renderer; + DinkyECS::World world; + + save::load_configs(world); + const auto& config = world.get_the(); + + Panel map_view(0, 0, 20, 5, true); + Map map(20,20); + WorldBuilder builder(map); + builder.generate(); + + Player player{world.entity()}; + world.set_the(player); + world.set(player.entity, {config.PLAYER_TILE}); + world.set(player.entity, {6,1}); + + world.set(player.entity, {map.place_entity(0)}); + + LightRender lights(map.width(), map.height(), map.limit()); + + Canvas map_canvas(map_view.width * 2, map_view.height * 4); + + map_view.set_renderer(Renderer([&] { + System::draw_map(world, map, lights.lighting(), map_canvas, map_view.width, map_view.height); + return canvas(map_canvas); + })); + + run_renderer(renderer, map_view); + + for(int i = 2; i < 14; i++) { + renderer.resize_grid(i * 10, map_view); + run_renderer(renderer, map_view); + } renderer.close(); }