ingame.rs 937 Bytes
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
36
37
38
use crate::state;
use crate::svg_loader;
use crate::utils;
use crate::resources;

pub struct InGameState {
    gui_svg: web_sys::SvgElement,
}

impl InGameState {
    pub fn new(level: svg_loader::SvgLevel) -> InGameState {
        InGameState {
            gui_svg: utils::get_element_by_id("ingame-ui").unwrap(),
        }
    }
}

impl state::State for InGameState {
    fn init(&mut self, _init: state::StateInitializer) -> state::Transition {
        self.gui_svg
            .style()
            .set_property("display", "block")
            .unwrap();

        let rendering = resources::Rendering::new("game-canvas").unwrap();
        rendering.ctx.set_fill_style(&"#100e23".into());
        rendering.ctx.fill_rect(0.0, 0.0, 1920.0, 1080.0);

        state::Transition::Sleep
    }

    fn deinit(&mut self) {
        self.gui_svg
            .style()
            .set_property("display", "none")
            .unwrap();
    }
}