68 lines
1.6 KiB
Rust
68 lines
1.6 KiB
Rust
use crate::prelude::Scene;
|
|
|
|
pub mod session; use session::Session;
|
|
pub mod scene;
|
|
|
|
pub struct App {
|
|
pub session:Session,
|
|
|
|
pub document:web_sys::Document,
|
|
pub menu:web_sys::Element,
|
|
pub container:web_sys::Element,
|
|
|
|
unload:Option<fn()>,
|
|
}
|
|
impl App {
|
|
pub fn init() -> Result<Self,()>
|
|
{
|
|
match web_sys::window() {
|
|
Some(window) => match window.document() {
|
|
Some(document) => {
|
|
let menu = document.create_element("nav");
|
|
let container = document.create_element("main");
|
|
|
|
if menu.is_ok() && container.is_ok() {
|
|
Ok(Self {
|
|
session:Session::new(),
|
|
|
|
document:document,
|
|
menu:menu.unwrap(),
|
|
container:container.unwrap(),
|
|
|
|
unload:None,
|
|
})
|
|
} else {
|
|
Err(())
|
|
}
|
|
}
|
|
None => Err(())
|
|
}
|
|
None => Err(())
|
|
}
|
|
}
|
|
|
|
pub fn load<S:Scene>(&mut self)
|
|
{
|
|
match self.unload {
|
|
Some(proc) => { proc(); }
|
|
None => { }
|
|
}
|
|
|
|
self.document_clear();
|
|
S::load();
|
|
self.unload = Some(S::unload);
|
|
}
|
|
|
|
pub fn document_clear(&self)
|
|
{
|
|
match self.document.body() {
|
|
Some(body) => {
|
|
while let Some(child) = body.last_child() {
|
|
body.remove_child(&child).ok();
|
|
}
|
|
}
|
|
None => { }
|
|
}
|
|
}
|
|
}
|