I think the actual map drawing is more of a view thing than in the system, so I've moved it to the MapViewUI out of system.
This commit is contained in:
parent
380e18b91a
commit
5adeb4e078
5 changed files with 42 additions and 78 deletions
37
systems.cpp
37
systems.cpp
|
@ -173,40 +173,3 @@ void System::draw_entities(DinkyECS::World &world, Map &game_map, const Matrix &
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
void System::draw_map(DinkyECS::World &world, Map &game_map, const Matrix &lighting, ftxui::Canvas &canvas, size_t view_x, size_t view_y) {
|
||||
const auto& debug = world.get_the<Debug>();
|
||||
const auto& player = world.get_the<Player>();
|
||||
const auto& player_position = world.get<Position>(player.entity);
|
||||
Point start = game_map.center_camera(player_position.location, view_x, view_y);
|
||||
auto &tiles = game_map.tiles();
|
||||
auto &paths = game_map.paths();
|
||||
|
||||
size_t end_x = std::min(view_x, game_map.width() - start.x);
|
||||
size_t end_y = std::min(view_y, game_map.height() - start.y);
|
||||
|
||||
for(size_t y = 0; y < end_y; ++y) {
|
||||
for(size_t x = 0; x < end_x; ++x) {
|
||||
const TileCell& tile = tiles.at(start.x+x, start.y+y);
|
||||
// light value is an integer that's a percent
|
||||
float light_value = debug.LIGHT ? 80 * PERCENT : lighting[start.y+y][start.x+x] * PERCENT;
|
||||
int dnum = debug.PATHS ? paths[start.y+y][start.x+x] : WALL_PATH_LIMIT;
|
||||
|
||||
if(debug.PATHS && dnum != WALL_PATH_LIMIT) {
|
||||
string num = dnum > 15 ? "*" : format("{:x}", dnum);
|
||||
|
||||
canvas.DrawText(x * 2, y * 4, num, [dnum, tile, light_value](auto &pixel) {
|
||||
pixel.foreground_color = Color::HSV(dnum * 20, 150, 200);
|
||||
pixel.background_color = Color::HSV(30, 20, tile.bg_v * 50 * PERCENT);
|
||||
});
|
||||
} else {
|
||||
canvas.DrawText(x * 2, y * 4, tile.display, [tile, light_value](auto &pixel) {
|
||||
pixel.foreground_color = Color::HSV(tile.fg_h, tile.fg_s, tile.fg_v * light_value);
|
||||
pixel.background_color = Color::HSV(tile.bg_h, tile.bg_s, tile.bg_v * light_value);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System::draw_entities(world, game_map, lighting, canvas, start, view_x, view_y);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue