Make MapBuilder themeable with MapTheme trait
This commit is contained in:
parent
b807418601
commit
81b99c632c
@ -45,15 +45,14 @@ impl State {
|
||||
spawn_amulet_of_yala(&mut ecs, map_builder.amulet_start);
|
||||
|
||||
map_builder
|
||||
.rooms
|
||||
.monster_spawns
|
||||
.iter()
|
||||
.skip(1)
|
||||
.map(|r| r.center())
|
||||
.for_each(|pos| spawn_monster(&mut ecs, &mut rng, pos));
|
||||
.for_each(|pos| spawn_monster(&mut ecs, &mut rng, *pos));
|
||||
|
||||
resources.insert(map_builder.map);
|
||||
resources.insert(Camera::new(map_builder.player_start));
|
||||
resources.insert(TurnState::AwaitingInput);
|
||||
resources.insert(map_builder.theme);
|
||||
|
||||
Self {
|
||||
ecs,
|
||||
@ -80,6 +79,7 @@ impl State {
|
||||
self.resources.insert(map_builder.map);
|
||||
self.resources.insert(Camera::new(map_builder.player_start));
|
||||
self.resources.insert(TurnState::AwaitingInput);
|
||||
self.resources.insert(map_builder.theme);
|
||||
}
|
||||
|
||||
fn game_over(&mut self, ctx: &mut BTerm) {
|
||||
|
@ -3,7 +3,12 @@ use crate::prelude::*;
|
||||
#[system]
|
||||
#[read_component(FieldOfView)]
|
||||
#[read_component(Player)]
|
||||
pub fn map_render(ecs: &SubWorld, #[resource] map: &Map, #[resource] camera: &Camera) {
|
||||
pub fn map_render(
|
||||
ecs: &SubWorld,
|
||||
#[resource] map: &Map,
|
||||
#[resource] camera: &Camera,
|
||||
#[resource] theme: &Box<dyn MapTheme>,
|
||||
) {
|
||||
let mut fov = <&FieldOfView>::query().filter(component::<Player>());
|
||||
let player_fov = fov.iter(ecs).next().unwrap();
|
||||
let mut draw_batch = DrawBatch::new();
|
||||
@ -25,14 +30,8 @@ pub fn map_render(ecs: &SubWorld, #[resource] map: &Map, #[resource] camera: &Ca
|
||||
DARK_GRAY
|
||||
};
|
||||
|
||||
match map.tiles[idx] {
|
||||
TileType::Floor => {
|
||||
draw_batch.set(pt - offset, ColorPair::new(tint, BLACK), to_cp437('.'))
|
||||
}
|
||||
TileType::Wall => {
|
||||
draw_batch.set(pt - offset, ColorPair::new(tint, BLACK), to_cp437('#'))
|
||||
}
|
||||
};
|
||||
let glyph = theme.tile_to_render(map.tiles[idx]);
|
||||
draw_batch.set(pt - offset, ColorPair::new(tint, BLACK), glyph);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user