mirror of
https://github.com/redstrate/Kawari.git
synced 2025-06-30 11:47:45 +00:00
parent
92a5cc48eb
commit
cdcce88c5f
3 changed files with 24 additions and 30 deletions
|
@ -905,7 +905,9 @@ async fn main() {
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut lua = lua.lock().unwrap();
|
let mut lua = lua.lock().unwrap();
|
||||||
load_global_script(&mut lua);
|
if let Err(err) = load_global_script(&mut lua) {
|
||||||
|
tracing::warn!("Failed to load Global.lua: {:?}", err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let (handle, _) = spawn_main_loop();
|
let (handle, _) = spawn_main_loop();
|
||||||
|
|
|
@ -626,7 +626,9 @@ impl ZoneConnection {
|
||||||
}
|
}
|
||||||
Task::ReloadScripts => {
|
Task::ReloadScripts => {
|
||||||
let mut lua = self.lua.lock().unwrap();
|
let mut lua = self.lua.lock().unwrap();
|
||||||
load_global_script(&mut lua);
|
if let Err(err) = load_global_script(&mut lua) {
|
||||||
|
tracing::warn!("Failed to load Global.lua: {:?}", err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Task::ToggleInvisibility { invisible } => {
|
Task::ToggleInvisibility { invisible } => {
|
||||||
self.toggle_invisibility(*invisible).await;
|
self.toggle_invisibility(*invisible).await;
|
||||||
|
|
|
@ -415,56 +415,46 @@ impl FromLua for EffectsBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Loads `Global.lua`
|
/// Loads `Global.lua`
|
||||||
pub fn load_global_script(lua: &mut Lua) {
|
pub fn load_global_script(lua: &mut Lua) -> mlua::Result<()> {
|
||||||
let register_action_func = lua
|
let register_action_func =
|
||||||
.create_function(|lua, (action_id, action_script): (u32, String)| {
|
lua.create_function(|lua, (action_id, action_script): (u32, String)| {
|
||||||
tracing::info!("Registering {action_id} with {action_script}!");
|
tracing::info!("Registering {action_id} with {action_script}!");
|
||||||
let mut state = lua.app_data_mut::<ExtraLuaState>().unwrap();
|
let mut state = lua.app_data_mut::<ExtraLuaState>().unwrap();
|
||||||
let _ = state.action_scripts.insert(action_id, action_script);
|
let _ = state.action_scripts.insert(action_id, action_script);
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let register_event_func = lua
|
let register_event_func =
|
||||||
.create_function(|lua, (event_id, event_script): (u32, String)| {
|
lua.create_function(|lua, (event_id, event_script): (u32, String)| {
|
||||||
tracing::info!("Registering {event_id} with {event_script}!");
|
tracing::info!("Registering {event_id} with {event_script}!");
|
||||||
let mut state = lua.app_data_mut::<ExtraLuaState>().unwrap();
|
let mut state = lua.app_data_mut::<ExtraLuaState>().unwrap();
|
||||||
let _ = state.event_scripts.insert(event_id, event_script);
|
let _ = state.event_scripts.insert(event_id, event_script);
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let register_command_func = lua
|
let register_command_func =
|
||||||
.create_function(|lua, (command_name, command_script): (String, String)| {
|
lua.create_function(|lua, (command_name, command_script): (String, String)| {
|
||||||
tracing::info!("Registering {command_name} with {command_script}!");
|
tracing::info!("Registering {command_name} with {command_script}!");
|
||||||
let mut state = lua.app_data_mut::<ExtraLuaState>().unwrap();
|
let mut state = lua.app_data_mut::<ExtraLuaState>().unwrap();
|
||||||
let _ = state.command_scripts.insert(command_name, command_script);
|
let _ = state.command_scripts.insert(command_name, command_script);
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
lua.set_app_data(ExtraLuaState::default());
|
lua.set_app_data(ExtraLuaState::default());
|
||||||
|
lua.globals().set("registerAction", register_action_func)?;
|
||||||
|
lua.globals().set("registerEvent", register_event_func)?;
|
||||||
lua.globals()
|
lua.globals()
|
||||||
.set("registerAction", register_action_func)
|
.set("registerCommand", register_command_func)?;
|
||||||
.unwrap();
|
|
||||||
lua.globals()
|
|
||||||
.set("registerEvent", register_event_func)
|
|
||||||
.unwrap();
|
|
||||||
lua.globals()
|
|
||||||
.set("registerCommand", register_command_func)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let effectsbuilder_constructor = lua
|
let effectsbuilder_constructor = lua.create_function(|_, ()| Ok(EffectsBuilder::default()))?;
|
||||||
.create_function(|_, ()| Ok(EffectsBuilder::default()))
|
|
||||||
.unwrap();
|
|
||||||
lua.globals()
|
lua.globals()
|
||||||
.set("EffectsBuilder", effectsbuilder_constructor)
|
.set("EffectsBuilder", effectsbuilder_constructor)?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let config = get_config();
|
let config = get_config();
|
||||||
let file_name = format!("{}/Global.lua", &config.world.scripts_location);
|
let file_name = format!("{}/Global.lua", &config.world.scripts_location);
|
||||||
lua.load(std::fs::read(&file_name).expect("Failed to locate scripts directory!"))
|
lua.load(std::fs::read(&file_name).expect("Failed to locate scripts directory!"))
|
||||||
.set_name("@".to_string() + &file_name)
|
.set_name("@".to_string() + &file_name)
|
||||||
.exec()
|
.exec()?;
|
||||||
.unwrap();
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue