rust_warrior/engine/systems/
ui.rs

1//! contains system which prints out the state of the world
2
3#[cfg(feature = "ncurses")]
4use crate::engine::curses;
5
6use crate::{engine::world::World, floor::Floor, unit::Unit};
7
8#[cfg(feature = "ncurses")]
9pub fn ui_system(world: &World, events: Vec<String>, c: &mut curses::Curses) {
10    let floor = update_floor(world);
11    c.clear();
12    c.println(&floor.draw());
13    for e in events {
14        c.println(&e);
15    }
16}
17
18/// This system simply calls the `draw` method of
19/// [`Floor`](crate::floor::Floor) after each turn is executed.
20#[cfg(not(feature = "ncurses"))]
21pub fn ui_system(world: &World, events: Vec<String>) {
22    let floor = update_floor(world);
23    println!("{}", floor.draw());
24    for e in events {
25        println!("{}", e);
26    }
27}
28
29fn update_floor(world: &World) -> Floor {
30    let mut floor = world.floor.clone();
31
32    floor.units = Vec::new();
33
34    let warrior = Unit::new(world.warrior.unit_type, world.warrior.position);
35    floor.units.push(warrior);
36
37    for unit in &world.other_units {
38        let updated = Unit::new(unit.unit_type, unit.position);
39        floor.units.push(updated);
40    }
41
42    floor
43}