Large amounts of work on Rune
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2024-05-08 15:46:09 +02:00
parent 4bc76b0ee4
commit 4ec07ca049
43 changed files with 979 additions and 397 deletions

View File

@@ -0,0 +1,34 @@
use crate::script_implementations::rune::wrappers::{impl_rune_wrapper, RuneStringKey, RuneWrapper};
use crate::static_data::Ability;
use rune::runtime::{AnyObj, Shared};
use rune::Any;
use std::sync::Arc;
pub fn register(module: &mut rune::Module) -> anyhow::Result<()> {
module.ty::<RuneAbility>()?;
module.function_meta(RuneAbility::name)?;
module.function_meta(RuneAbility::effect)?;
module.function_meta(RuneAbility::get_parameter)?;
Ok(())
}
#[derive(Debug, Any)]
pub struct RuneAbility(Arc<dyn Ability>);
impl_rune_wrapper!(&Arc<dyn Ability>, RuneAbility);
impl RuneAbility {
#[rune::function]
fn name(&self) -> Shared<AnyObj> { self.0.name().wrap() }
#[rune::function]
fn effect(&self) -> Shared<AnyObj> { self.0.effect().wrap() }
#[rune::function(vm_result)]
fn get_parameter(&self, key: RuneStringKey) -> Option<Shared<AnyObj>> {
match self.0.parameters().get(&key.0) {
None => None,
Some(p) => Some(p.wrap()),
}
}
}

View File

@@ -0,0 +1,67 @@
use crate::script_implementations::rune::wrappers::{impl_rune_wrapper, RuneStringKey, RuneWrapper};
use crate::static_data::{AbilityIndex, Form, Statistic};
use rune::runtime::{AnyObj, Shared};
use rune::Any;
use std::sync::Arc;
pub fn register(module: &mut rune::Module) -> anyhow::Result<()> {
module.ty::<RuneForm>()?;
module.function_meta(RuneForm::name)?;
module.function_meta(RuneForm::height)?;
module.function_meta(RuneForm::weight)?;
module.function_meta(RuneForm::base_experience)?;
module.function_meta(RuneForm::types)?;
module.function_meta(RuneForm::base_stats)?;
module.function_meta(RuneForm::abilities)?;
module.function_meta(RuneForm::hidden_abilities)?;
module.function_meta(RuneForm::has_flag)?;
module.function_meta(RuneForm::get_type)?;
module.function_meta(RuneForm::get_base_stat)?;
module.function_meta(RuneForm::get_ability)?;
Ok(())
}
#[derive(Debug, Any)]
pub struct RuneForm(Arc<dyn Form>);
impl_rune_wrapper!(&Arc<dyn Form>, RuneForm);
impl RuneForm {
#[rune::function]
fn name(&self) -> Shared<AnyObj> { self.0.name().wrap() }
#[rune::function]
fn height(&self) -> f32 { self.0.height() }
#[rune::function]
fn weight(&self) -> f32 { self.0.weight() }
#[rune::function]
fn base_experience(&self) -> u32 { self.0.base_experience() }
#[rune::function]
fn types(&self) -> Vec<u8> { self.0.types().iter().map(|t| u8::from(*t)).collect() }
#[rune::function]
fn base_stats(&self) -> Shared<AnyObj> { self.0.base_stats().wrap() }
#[rune::function]
fn abilities(&self) -> Vec<Shared<AnyObj>> { self.0.abilities().iter().map(|a| a.wrap()).collect() }
#[rune::function]
fn hidden_abilities(&self) -> Vec<Shared<AnyObj>> { self.0.hidden_abilities().iter().map(|a| a.wrap()).collect() }
#[rune::function]
fn has_flag(&self, key: &RuneStringKey) -> bool { self.0.has_flag(&key.0) }
#[rune::function]
fn get_type(&self, index: usize) -> anyhow::Result<u8> { self.0.get_type(index).map(|t| u8::from(t)) }
#[rune::function]
fn get_base_stat(&self, statistic: Statistic) -> u16 { self.0.get_base_stat(statistic) }
#[rune::function]
fn get_ability(&self, hidden: bool, index: u8) -> anyhow::Result<Shared<AnyObj>> {
self.0.get_ability(AbilityIndex { hidden, index }).map(|a| a.wrap())
}
}

View File

@@ -0,0 +1,27 @@
use crate::defines::LevelInt;
use crate::script_implementations::rune::wrappers::impl_rune_wrapper;
use crate::static_data::GrowthRate;
use rune::Any;
use std::sync::Arc;
pub fn register(module: &mut rune::Module) -> anyhow::Result<()> {
module.ty::<RuneGrowthRate>()?;
module.function_meta(RuneGrowthRate::calculate_level)?;
module.function_meta(RuneGrowthRate::calculate_experience)?;
Ok(())
}
#[derive(Debug, Any)]
pub struct RuneGrowthRate(Arc<dyn GrowthRate>);
impl_rune_wrapper!(&Arc<dyn GrowthRate>, RuneGrowthRate);
impl RuneGrowthRate {
#[rune::function]
fn calculate_level(&self, experience: u32) -> i32 { self.0.calculate_level(experience) as i32 }
#[rune::function]
fn calculate_experience(&self, level: LevelInt) -> Result<u32, String> {
self.0.calculate_experience(level).map_err(|e| e.to_string())
}
}

View File

@@ -0,0 +1,47 @@
use std::sync::Arc;
use rune::runtime::{AnyObj, Shared};
use rune::Any;
use crate::script_implementations::rune::wrappers::{impl_rune_wrapper, RuneStringKey, RuneWrapper};
use crate::static_data::{BattleItemCategory, Item, ItemCategory};
pub fn register(module: &mut rune::Module) -> anyhow::Result<()> {
module.ty::<ItemCategory>()?;
module.ty::<BattleItemCategory>()?;
module.ty::<RuneItem>()?;
module.function_meta(RuneItem::name)?;
module.function_meta(RuneItem::category)?;
module.function_meta(RuneItem::battle_category)?;
module.function_meta(RuneItem::price)?;
module.function_meta(RuneItem::flags)?;
module.function_meta(RuneItem::has_flag)?;
Ok(())
}
#[derive(Debug, Any)]
pub struct RuneItem(Arc<dyn Item>);
impl_rune_wrapper!(&Arc<dyn Item>, RuneItem);
impl RuneItem {
#[rune::function]
fn name(&self) -> Shared<AnyObj> { self.0.name().clone().wrap() }
#[rune::function]
fn category(&self) -> ItemCategory { self.0.category() }
#[rune::function]
fn battle_category(&self) -> BattleItemCategory { self.0.battle_category() }
#[rune::function]
fn price(&self) -> i32 { self.0.price() }
#[rune::function]
fn flags(&self) -> Vec<Shared<AnyObj>> { self.0.flags().iter().map(|s| s.clone().wrap()).collect() }
#[rune::function]
fn has_flag(&self, key: &RuneStringKey) -> bool { self.0.has_flag(&key.0) }
}

View File

@@ -0,0 +1,40 @@
use crate::defines::LevelInt;
use crate::script_implementations::rune::wrappers::{impl_rune_wrapper, RuneStringKey, RuneWrapper};
use crate::static_data::LearnableMoves;
use rune::runtime::{AnyObj, Shared};
use rune::Any;
use std::sync::Arc;
pub fn register(module: &mut rune::Module) -> anyhow::Result<()> {
module.ty::<RuneLearnableMoves>()?;
module.function_meta(RuneLearnableMoves::get_learned_by_level)?;
module.function_meta(RuneLearnableMoves::get_distinct_level_moves)?;
module.function_meta(RuneLearnableMoves::learns_move)?;
Ok(())
}
#[derive(Debug, Any)]
pub struct RuneLearnableMoves(Arc<dyn LearnableMoves>);
impl_rune_wrapper!(&Arc<dyn LearnableMoves>, RuneLearnableMoves);
impl RuneLearnableMoves {
#[rune::function]
fn get_learned_by_level(&self, level: LevelInt) -> Option<Vec<Shared<AnyObj>>> {
self.0
.get_learned_by_level(level)
.map(|v| v.into_iter().map(|s| s.wrap()).collect())
}
#[rune::function]
fn get_distinct_level_moves(&self) -> Vec<Shared<AnyObj>> {
self.0
.get_distinct_level_moves()
.into_iter()
.map(|s| s.wrap())
.collect()
}
#[rune::function]
fn learns_move(&self, moveName: &RuneStringKey) -> bool { self.0.get_distinct_level_moves().contains(&moveName.0) }
}

View File

@@ -0,0 +1,29 @@
use crate::defines::LevelInt;
use crate::script_implementations::rune::wrappers::{impl_rune_wrapper, RuneStringKey};
use crate::static_data::GrowthRateLibrary;
use std::sync::Arc;
pub fn register(module: &mut rune::Module) -> anyhow::Result<()> {
module.ty::<RuneGrowthRateLibrary>()?;
module.function_meta(RuneGrowthRateLibrary::calculate_level)?;
module.function_meta(RuneGrowthRateLibrary::calculate_experience)?;
Ok(())
}
#[derive(Debug, rune::Any)]
struct RuneGrowthRateLibrary(Arc<dyn GrowthRateLibrary>);
impl_rune_wrapper!(&Arc<dyn GrowthRateLibrary>, RuneGrowthRateLibrary);
impl RuneGrowthRateLibrary {
#[rune::function]
fn calculate_level(&self, growth_rate: &RuneStringKey, experience: u32) -> anyhow::Result<LevelInt> {
self.0.calculate_level(&growth_rate.0, experience)
}
#[rune::function]
fn calculate_experience(&self, growth_rate: &RuneStringKey, level: LevelInt) -> anyhow::Result<u32> {
self.0.calculate_experience(&growth_rate.0, level)
}
}

View File

@@ -0,0 +1,23 @@
use crate::script_implementations::rune::wrappers::impl_rune_wrapper;
use crate::static_data::LibrarySettings;
use std::sync::Arc;
pub fn register(module: &mut rune::Module) -> anyhow::Result<()> {
module.ty::<RuneLibrarySettings>()?;
module.function_meta(RuneLibrarySettings::maximum_level)?;
module.function_meta(RuneLibrarySettings::shiny_rate)?;
Ok(())
}
#[derive(Debug, rune::Any)]
struct RuneLibrarySettings(Arc<dyn LibrarySettings>);
impl_rune_wrapper!(&Arc<dyn LibrarySettings>, RuneLibrarySettings);
impl RuneLibrarySettings {
#[rune::function]
fn maximum_level(&self) -> i64 { self.0.maximum_level() as i64 }
#[rune::function]
fn shiny_rate(&self) -> i64 { self.0.shiny_rate() as i64 }
}

View File

@@ -0,0 +1,68 @@
mod growth_rate_library;
mod library_settings;
mod nature_library;
mod static_data;
mod type_library;
use crate::script_implementations::rune::wrappers::{impl_rune_wrapper, RuneStringKey, RuneWrapper};
use crate::static_data::{AbilityLibrary, ItemLibrary, MoveLibrary, SpeciesLibrary};
use rune::runtime::{AnyObj, Shared};
use std::sync::Arc;
pub fn register(module: &mut rune::Module) -> anyhow::Result<()> {
module.ty::<RuneAbilityLibrary>()?;
module.function_meta(RuneAbilityLibrary::get)?;
module.function_meta(RuneAbilityLibrary::len)?;
module.function_meta(RuneAbilityLibrary::get_key_by_index)?;
module.ty::<RuneItemLibrary>()?;
module.function_meta(RuneItemLibrary::get)?;
module.function_meta(RuneItemLibrary::len)?;
module.function_meta(RuneItemLibrary::get_key_by_index)?;
module.ty::<RuneMoveLibrary>()?;
module.function_meta(RuneMoveLibrary::get)?;
module.function_meta(RuneMoveLibrary::len)?;
module.function_meta(RuneMoveLibrary::get_key_by_index)?;
module.ty::<RuneSpeciesLibrary>()?;
module.function_meta(RuneSpeciesLibrary::get)?;
module.function_meta(RuneSpeciesLibrary::len)?;
module.function_meta(RuneSpeciesLibrary::get_key_by_index)?;
growth_rate_library::register(module)?;
library_settings::register(module)?;
nature_library::register(module)?;
type_library::register(module)?;
static_data::register(module)?;
Ok(())
}
macro_rules! impl_rune_data_library_wrapper {
($t:ident, $wrapped_type:ty) => {
#[derive(Debug, rune::Any)]
struct $t($wrapped_type);
impl_rune_wrapper!(&$wrapped_type, $t);
impl $t {
#[rune::function]
fn get(&self, key: &RuneStringKey) -> Option<Shared<AnyObj>> { self.0.get(&key.0).map(|v| v.wrap()) }
#[rune::function]
fn len(&self) -> usize { self.0.len() }
#[rune::function]
fn get_key_by_index(&self, index: usize) -> Option<Shared<AnyObj>> {
self.0.get_key_by_index(index).map(|v| v.wrap())
}
}
};
}
impl_rune_data_library_wrapper!(RuneAbilityLibrary, Arc<dyn AbilityLibrary>);
impl_rune_data_library_wrapper!(RuneItemLibrary, Arc<dyn ItemLibrary>);
impl_rune_data_library_wrapper!(RuneMoveLibrary, Arc<dyn MoveLibrary>);
impl_rune_data_library_wrapper!(RuneSpeciesLibrary, Arc<dyn SpeciesLibrary>);

View File

@@ -0,0 +1,27 @@
use crate::script_implementations::rune::wrappers::static_data::nature::RuneNature;
use crate::script_implementations::rune::wrappers::{impl_rune_wrapper, RuneStringKey, RuneWrapper};
use crate::static_data::NatureLibrary;
use rune::runtime::{AnyObj, Shared};
use std::sync::Arc;
pub fn register(module: &mut rune::Module) -> anyhow::Result<()> {
module.ty::<RuneNatureLibrary>()?;
module.function_meta(RuneNatureLibrary::get_nature)?;
module.function_meta(RuneNatureLibrary::get_nature_name)?;
Ok(())
}
#[derive(Debug, rune::Any)]
struct RuneNatureLibrary(Arc<dyn NatureLibrary>);
impl_rune_wrapper!(&Arc<dyn NatureLibrary>, RuneNatureLibrary);
impl RuneNatureLibrary {
#[rune::function]
fn get_nature(&self, key: RuneStringKey) -> Option<Shared<AnyObj>> { self.0.get_nature(&key.0).map(|v| v.wrap()) }
#[rune::function]
fn get_nature_name(&self, nature: &RuneNature) -> RuneStringKey {
RuneStringKey(self.0.get_nature_name(&nature.0).unwrap())
}
}

View File

@@ -0,0 +1,48 @@
use crate::script_implementations::rune::wrappers::{impl_rune_wrapper, RuneWrapper};
use crate::static_data::StaticData;
use rune::runtime::{AnyObj, Shared};
use std::sync::Arc;
pub fn register(module: &mut rune::Module) -> anyhow::Result<()> {
module.ty::<RuneStaticData>()?;
module.function_meta(RuneStaticData::settings)?;
module.function_meta(RuneStaticData::species)?;
module.function_meta(RuneStaticData::moves)?;
module.function_meta(RuneStaticData::items)?;
module.function_meta(RuneStaticData::growth_rates)?;
module.function_meta(RuneStaticData::types)?;
module.function_meta(RuneStaticData::natures)?;
module.function_meta(RuneStaticData::abilities)?;
Ok(())
}
#[derive(Debug, rune::Any)]
struct RuneStaticData(Arc<dyn StaticData>);
impl_rune_wrapper!(&Arc<dyn StaticData>, RuneStaticData);
impl RuneStaticData {
#[rune::function]
fn settings(&self) -> Shared<AnyObj> { self.0.settings().wrap() }
#[rune::function]
fn species(&self) -> Shared<AnyObj> { self.0.species().wrap() }
#[rune::function]
fn moves(&self) -> Shared<AnyObj> { self.0.moves().wrap() }
#[rune::function]
fn items(&self) -> Shared<AnyObj> { self.0.items().wrap() }
#[rune::function]
fn growth_rates(&self) -> Shared<AnyObj> { self.0.growth_rates().wrap() }
#[rune::function]
fn types(&self) -> Shared<AnyObj> { self.0.types().wrap() }
#[rune::function]
fn natures(&self) -> Shared<AnyObj> { self.0.natures().wrap() }
#[rune::function]
fn abilities(&self) -> Shared<AnyObj> { self.0.abilities().wrap() }
}

View File

@@ -0,0 +1,39 @@
use crate::script_implementations::rune::wrappers::{impl_rune_wrapper, RuneStringKey, RuneWrapper};
use crate::static_data::TypeLibrary;
use rune::runtime::{AnyObj, Shared};
use std::sync::Arc;
pub fn register(module: &mut rune::Module) -> anyhow::Result<()> {
module.ty::<RuneTypeLibrary>()?;
module.function_meta(RuneTypeLibrary::get_type_id)?;
module.function_meta(RuneTypeLibrary::get_type_name)?;
module.function_meta(RuneTypeLibrary::get_single_effectiveness)?;
module.function_meta(RuneTypeLibrary::get_effectiveness)?;
Ok(())
}
#[derive(Debug, rune::Any)]
struct RuneTypeLibrary(Arc<dyn TypeLibrary>);
impl_rune_wrapper!(&Arc<dyn TypeLibrary>, RuneTypeLibrary);
impl RuneTypeLibrary {
#[rune::function]
fn get_type_id(&self, key: &RuneStringKey) -> Option<u8> { self.0.get_type_id(&key.0).map(|v| v.into()) }
#[rune::function]
fn get_type_name(&self, t: u8) -> Option<Shared<AnyObj>> { self.0.get_type_name(t.into()).map(|v| v.wrap()) }
#[rune::function]
fn get_single_effectiveness(&self, attacking: u8, defending: u8) -> anyhow::Result<f32> {
self.0.get_single_effectiveness(attacking.into(), defending.into())
}
#[rune::function]
fn get_effectiveness(&self, attacking: u8, defending: &[u8]) -> anyhow::Result<f32> {
self.0.get_effectiveness(
attacking.into(),
&defending.iter().map(|v| (*v).into()).collect::<Vec<_>>(),
)
}
}

View File

@@ -1,12 +1,30 @@
mod ability;
mod form;
mod growth_rate;
mod item;
mod learnable_moves;
mod libraries;
mod move_data;
mod nature;
mod species;
mod statistic_set;
use crate::static_data::{Statistic, TimeOfDay};
use crate::static_data::{Gender, Statistic, TimeOfDay};
pub fn register(module: &mut rune::Module) -> anyhow::Result<()> {
module.ty::<TimeOfDay>()?;
module.ty::<Statistic>()?;
module.ty::<Gender>()?;
statistic_set::register(module)?;
nature::register(module)?;
item::register(module)?;
growth_rate::register(module)?;
form::register(module)?;
ability::register(module)?;
learnable_moves::register(module)?;
species::register(module)?;
move_data::register(module)?;
libraries::register(module)?;
Ok(())
}

View File

@@ -0,0 +1,89 @@
use crate::script_implementations::rune::wrappers::{impl_rune_wrapper, RuneStringKey, RuneWrapper};
use crate::static_data::{MoveCategory, MoveData, MoveTarget, SecondaryEffect};
use rune::runtime::{AnyObj, Object, Shared};
use rune::{Any, Value};
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) -> Shared<AnyObj> { 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<Shared<AnyObj>> { 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) -> Shared<AnyObj> { 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)
}
}

View File

@@ -5,27 +5,32 @@ use std::sync::Arc;
pub fn register(module: &mut rune::Module) -> anyhow::Result<()> {
module.ty::<RuneNature>()?;
module.function_meta(RuneNature::increased_stat)?;
module.function_meta(RuneNature::decreased_stat)?;
module.function_meta(RuneNature::increased_modifier)?;
module.function_meta(RuneNature::decreased_modifier)?;
module.function_meta(RuneNature::get_stat_modifier)?;
Ok(())
}
#[derive(Debug, Any)]
pub struct RuneNature(Arc<dyn Nature>);
pub struct RuneNature(pub Arc<dyn Nature>);
impl_rune_wrapper!(&Arc<dyn Nature>, RuneNature);
impl RuneNature {
#[rune::function]
pub fn increased_stat(&self) -> Statistic { self.0.increased_stat() }
fn increased_stat(&self) -> Statistic { self.0.increased_stat() }
#[rune::function]
pub fn decreased_stat(&self) -> Statistic { self.0.decreased_stat() }
fn decreased_stat(&self) -> Statistic { self.0.decreased_stat() }
#[rune::function]
pub fn increased_modifier(&self) -> f32 { self.0.increased_modifier() }
fn increased_modifier(&self) -> f32 { self.0.increased_modifier() }
#[rune::function]
pub fn decreased_modifier(&self) -> f32 { self.0.decreased_modifier() }
fn decreased_modifier(&self) -> f32 { self.0.decreased_modifier() }
#[rune::function]
pub fn get_stat_modifier(&self, stat: Statistic) -> f32 { self.0.get_stat_modifier(stat) }
fn get_stat_modifier(&self, stat: Statistic) -> f32 { self.0.get_stat_modifier(stat) }
}

View File

@@ -0,0 +1,56 @@
use crate::script_implementations::rune::wrappers::{impl_rune_wrapper, RuneStringKey, RuneWrapper};
use crate::static_data::Species;
use rune::runtime::{AnyObj, Shared};
use rune::Any;
use std::sync::Arc;
pub fn register(module: &mut rune::Module) -> anyhow::Result<()> {
module.ty::<RuneSpecies>()?;
module.function_meta(RuneSpecies::id)?;
module.function_meta(RuneSpecies::name)?;
module.function_meta(RuneSpecies::gender_rate)?;
module.function_meta(RuneSpecies::growth_rate)?;
module.function_meta(RuneSpecies::capture_rate)?;
module.function_meta(RuneSpecies::base_happiness)?;
module.function_meta(RuneSpecies::get_form)?;
module.function_meta(RuneSpecies::get_default_form)?;
module.function_meta(RuneSpecies::has_flag)?;
Ok(())
}
#[derive(Debug, Any)]
pub struct RuneSpecies(Arc<dyn Species>);
impl_rune_wrapper!(&Arc<dyn Species>, RuneSpecies);
impl RuneSpecies {
#[rune::function]
fn id(&self) -> u16 { self.0.id() }
#[rune::function]
fn name(&self) -> Shared<AnyObj> { self.0.name().wrap() }
#[rune::function]
fn gender_rate(&self) -> f32 { self.0.gender_rate() }
#[rune::function]
fn growth_rate(&self) -> Shared<AnyObj> { self.0.growth_rate().wrap() }
#[rune::function]
fn capture_rate(&self) -> u8 { self.0.capture_rate() }
#[rune::function]
fn base_happiness(&self) -> u8 { self.0.base_happiness() }
#[rune::function]
fn get_form(&self, name: &RuneStringKey) -> Option<Shared<AnyObj>> {
self.0.get_form(&name.0).map(|form| form.wrap())
}
#[rune::function]
fn get_default_form(&self) -> anyhow::Result<Shared<AnyObj>> { self.0.get_default_form().map(|v| v.wrap()) }
#[rune::function]
fn has_flag(&self, key: &RuneStringKey) -> bool { self.0.has_flag(&key.0) }
}

View File

@@ -5,7 +5,24 @@ use std::sync::Arc;
pub fn register(module: &mut rune::Module) -> anyhow::Result<()> {
module.ty::<RuneStatisticSet>()?;
module.function_meta(RuneStatisticSet::get)?;
module.function_meta(RuneStatisticSet::set)?;
module.function_meta(RuneStatisticSet::hp)?;
module.function_meta(RuneStatisticSet::attack)?;
module.function_meta(RuneStatisticSet::defense)?;
module.function_meta(RuneStatisticSet::special_attack)?;
module.function_meta(RuneStatisticSet::special_defense)?;
module.function_meta(RuneStatisticSet::speed)?;
module.ty::<RuneStaticStatisticSet>()?;
module.function_meta(RuneStaticStatisticSet::get)?;
module.function_meta(RuneStaticStatisticSet::hp)?;
module.function_meta(RuneStaticStatisticSet::attack)?;
module.function_meta(RuneStaticStatisticSet::defense)?;
module.function_meta(RuneStaticStatisticSet::special_attack)?;
module.function_meta(RuneStaticStatisticSet::special_defense)?;
module.function_meta(RuneStaticStatisticSet::speed)?;
Ok(())
}
@@ -15,28 +32,28 @@ pub struct RuneStatisticSet(Arc<StatisticSet<u32>>);
impl_rune_wrapper!(&Arc<StatisticSet<u32>>, RuneStatisticSet);
impl RuneStatisticSet {
#[rune::function]
pub fn get(&self, stat: Statistic) -> u32 { self.0.get_stat(stat) }
fn get(&self, stat: Statistic) -> u32 { self.0.get_stat(stat) }
#[rune::function]
pub fn set(&mut self, stat: Statistic, value: u32) { self.0.set_stat(stat, value) }
fn set(&mut self, stat: Statistic, value: u32) { self.0.set_stat(stat, value) }
#[rune::function]
pub fn hp(&self) -> u32 { self.0.hp() }
fn hp(&self) -> u32 { self.0.hp() }
#[rune::function]
pub fn attack(&self) -> u32 { self.0.attack() }
fn attack(&self) -> u32 { self.0.attack() }
#[rune::function]
pub fn defense(&self) -> u32 { self.0.defense() }
fn defense(&self) -> u32 { self.0.defense() }
#[rune::function]
pub fn special_attack(&self) -> u32 { self.0.special_attack() }
fn special_attack(&self) -> u32 { self.0.special_attack() }
#[rune::function]
pub fn special_defense(&self) -> u32 { self.0.special_defense() }
fn special_defense(&self) -> u32 { self.0.special_defense() }
#[rune::function]
pub fn speed(&self) -> u32 { self.0.speed() }
fn speed(&self) -> u32 { self.0.speed() }
}
#[derive(Debug, Any)]
@@ -46,22 +63,22 @@ impl_rune_wrapper!(&Arc<StaticStatisticSet<u16>>, RuneStaticStatisticSet);
impl RuneStaticStatisticSet {
#[rune::function]
pub fn get(&self, stat: Statistic) -> u16 { self.0.get_stat(stat) }
fn get(&self, stat: Statistic) -> u16 { self.0.get_stat(stat) }
#[rune::function]
pub fn hp(&self) -> u16 { self.0.hp() }
fn hp(&self) -> u16 { self.0.hp() }
#[rune::function]
pub fn attack(&self) -> u16 { self.0.attack() }
fn attack(&self) -> u16 { self.0.attack() }
#[rune::function]
pub fn defense(&self) -> u16 { self.0.defense() }
fn defense(&self) -> u16 { self.0.defense() }
#[rune::function]
pub fn special_attack(&self) -> u16 { self.0.special_attack() }
fn special_attack(&self) -> u16 { self.0.special_attack() }
#[rune::function]
pub fn special_defense(&self) -> u16 { self.0.special_defense() }
fn special_defense(&self) -> u16 { self.0.special_defense() }
#[rune::function]
pub fn speed(&self) -> u16 { self.0.speed() }