|
|
|
@ -84,10 +84,48 @@ MapViewUI::MapViewUI(DinkyECS::World& world, LightRender& lights, Map& game_map) |
|
|
|
|
$world(world), $lights(lights), $game_map(game_map) |
|
|
|
|
{} |
|
|
|
|
|
|
|
|
|
void MapViewUI::draw_map() { |
|
|
|
|
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, width, height); |
|
|
|
|
auto &tiles = $game_map.tiles(); |
|
|
|
|
auto &paths = $game_map.paths(); |
|
|
|
|
auto &lighting = $lights.lighting(); |
|
|
|
|
|
|
|
|
|
// WARN: this is exploiting that -1 in size_t becomes largest
|
|
|
|
|
size_t end_x = std::min(size_t(width), $game_map.width() - start.x); |
|
|
|
|
size_t end_y = std::min(size_t(height), $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, width, height); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void MapViewUI::create_render() { |
|
|
|
|
set_renderer(Renderer([&] { |
|
|
|
|
System::draw_map($world, $game_map, $lights.lighting(), $canvas, width, height); |
|
|
|
|
draw_map(); |
|
|
|
|
return canvas($canvas); |
|
|
|
|
})); |
|
|
|
|
} |
|
|
|
|