Commit 6836b014 authored by Rahix's avatar Rahix 🦀
Browse files

gamestate: Deregister handlers

During state cleanup, remove all registered handlers from the DOM again.
parent eb8c895e
......@@ -137,7 +137,21 @@ impl EventHandlers {
}
pub fn deregister_all(&mut self) {
// TODO
if let Some(_) = self.key_handlers {
let body = utils::document().body().unwrap();
body.set_onkeydown(None);
body.set_onkeyup(None);
}
for id in self.mouse_handlers.keys() {
if let Ok(el) = utils::get_element_by_id::<web_sys::SvgElement>(id) {
el.set_onclick(None);
} else if let Ok(el) = utils::get_element_by_id::<web_sys::HtmlElement>(id) {
el.set_onclick(None);
} else {
panic!("Cannot find appropriate element {:?}", id);
}
}
}
}
......@@ -228,7 +242,8 @@ impl StateStorage {
}
pub fn deinit(&mut self) {
self.state.deinit()
self.state.deinit();
self.event_handlers.deregister_all();
}
pub fn update(&mut self) -> Transition {
......
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