Refactor context handling and redraw requests

Remove unsafe pointer shenanigans and give Lua instance ownership over
`Context`. Event handlers now directly mutate Context instead of using a
shared app state which is then hooked up to Context via unsafe pointers.
The removal of a shared state means stages (previously called "modes")
are now responsible for keeping their own internal state.

Additionally, clean up draw request handling and module hierarchy.
This commit is contained in:
meehl committed 2026-08-23 23:55:43 +02:00
1 parent 337e876571
commit cc6de120f2
27 files changed
+803 -876

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
use crate::{
input::{str_as_key, str_as_mousebutton},
pob::Context,
};
use mlua::{Lua, Result as LuaResult};
pub fn get_cursor_pos(l: &Lua, _: ()) -> LuaResult<(u32, u32)> {
let ctx = l.app_data_ref::<Context>().unwrap();
let pos = ctx.input_state.mouse_pos();
Ok((pos.x as u32, pos.y as u32))
}
pub fn is_key_down(l: &Lua, key_name: String) -> LuaResult<bool> {
let ctx = l.app_data_ref::<Context>().unwrap();
if let Some(key) = str_as_key(&key_name) {
Ok(ctx.input_state.key_pressed(&key))
} else if let Some(button) = str_as_mousebutton(&key_name) {
Ok(ctx.input_state.mouse_pressed(button))
} else {
Ok(false)
}
}