Initial work on rune as scripting library
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2024-04-07 18:55:41 +02:00
parent 6379abf446
commit 67b0abe59f
24 changed files with 1186 additions and 739 deletions

View File

@@ -1,5 +1,6 @@
use crate::static_data::Parameter;
use crate::StringKey;
use hashbrown::HashMap;
use std::fmt::Debug;
use std::sync::Arc;
@@ -10,7 +11,7 @@ pub trait SecondaryEffect: Debug {
/// The name of the effect.
fn effect_name(&self) -> &StringKey;
/// A list of parameters for the effect.
fn parameters(&self) -> &Vec<Arc<Parameter>>;
fn parameters(&self) -> &HashMap<StringKey, Arc<Parameter>>;
}
/// A secondary effect is an effect on a move that happens after it hits.
@@ -21,12 +22,12 @@ pub struct SecondaryEffectImpl {
/// The name of the effect.
effect_name: StringKey,
/// A list of parameters for the effect.
parameters: Vec<Arc<Parameter>>,
parameters: HashMap<StringKey, Arc<Parameter>>,
}
impl SecondaryEffectImpl {
/// Instantiates a new Secondary Effect.
pub fn new(chance: f32, effect_name: StringKey, parameters: Vec<Arc<Parameter>>) -> Self {
pub fn new(chance: f32, effect_name: StringKey, parameters: HashMap<StringKey, Arc<Parameter>>) -> Self {
Self {
chance,
effect_name,
@@ -45,7 +46,7 @@ impl SecondaryEffect for SecondaryEffectImpl {
&self.effect_name
}
/// A list of parameters for the effect.
fn parameters(&self) -> &Vec<Arc<Parameter>> {
fn parameters(&self) -> &HashMap<StringKey, Arc<Parameter>> {
&self.parameters
}
}

View File

@@ -1,5 +1,6 @@
use crate::static_data::Parameter;
use crate::StringKey;
use hashbrown::HashMap;
use std::fmt::Debug;
use std::sync::Arc;
@@ -10,7 +11,7 @@ pub trait Ability: Debug {
/// The name of the script effect of the ability.
fn effect(&self) -> &StringKey;
/// The parameters for the script effect of the ability.
fn parameters(&self) -> &Vec<Arc<Parameter>>;
fn parameters(&self) -> &HashMap<StringKey, Arc<Parameter>>;
}
/// An ability is a passive effect in battle that is attached to a Pokemon.
@@ -21,12 +22,12 @@ pub struct AbilityImpl {
/// The name of the script effect of the ability.
effect: StringKey,
/// The parameters for the script effect of the ability.
parameters: Vec<Arc<Parameter>>,
parameters: HashMap<StringKey, Arc<Parameter>>,
}
impl AbilityImpl {
/// Instantiates a new ability.
pub fn new(name: &StringKey, effect: &StringKey, parameters: Vec<Arc<Parameter>>) -> Self {
pub fn new(name: &StringKey, effect: &StringKey, parameters: HashMap<StringKey, Arc<Parameter>>) -> Self {
Self {
name: name.clone(),
effect: effect.clone(),
@@ -37,17 +38,11 @@ impl AbilityImpl {
impl Ability for AbilityImpl {
/// The name of the ability.
fn name(&self) -> &StringKey {
&self.name
}
fn name(&self) -> &StringKey { &self.name }
/// The name of the script effect of the ability.
fn effect(&self) -> &StringKey {
&self.effect
}
fn effect(&self) -> &StringKey { &self.effect }
/// The parameters for the script effect of the ability.
fn parameters(&self) -> &Vec<Arc<Parameter>> {
&self.parameters
}
fn parameters(&self) -> &HashMap<StringKey, Arc<Parameter>> { &self.parameters }
}
/// An ability index allows us to find an ability on a form. It combines a bool for whether the