66 lines
2.1 KiB
Rust
66 lines
2.1 KiB
Rust
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::<RuneBattle>()?;
|
|
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<AnyObj> { self.0.library().wrap() }
|
|
|
|
#[rune::function]
|
|
fn parties(&self) -> Vec<Shared<AnyObj>> { 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<Shared<AnyObj>> { self.0.sides().iter().map(|s| s.wrap()).collect() }
|
|
|
|
#[rune::function]
|
|
fn random(&self) -> Shared<AnyObj> { 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<Shared<AnyObj>> {
|
|
self.0.get_pokemon(side, index).map(|v| v.wrap())
|
|
}
|
|
|
|
#[rune::function]
|
|
fn set_weather(&self, weather: Option<RuneStringKey>) -> anyhow::Result<()> {
|
|
self.0.set_weather(weather.map(|w| w.0))
|
|
}
|
|
}
|