use crate::dynamic_data::Battle; use crate::script_implementations::rune::wrappers::{impl_rune_wrapper, RuneStringKey, RuneWrapper}; use rune::runtime::{AnyObj, Shared}; use rune::Any; pub fn register(module: &mut rune::Module) -> anyhow::Result<()> { module.ty::()?; module.function_meta(RuneBattle::library)?; module.function_meta(RuneBattle::parties)?; module.function_meta(RuneBattle::can_flee)?; module.function_meta(RuneBattle::number_of_sides)?; module.function_meta(RuneBattle::pokemon_per_side)?; module.function_meta(RuneBattle::sides)?; module.function_meta(RuneBattle::random)?; module.function_meta(RuneBattle::has_ended)?; module.function_meta(RuneBattle::current_turn)?; module.function_meta(RuneBattle::get_pokemon)?; module.function_meta(RuneBattle::set_weather)?; Ok(()) } #[derive(Debug, Clone, Any)] pub struct RuneBattle(Battle); impl_rune_wrapper!(&Battle, RuneBattle); impl RuneBattle { #[rune::function] fn library(&self) -> Shared { self.0.library().wrap() } #[rune::function] fn parties(&self) -> Vec> { self.0.parties().iter().map(|p| p.wrap()).collect() } #[rune::function] fn can_flee(&self) -> bool { self.0.can_flee() } #[rune::function] fn number_of_sides(&self) -> u8 { self.0.number_of_sides() } #[rune::function] fn pokemon_per_side(&self) -> u8 { self.0.pokemon_per_side() } #[rune::function] fn sides(&self) -> Vec> { self.0.sides().iter().map(|s| s.wrap()).collect() } #[rune::function] fn random(&self) -> Shared { self.0.random().wrap() } #[rune::function] fn has_ended(&self) -> bool { self.0.has_ended() } #[rune::function] fn current_turn(&self) -> u32 { self.0.current_turn() } #[rune::function] fn get_pokemon(&self, side: u8, index: u8) -> Option> { self.0.get_pokemon(side, index).map(|v| v.wrap()) } #[rune::function] fn set_weather(&self, weather: Option) -> anyhow::Result<()> { self.0.set_weather(weather.map(|w| w.0)) } }