Map is way better and components::Tile is _vastly_ improved by switching to a wchar_t on display and letting nlohmann::json auto convert it for me.

This commit is contained in:
Zed A. Shaw 2025-03-22 02:10:56 -04:00
parent 2b57552152
commit 2e79cf8781
11 changed files with 70 additions and 71 deletions

View file

@ -5,6 +5,7 @@
#include "components.hpp"
#include "rand.hpp"
#include "animation.hpp"
#include "systems.hpp"
#include "rand.hpp"
#include <codecvt>
#include <iostream>
@ -13,7 +14,9 @@ namespace gui {
using namespace components;
MapViewUI::MapViewUI(GameLevel &level) :
$level(level), $tiles(level.map->width(), level.map->height())
$level(level),
$tiles(level.map->width(),
level.map->height())
{
}
@ -26,7 +29,9 @@ namespace gui {
$gui.layout("[map_grid]");
auto grid = $gui.entity("map_grid");
$gui.set<guecs::WideText>(grid, {L"Loading...", 45, ColorValue::DARK_LIGHT, 10});
$gui.set<guecs::WideText>(grid,
{L"Loading...", 45, ColorValue::DARK_LIGHT, 10});
$gui.set<guecs::Sprite>(grid, {"paper_ui_background"});
$gui.init();
@ -35,28 +40,11 @@ namespace gui {
void MapViewUI::render(sf::RenderWindow &window) {
$tiles = $level.map->tiles();
auto grid = $gui.entity("map_grid");
auto player_pos = $level.world->get<Position>($level.player).location;
std::string map;
matrix::box it{$level.map->walls(), player_pos.x, player_pos.y, 7, 3};
while(it.next())
{
if(it.x == player_pos.x && it.y == player_pos.y) {
map += "@";
} else {
map += $tiles.at(it.x, it.y).display;
}
if(it.x == it.right - 1) map += "\n";
}
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::wstring map_wstr = converter.from_bytes(map);
std::wstring map_out = System::draw_map($level, 13, 6);
auto& map_text = $gui.get<guecs::WideText>(grid);
map_text.update(map_wstr);
map_text.update(map_out);
$gui.render(window);
}