Renderer is now more standalone and doesn't try to protect against small maps, that's the GUI's job.

This commit is contained in:
Zed A. Shaw 2024-11-21 15:51:22 -05:00
parent 19b8bf1850
commit 15a302d133
11 changed files with 65 additions and 90 deletions

16
gui.cpp
View file

@ -22,19 +22,20 @@
#include "render.hpp"
#include "save.hpp"
const int MAX_FONT_SIZE = 140;
const int MIN_FONT_SIZE = 20;
using std::string;
using namespace fmt;
using namespace std::chrono_literals;
using namespace ftxui;
using namespace components;
GUI::GUI(DinkyECS::World &world, Map& game_map) :
$game_map(game_map),
$log({{"Welcome to the game!"}}),
$status_ui(SCREEN_X, SCREEN_Y, 0, 0),
$map_view(0, 0, GAME_MAP_POS, 0, true),
$view_port{0,0},
$status_ui(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT),
$map_view(GAME_MAP_POS, 0, 0, 0, true),
$world(world),
$sounds("./assets"),
$renderer()
@ -49,10 +50,9 @@ GUI::GUI(DinkyECS::World &world, Map& game_map) :
}
void GUI::resize_map(int new_size) {
if($renderer.resize_grid(new_size, $view_port)) {
if($renderer.resize_grid(new_size, $map_view)) {
// set canvas to best size
$canvas = Canvas($view_port.x * 2, $view_port.y * 4);
$map_view.resize($view_port.x, $view_port.y);
$canvas = Canvas($map_view.width * 2, $map_view.height * 4);
}
}
@ -66,7 +66,7 @@ void GUI::create_renderer() {
auto player = $world.get_the<Player>();
$map_view.set_renderer(Renderer([&] {
System::draw_map($world, $game_map, $canvas, $view_port.x, $view_port.y);
System::draw_map($world, $game_map, $canvas, $map_view.width, $map_view.height);
return canvas($canvas);
}));