use crate::components::{Position, Renderable}; use crate::map; use rltk::{Console, Rltk}; use specs::{Join, ReadExpect, ReadStorage, System}; pub struct DrawRenderables<'r> { pub ctx: &'r mut Rltk, } impl<'a, 'r> System<'a> for DrawRenderables<'r> { type SystemData = ( ReadStorage<'a, Position>, ReadStorage<'a, Renderable>, ReadExpect<'a, map::Map>, ); fn run(&mut self, (positions, renderables, map): Self::SystemData) { let points = iproduct!(0..map::MAPHEIGHT, 0..map::MAPWIDTH); for (idx, (tile, (y, x))) in map.tiles.iter().zip(points).enumerate() { // Render a tile depending upon the tile type if map.revealed_tiles[idx] { let fg = if map.visible_tiles[idx] { tile.color() } else { tile.color().to_greyscale() }; self.ctx.set( x as i32, y as i32, fg, rltk::RGB::from_f32(0., 0., 0.), tile.glyph(), ); } } for (pos, render) in (&positions, &renderables).join() { let idx = map.xy_idx(pos.x, pos.y); if map.visible_tiles[idx] { self.ctx .set(pos.x, pos.y, render.fg, render.bg, render.glyph); } } } }