Commit 1c544313 authored by Rahix's avatar Rahix 🦀
Browse files

network_switch: Show objective status

Display how many switches are back online.
parent cabe7064
......@@ -4,6 +4,7 @@ use crate::entities;
use crate::resources;
use crate::sprites;
use crate::svg_loader;
use crate::utils;
pub struct NetworkSwitchShift {
hours: usize,
......@@ -26,15 +27,24 @@ impl NetworkSwitchShift {
pub struct NetworkSwitchAngelState {
reconnected_switches: usize,
switches_in_map: usize,
stats_element: web_sys::Element,
}
impl NetworkSwitchAngelState {
fn new(switches_in_map: usize) -> NetworkSwitchAngelState {
fn new(switches_in_map: usize, stats_element: web_sys::Element) -> NetworkSwitchAngelState {
NetworkSwitchAngelState {
reconnected_switches: 0,
switches_in_map,
stats_element,
}
}
fn update_stats(&self) {
self.stats_element.set_text_content(Some(&format!(
"{}/{}",
self.reconnected_switches, self.switches_in_map
)));
}
}
impl super::AngelShiftImpl for NetworkSwitchShift {
......@@ -57,8 +67,17 @@ impl super::AngelShiftImpl for NetworkSwitchShift {
schedule_builder: &mut legion::systems::Builder,
level: &svg_loader::SvgLevel,
) {
// Display objective
let objective = utils::get_element_by_id::<web_sys::Element>("ingame-objective").unwrap();
objective.set_inner_html(
r#"
<text x="30" y="0" class="stats-label">Switches online:</text>
<text id="ingame-network-stats" x="430" y="0" class="stats-number">0/4</text>
"#,
);
let stats = utils::get_element_by_id::<web_sys::Element>("ingame-network-stats").unwrap();
entities::create_network_switches(world, level);
resources.insert(NetworkSwitchAngelState::new(4));
resources.insert(NetworkSwitchAngelState::new(4, stats));
schedule_builder
.add_thread_local(reconnect_switches_system())
......@@ -98,6 +117,7 @@ pub fn reconnect_switches(
*sprite = components::Sprite::new(sprites::Sprite::NetworkSwitchConnected);
cmd.remove_component::<components::NetworkSwitch>(entity);
angel_state.reconnected_switches += 1;
angel_state.update_stats();
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment