Now have color and display char coming from assets/tiles.json but lighting still needs work.

This commit is contained in:
Zed A. Shaw 2024-12-24 02:56:17 -05:00
parent 7fe6ad174d
commit 89e31279be
4 changed files with 70 additions and 36 deletions

View file

@ -3,25 +3,27 @@
#include "constants.hpp"
#include "render.hpp"
using nlohmann::json;
using ftxui::Color;
TileMap::TileMap(size_t width, size_t height) :
$config("./assets/tiles.json"),
$width(width),
$height(height),
$tile_ids(height, matrix::Row(width, SPACE_VALUE)),
$display(height, TileRow(width, ""))
$display(height, TileRow(width, {""}))
{
}
void TileMap::dump(int show_x, int show_y) {
SFMLRender::init_terminal();
for(matrix::each_row it{$tile_ids}; it.next();) {
string cell = $display[it.y][it.x];
const TileCell &cell = $display[it.y][it.x];
if(int(it.x) == show_x && int(it.y) == show_y) {
fmt::print("{}<", cell);
fmt::print("{}<", cell.display);
} else {
fmt::print("{} ", cell);
fmt::print("{} ", cell.display);
}
if(it.row) fmt::print("\n");
@ -32,16 +34,24 @@ void TileMap::load(matrix::Matrix &walls) {
for(matrix::each_cell it{walls}; it.next();) {
string tile_name = walls[it.y][it.x] == SPACE_VALUE ? "FLOOR_TILE" : "WALL_TILE";
std::wstring tile = $config.wstring(tile_name);
string tile_s = $config[tile_name];
std::wstring tile_id = $config.wstring(tile_name, "display");
json tile_conf = $config[tile_name];
TileCell tile{
tile_conf["display"],
tile_conf["foreground"][0],
tile_conf["foreground"][1],
tile_conf["foreground"][2],
tile_conf["background"][0],
tile_conf["background"][1],
tile_conf["background"][2]};
$tile_ids[it.y][it.x] = tile[0];
$display[it.y][it.x] = tile_s;
$tile_ids[it.y][it.x] = tile_id[0];
$display[it.y][it.x] = tile;
}
}
const string &TileMap::at(size_t x, size_t y) {
const TileCell &TileMap::at(size_t x, size_t y) {
return $display[y][x];
}