game_manager.rs 1.11 KB
Newer Older
Rahix's avatar
Rahix committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use crate::resources;
use crate::utils;

#[legion::system]
pub fn update_game_manager(
    #[resource] clock: &resources::Clock,
    #[resource] game_manager: &mut resources::GameManager,
) {
    if let Some(timeout) = game_manager.return_timeout.as_mut() {
        if game_manager.return_timestamp.is_none() {
            utils::get_element_by_id::<web_sys::SvgElement>("ingame-return-to-heaven")
                .unwrap()
                .style()
                .set_property("display", "block")
                .unwrap();
        }

        let now = clock.wall_time();
        let timestamp = *game_manager.return_timestamp.get_or_insert(now);

        *timeout = now - timestamp;

        utils::get_element_by_id::<web_sys::Element>("ingame-return-secs")
            .unwrap()
            .set_inner_html(&format!("{:.0}", (3.0 - *timeout).ceil()));

        if game_manager.wants_return_to_heaven() {
            utils::get_element_by_id::<web_sys::SvgElement>("ingame-return-to-heaven")
                .unwrap()
                .style()
                .set_property("display", "none")
                .unwrap();
        }
    }
}