You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.2 KiB
47 lines
1.2 KiB
#include "tilemap.hpp"
|
|
#include "dbc.hpp"
|
|
#include "constants.hpp"
|
|
#include "render.hpp"
|
|
|
|
TileMap::TileMap(Config& config, size_t width, size_t height)
|
|
: $config(config),
|
|
$width(width),
|
|
$height(height),
|
|
$tile_ids(height, matrix::Row(width, SPACE_VALUE)),
|
|
$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];
|
|
|
|
if(int(it.x) == show_x && int(it.y) == show_y) {
|
|
fmt::print("{}<", cell);
|
|
} else {
|
|
fmt::print("{} ", cell);
|
|
}
|
|
|
|
if(it.row) fmt::print("\n");
|
|
}
|
|
}
|
|
|
|
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);
|
|
std::string tile_s = $config[tile_name];
|
|
|
|
$tile_ids[it.y][it.x] = tile[0];
|
|
$display[it.y][it.x] = tile_s;
|
|
}
|
|
}
|
|
|
|
bool TileMap::INVARIANT() {
|
|
dbc::check(matrix::height($tile_ids) == $height, "$tile_ids has wrong height");
|
|
dbc::check(matrix::width($tile_ids) == $width, "$tile_ids has wrong width");
|
|
return true;
|
|
}
|
|
|