Fix up the colors and rendering so that tilemap just uses components::Tile all the time. Need to load all of the config data from json one time on system start instead of constantly, although constantly does make debugging live easier.
This commit is contained in:
parent
a4c13f7fc9
commit
0cbe20af35
10 changed files with 36 additions and 44 deletions
17
tilemap.cpp
17
tilemap.cpp
|
@ -3,19 +3,20 @@
|
|||
#include "constants.hpp"
|
||||
|
||||
using nlohmann::json;
|
||||
using components::Tile;
|
||||
|
||||
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, {"", {0,0,0}, {0,0,0}}))
|
||||
{
|
||||
}
|
||||
|
||||
void TileMap::dump(int show_x, int show_y) {
|
||||
for(matrix::each_row it{$tile_ids}; it.next();) {
|
||||
const TileCell &cell = $display[it.y][it.x];
|
||||
const Tile &cell = $display[it.y][it.x];
|
||||
|
||||
if(int(it.x) == show_x && int(it.y) == show_y) {
|
||||
fmt::print("{}<", cell.display);
|
||||
|
@ -30,15 +31,7 @@ void TileMap::dump(int show_x, int show_y) {
|
|||
void TileMap::set_tile(size_t x, size_t y, string 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]};
|
||||
|
||||
auto tile = components::convert<Tile>(tile_conf);
|
||||
$tile_ids[y][x] = tile_id[0];
|
||||
$display[y][x] = tile;
|
||||
}
|
||||
|
@ -50,7 +43,7 @@ void TileMap::load(matrix::Matrix &walls) {
|
|||
}
|
||||
}
|
||||
|
||||
const TileCell &TileMap::at(size_t x, size_t y) {
|
||||
const Tile &TileMap::at(size_t x, size_t y) {
|
||||
return $display[y][x];
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue