Major rework of extern ref system for WASM, fixes most possible panics in WASM handling
All checks were successful
continuous-integration/drone Build is passing
All checks were successful
continuous-integration/drone Build is passing
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use crate::static_data::EffectParameter;
|
||||
use crate::{StringKey, ValueIdentifiable, ValueIdentifier};
|
||||
use std::fmt::Debug;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// An ability is a passive effect in battle that is attached to a Pokemon.
|
||||
pub trait Ability: Debug + ValueIdentifiable {
|
||||
@@ -9,7 +10,7 @@ pub trait Ability: Debug + ValueIdentifiable {
|
||||
/// 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<EffectParameter>;
|
||||
fn parameters(&self) -> &Vec<Arc<EffectParameter>>;
|
||||
}
|
||||
|
||||
/// An ability is a passive effect in battle that is attached to a Pokemon.
|
||||
@@ -22,12 +23,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<EffectParameter>,
|
||||
parameters: Vec<Arc<EffectParameter>>,
|
||||
}
|
||||
|
||||
impl AbilityImpl {
|
||||
/// Instantiates a new ability.
|
||||
pub fn new(name: &StringKey, effect: &StringKey, parameters: Vec<EffectParameter>) -> Self {
|
||||
pub fn new(name: &StringKey, effect: &StringKey, parameters: Vec<Arc<EffectParameter>>) -> Self {
|
||||
Self {
|
||||
identifier: Default::default(),
|
||||
name: name.clone(),
|
||||
@@ -47,7 +48,7 @@ impl Ability for AbilityImpl {
|
||||
&self.effect
|
||||
}
|
||||
/// The parameters for the script effect of the ability.
|
||||
fn parameters(&self) -> &Vec<EffectParameter> {
|
||||
fn parameters(&self) -> &Vec<Arc<EffectParameter>> {
|
||||
&self.parameters
|
||||
}
|
||||
}
|
||||
@@ -81,7 +82,7 @@ pub(crate) mod tests {
|
||||
impl Ability for Ability {
|
||||
fn name(&self) -> &StringKey;
|
||||
fn effect(&self) -> &StringKey;
|
||||
fn parameters(&self) -> &Vec<EffectParameter>;
|
||||
fn parameters(&self) -> &Vec<Arc<EffectParameter>>;
|
||||
}
|
||||
impl ValueIdentifiable for Ability {
|
||||
fn value_identifier(&self) -> ValueIdentifier {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use anyhow_ext::{ensure, Result};
|
||||
use hashbrown::HashSet;
|
||||
use std::fmt::Debug;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::static_data::Statistic;
|
||||
use crate::static_data::TypeIdentifier;
|
||||
@@ -23,7 +24,7 @@ pub trait Form: ValueIdentifiable + Debug {
|
||||
/// The normal types a Pokemon with this form has.
|
||||
fn types(&self) -> &Vec<TypeIdentifier>;
|
||||
/// The inherent values of a form of species that are used for the stats of a Pokemon.
|
||||
fn base_stats(&self) -> &StaticStatisticSet<u16>;
|
||||
fn base_stats(&self) -> &Arc<StaticStatisticSet<u16>>;
|
||||
/// The possible abilities a Pokemon with this form can have.
|
||||
fn abilities(&self) -> &Vec<StringKey>;
|
||||
/// The possible hidden abilities a Pokemon with this form can have.
|
||||
@@ -74,7 +75,7 @@ pub struct FormImpl {
|
||||
/// The normal types a Pokemon with this form has.
|
||||
types: Vec<TypeIdentifier>,
|
||||
/// The inherent values of a form of species that are used for the stats of a Pokemon.
|
||||
base_stats: StaticStatisticSet<u16>,
|
||||
base_stats: Arc<StaticStatisticSet<u16>>,
|
||||
/// The possible abilities a Pokemon with this form can have.
|
||||
abilities: Vec<StringKey>,
|
||||
/// The possible hidden abilities a Pokemon with this form can have.
|
||||
@@ -106,7 +107,7 @@ impl FormImpl {
|
||||
weight,
|
||||
base_experience,
|
||||
types,
|
||||
base_stats,
|
||||
base_stats: Arc::new(base_stats),
|
||||
abilities,
|
||||
hidden_abilities,
|
||||
moves,
|
||||
@@ -137,7 +138,7 @@ impl Form for FormImpl {
|
||||
&self.types
|
||||
}
|
||||
/// The inherent values of a form of species that are used for the stats of a Pokemon.
|
||||
fn base_stats(&self) -> &StaticStatisticSet<u16> {
|
||||
fn base_stats(&self) -> &Arc<StaticStatisticSet<u16>> {
|
||||
&self.base_stats
|
||||
}
|
||||
/// The possible abilities a Pokemon with this form can have.
|
||||
@@ -242,7 +243,7 @@ pub(crate) mod tests {
|
||||
fn weight(&self) -> f32;
|
||||
fn base_experience(&self) -> u32;
|
||||
fn types(&self) -> &Vec<TypeIdentifier>;
|
||||
fn base_stats(&self) -> &StaticStatisticSet<u16>;
|
||||
fn base_stats(&self) -> &Arc<StaticStatisticSet<u16>>;
|
||||
fn abilities(&self) -> &Vec<StringKey>;
|
||||
fn hidden_abilities(&self) -> &Vec<StringKey>;
|
||||
fn moves(&self) -> &Box<dyn LearnableMoves>;
|
||||
|
||||
Reference in New Issue
Block a user