Commit cabe7064 authored by Rahix's avatar Rahix 🦀
Browse files

bottle_angel: Show objective status

Display how many drop points were collected already.
parent 146dd581
......@@ -4,6 +4,7 @@ use crate::entities;
use crate::resources;
use crate::sprites;
use crate::svg_loader;
use crate::utils;
pub struct BottleAngelShift {
hours: usize,
......@@ -44,8 +45,19 @@ impl super::AngelShiftImpl for BottleAngelShift {
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">Collect drop points:</text>
<text id="ingame-bottle-angel-stats" x="430" y="0" class="stats-number">0/4</text>
"#,
);
let stats =
utils::get_element_by_id::<web_sys::Element>("ingame-bottle-angel-stats").unwrap();
entities::create_drop_points(world, level);
resources.insert(BottleAngelState::new(4));
resources.insert(BottleAngelState::new(4, stats));
schedule_builder
.add_thread_local(collect_bottledrops_system())
......@@ -56,15 +68,24 @@ impl super::AngelShiftImpl for BottleAngelShift {
pub struct BottleAngelState {
collected_drops: usize,
drops_in_map: usize,
stats_element: web_sys::Element,
}
impl BottleAngelState {
fn new(drops_in_map: usize) -> BottleAngelState {
fn new(drops_in_map: usize, stats_element: web_sys::Element) -> BottleAngelState {
BottleAngelState {
collected_drops: 0,
drops_in_map,
stats_element,
}
}
fn update_stats(&self) {
self.stats_element.set_text_content(Some(&format!(
"{}/{}",
self.collected_drops, self.drops_in_map
)));
}
}
#[legion::system]
......@@ -99,6 +120,7 @@ pub fn collect_bottledrops(
*sprite = components::Sprite::new(sprites::Sprite::BottleDropPointEmpty);
cmd.remove_component::<components::Matebottledrop>(entity);
bottle_angel_state.collected_drops += 1;
bottle_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