Use better name for context

This commit is contained in:
meehl committed 2025-11-02 09:53:37 +01:00
1 parent 18b05338bf
commit 2739c45181
8 files changed
+92 -106

No files matched your search

+6 -6
View File
@@ -1,22 +1,22 @@
use crate::{
input::{str_as_keycode, str_as_mousebutton},
lua::ContextSocket,
lua::Context,
};
use mlua::{Lua, Result as LuaResult};
pub fn get_cursor_pos(l: &Lua, _: ()) -> LuaResult<(u32, u32)> {
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
let pos = socket.input().mouse_pos();
let ctx = l.app_data_ref::<&'static Context>().unwrap();
let pos = ctx.input().mouse_pos();
Ok((pos.x as u32, pos.y as u32))
}
pub fn is_key_down(l: &Lua, key_name: String) -> LuaResult<bool> {
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
let ctx = l.app_data_ref::<&'static Context>().unwrap();
if let Some(code) = str_as_keycode(&key_name) {
Ok(socket.input().key_pressed(code))
Ok(ctx.input().key_pressed(code))
} else if let Some(button) = str_as_mousebutton(&key_name) {
Ok(socket.input().mouse_pressed(button))
Ok(ctx.input().mouse_pressed(button))
} else {
Ok(false)
}