use crate::modding::control::PluginControl;
use crate::modding::error::ModResult;
use std::path::Path;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct ModMetadata {
pub name: String,
pub version: String,
pub author: Option<String>,
pub description: Option<String>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct ModHandle {
pub id: String,
pub metadata: ModMetadata,
pub backend: ModBackend,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum ModBackend {
Rhai,
Wasm,
}
impl std::fmt::Display for ModBackend {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ModBackend::Rhai => write!(f, "rhai"),
ModBackend::Wasm => write!(f, "wasm"),
}
}
}
pub trait ModLoader: Send + Sync {
fn load(&mut self, path: &Path) -> ModResult<ModHandle>;
fn unload(&mut self, handle: &ModHandle) -> ModResult<()>;
fn control_plugin(&mut self, handle: &ModHandle, control: &PluginControl) -> ModResult<()>;
fn call_function(
&mut self,
handle: &ModHandle,
fn_name: &str,
args: Vec<serde_json::Value>,
) -> ModResult<serde_json::Value> {
let _ = (handle, fn_name, args);
Ok(serde_json::Value::Null)
}
fn drain_commands(&mut self) -> Vec<PluginControl> {
Vec::new() }
fn drain_events(&mut self) -> Vec<(String, serde_json::Value)> {
Vec::new() }
fn dispatch_event(&mut self, event_type: &str, event_data: &serde_json::Value) -> usize {
let _ = (event_type, event_data);
0 }
fn clone_box(&self) -> Box<dyn ModLoader>;
}