90 lines
2.8 KiB
Rust
90 lines
2.8 KiB
Rust
use crate::script_implementations::rune::wrappers::{impl_rune_wrapper, RuneStringKey, RuneWrapper};
|
|
use crate::static_data::{MoveCategory, MoveData, MoveTarget, SecondaryEffect};
|
|
use rune::runtime::{Object, Value};
|
|
use rune::Any;
|
|
use std::convert::TryFrom;
|
|
use std::sync::Arc;
|
|
|
|
pub fn register(module: &mut rune::Module) -> anyhow::Result<()> {
|
|
module.ty::<MoveCategory>()?;
|
|
module.ty::<MoveTarget>()?;
|
|
module.ty::<RuneMoveData>()?;
|
|
module.function_meta(RuneMoveData::name)?;
|
|
module.function_meta(RuneMoveData::move_type)?;
|
|
module.function_meta(RuneMoveData::category)?;
|
|
module.function_meta(RuneMoveData::base_power)?;
|
|
module.function_meta(RuneMoveData::accuracy)?;
|
|
module.function_meta(RuneMoveData::base_usages)?;
|
|
module.function_meta(RuneMoveData::target)?;
|
|
module.function_meta(RuneMoveData::priority)?;
|
|
module.function_meta(RuneMoveData::secondary_effect)?;
|
|
module.function_meta(RuneMoveData::has_flag)?;
|
|
|
|
module.ty::<RuneSecondaryEffect>()?;
|
|
module.function_meta(RuneSecondaryEffect::chance)?;
|
|
module.function_meta(RuneSecondaryEffect::effect_name)?;
|
|
module.function_meta(RuneSecondaryEffect::parameters)?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[derive(Debug, Any)]
|
|
pub struct RuneMoveData(Arc<dyn MoveData>);
|
|
|
|
impl_rune_wrapper!(&Arc<dyn MoveData>, RuneMoveData);
|
|
|
|
impl RuneMoveData {
|
|
#[rune::function]
|
|
fn name(&self) -> Value { self.0.name().wrap() }
|
|
|
|
#[rune::function]
|
|
fn move_type(&self) -> u8 { u8::from(self.0.move_type()) }
|
|
|
|
#[rune::function]
|
|
fn category(&self) -> MoveCategory { self.0.category() }
|
|
|
|
#[rune::function]
|
|
fn base_power(&self) -> u8 { self.0.base_power() }
|
|
|
|
#[rune::function]
|
|
fn accuracy(&self) -> u8 { self.0.accuracy() }
|
|
|
|
#[rune::function]
|
|
fn base_usages(&self) -> u8 { self.0.base_usages() }
|
|
|
|
#[rune::function]
|
|
fn target(&self) -> MoveTarget { self.0.target() }
|
|
|
|
#[rune::function]
|
|
fn priority(&self) -> i8 { self.0.priority() }
|
|
|
|
#[rune::function]
|
|
fn secondary_effect(&self) -> Option<Value> { self.0.secondary_effect().as_ref().map(|x| x.wrap()) }
|
|
|
|
#[rune::function]
|
|
fn has_flag(&self, flag: RuneStringKey) -> bool { self.0.has_flag(&flag.0) }
|
|
}
|
|
|
|
#[derive(Debug, Any)]
|
|
pub struct RuneSecondaryEffect(Arc<dyn SecondaryEffect>);
|
|
|
|
impl_rune_wrapper!(&Arc<dyn SecondaryEffect>, RuneSecondaryEffect);
|
|
|
|
impl RuneSecondaryEffect {
|
|
#[rune::function]
|
|
fn chance(&self) -> f32 { self.0.chance() }
|
|
|
|
#[rune::function]
|
|
fn effect_name(&self) -> Value { self.0.effect_name().wrap() }
|
|
|
|
#[rune::function]
|
|
fn parameters(&self) -> anyhow::Result<Object> {
|
|
let pars = self.0.parameters();
|
|
let mut o = Object::with_capacity(pars.len())?;
|
|
for (key, value) in pars.iter() {
|
|
o.insert(rune::alloc::String::try_from(key.str())?, Value::from(value.wrap()))?;
|
|
}
|
|
Ok(o)
|
|
}
|
|
}
|