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

This commit is contained in:
2023-06-22 15:43:41 +02:00
parent 6a2353df4c
commit 46195d3042
71 changed files with 2142 additions and 1488 deletions

View File

@@ -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>;