Major fixes for WebAssembly
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-07-18 15:36:03 +02:00
parent 0961b199ff
commit 703fd2c147
11 changed files with 129 additions and 81 deletions

View File

@@ -505,7 +505,7 @@ impl<'own, 'library> Pokemon<'own, 'library> {
.set(ability_script)
.as_ref()
// Ensure the ability script gets initialized with the parameters for the ability.
.on_initialize(self.active_ability().parameters())
.on_initialize(self.library, self.active_ability().parameters())
} else {
self.ability_script.clear();
}

View File

@@ -225,6 +225,7 @@ mod tests {
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use crate::dynamic_data::script_handling::script::ScriptContainer;
use crate::dynamic_data::DynamicLibrary;
use crate::static_data::EffectParameter;
use crate::StringKey;
@@ -273,7 +274,7 @@ mod tests {
fn remove_suppression(&self) {}
fn on_initialize(&self, _pars: &[EffectParameter]) {
fn stack(&self) {
self.test_count.fetch_add(1, Ordering::SeqCst);
}
@@ -292,7 +293,7 @@ mod tests {
let scripts = vec![ScriptWrapper::from(&script)];
let mut aggregator = ScriptIterator::new(&scripts as *const Vec<ScriptWrapper>);
while let Some(v) = aggregator.get_next() {
v.get().unwrap().read().as_ref().unwrap().on_initialize(&[]);
v.get().unwrap().read().as_ref().unwrap().stack();
}
let a = script.get_as::<TestScript>();
assert_eq!(a.test_count.load(Ordering::Relaxed), 1);
@@ -306,7 +307,7 @@ mod tests {
for i in 1..11 {
aggregator.reset();
while let Some(v) = aggregator.get_next() {
v.get().unwrap().read().as_ref().unwrap().on_initialize(&[]);
v.get().unwrap().read().as_ref().unwrap().stack();
}
let a = script.get_as::<TestScript>();
assert_eq!(a.test_count.load(Ordering::Relaxed), i);
@@ -325,7 +326,7 @@ mod tests {
];
let mut aggregator = ScriptIterator::new(&scripts as *const Vec<ScriptWrapper>);
while let Some(v) = aggregator.get_next() {
v.get().unwrap().read().as_ref().unwrap().on_initialize(&[]);
v.get().unwrap().read().as_ref().unwrap().stack();
}
let a = script1.get_as::<TestScript>();
assert_eq!(a.test_count.load(Ordering::Relaxed), 1);
@@ -349,7 +350,7 @@ mod tests {
for i in 1..11 {
aggregator.reset();
while let Some(v) = aggregator.get_next() {
v.get().unwrap().read().as_ref().unwrap().on_initialize(&[]);
v.get().unwrap().read().as_ref().unwrap().stack();
}
let a = script1.get_as::<TestScript>();
assert_eq!(a.test_count.load(Ordering::Relaxed), i);
@@ -372,7 +373,7 @@ mod tests {
for i in 1..11 {
aggregator.reset();
while let Some(v) = aggregator.get_next() {
v.get().unwrap().read().as_ref().unwrap().on_initialize(&[]);
v.get().unwrap().read().as_ref().unwrap().stack();
}
let s = set.at(0);
let s = s.get_as::<TestScript>();

View File

@@ -8,10 +8,10 @@ use std::thread::JoinHandle;
use parking_lot::{MappedRwLockReadGuard, RwLock, RwLockReadGuard};
use crate::dynamic_data::choices::{MoveChoice, TurnChoice};
use crate::dynamic_data::Battle;
use crate::dynamic_data::DamageSource;
use crate::dynamic_data::ExecutingMove;
use crate::dynamic_data::Pokemon;
use crate::dynamic_data::{Battle, DynamicLibrary};
use crate::static_data::{EffectParameter, TypeIdentifier};
use crate::static_data::{Item, Statistic};
use crate::StringKey;
@@ -64,7 +64,7 @@ pub trait Script: Send + Sync {
/// This function is ran when this script stops being in effect, and is removed from its owner.
fn on_remove(&self) {}
/// This function is ran when this script starts being in effect.
fn on_initialize(&self, _pars: &[EffectParameter]) {}
fn on_initialize(&self, _library: &DynamicLibrary, _pars: &[EffectParameter]) {}
/// This function is ran just before the start of the turn. Everyone has made its choices here,
/// and the turn is about to start. This is a great place to initialize data if you need to know
/// something has happened during a turn.
@@ -423,7 +423,7 @@ mod tests {
&self.suppressed_count
}
fn on_initialize(&self, _pars: &[EffectParameter]) {
fn stack(&self) {
unsafe { self.container.load(Ordering::Relaxed).as_ref().unwrap().clear() }
}
@@ -451,7 +451,7 @@ mod tests {
drop(w);
// Initialize with the script being taken as read lock. This prevents the script from actually
// removing itself, as it's still doing things.
container.script.read().as_ref().unwrap().on_initialize(&[]);
container.script.read().as_ref().unwrap().stack();
// If we now try and get the script, it will be none the first time. This has the side effect
// of actually disposing of the script.
assert!(container.get().is_none());