A lot more work on WASM script execution
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
5
src/dynamic_data/models/battle.rs
Normal file → Executable file
5
src/dynamic_data/models/battle.rs
Normal file → Executable file
@@ -194,7 +194,7 @@ impl Battle {
|
||||
let mut winning_side = None;
|
||||
for (side_index, side) in self.sides.iter().enumerate() {
|
||||
// If any side has fled, the battle end.
|
||||
if side.has_fled() {
|
||||
if side.has_fled_battle() {
|
||||
let _w = self.result.write();
|
||||
unsafe {
|
||||
self.result.data_ptr().replace(BattleResult::Inconclusive);
|
||||
@@ -339,8 +339,7 @@ impl VolatileScriptsOwner for Battle {
|
||||
}
|
||||
|
||||
fn load_volatile_script(&self, key: &StringKey) -> PkmnResult<Option<Arc<dyn Script>>> {
|
||||
self.library
|
||||
.load_script((self as *const Self).cast(), ScriptCategory::Battle, key)
|
||||
self.library.load_script(self.into(), ScriptCategory::Battle, key)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
6
src/dynamic_data/models/battle_party.rs
Normal file → Executable file
6
src/dynamic_data/models/battle_party.rs
Normal file → Executable file
@@ -6,6 +6,7 @@ use crate::dynamic_data::models::pokemon_party::PokemonParty;
|
||||
/// A battle party is a wrapper around a party, with the indices for which the party is responsible
|
||||
/// on the field attached.
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
|
||||
pub struct BattleParty {
|
||||
/// The party the BattleParty is holding.
|
||||
party: Arc<PokemonParty>,
|
||||
@@ -47,4 +48,9 @@ impl BattleParty {
|
||||
pub fn get_pokemon(&self, index: usize) -> &Option<Arc<Pokemon>> {
|
||||
self.party.at(index)
|
||||
}
|
||||
|
||||
/// Gets the underlying Pokemon Party
|
||||
pub fn party(&self) -> &Arc<PokemonParty> {
|
||||
&self.party
|
||||
}
|
||||
}
|
||||
|
||||
1
src/dynamic_data/models/battle_random.rs
Normal file → Executable file
1
src/dynamic_data/models/battle_random.rs
Normal file → Executable file
@@ -9,6 +9,7 @@ use crate::utils::Random;
|
||||
|
||||
/// The RNG for a battle.
|
||||
#[derive(Default)]
|
||||
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
|
||||
pub struct BattleRandom {
|
||||
/// The actual underlying RNG. This is in a mutex, so it is thread safe, and can be ran
|
||||
/// predictably, with guaranteed the same outputs.
|
||||
|
||||
8
src/dynamic_data/models/battle_side.rs
Normal file → Executable file
8
src/dynamic_data/models/battle_side.rs
Normal file → Executable file
@@ -18,6 +18,7 @@ use crate::{script_hook, PkmnResult, StringKey};
|
||||
|
||||
/// A side on a battle.
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
|
||||
pub struct BattleSide {
|
||||
/// The index of the side on the battle.
|
||||
index: u8,
|
||||
@@ -239,11 +240,6 @@ impl BattleSide {
|
||||
true
|
||||
}
|
||||
|
||||
/// Checks whether the side has fled.
|
||||
pub fn has_fled(&self) -> bool {
|
||||
self.has_fled_battle
|
||||
}
|
||||
|
||||
/// Mark the side as fled.
|
||||
pub fn mark_as_fled(&mut self) {
|
||||
self.has_fled_battle = true;
|
||||
@@ -304,7 +300,7 @@ impl VolatileScriptsOwner for BattleSide {
|
||||
fn load_volatile_script(&self, key: &StringKey) -> PkmnResult<Option<Arc<dyn Script>>> {
|
||||
self.battle()
|
||||
.library()
|
||||
.load_script((self as *const Self).cast(), crate::ScriptCategory::Side, key)
|
||||
.load_script(self.into(), crate::ScriptCategory::Side, key)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
3
src/dynamic_data/models/executing_move.rs
Normal file → Executable file
3
src/dynamic_data/models/executing_move.rs
Normal file → Executable file
@@ -15,6 +15,7 @@ use crate::{PkmnResult, PokemonError};
|
||||
|
||||
/// A hit data is the data for a single hit, on a single target.
|
||||
#[derive(Default, Debug)]
|
||||
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
|
||||
pub struct HitData {
|
||||
/// Whether or not the hit is critical.
|
||||
critical: AtomicBool,
|
||||
@@ -158,7 +159,7 @@ impl ExecutingMove {
|
||||
}
|
||||
|
||||
/// Gets a hit data for a target, with a specific index.
|
||||
pub fn get_hit_data<'func>(&'func self, for_target: &'func Arc<Pokemon>, hit: u8) -> PkmnResult<&'func HitData> {
|
||||
pub fn get_hit_data(&self, for_target: &Pokemon, hit: u8) -> PkmnResult<&HitData> {
|
||||
for (index, target) in self.targets.iter().enumerate() {
|
||||
if let Some(target) = target {
|
||||
if std::ptr::eq(target.deref().deref(), for_target.deref().deref()) {
|
||||
|
||||
0
src/dynamic_data/models/learned_move.rs
Normal file → Executable file
0
src/dynamic_data/models/learned_move.rs
Normal file → Executable file
0
src/dynamic_data/models/mod.rs
Normal file → Executable file
0
src/dynamic_data/models/mod.rs
Normal file → Executable file
9
src/dynamic_data/models/pokemon.rs
Normal file → Executable file
9
src/dynamic_data/models/pokemon.rs
Normal file → Executable file
@@ -502,11 +502,7 @@ impl Pokemon {
|
||||
|
||||
let ability_script = self
|
||||
.library
|
||||
.load_script(
|
||||
(self as *const Self).cast(),
|
||||
ScriptCategory::Ability,
|
||||
self.active_ability().name(),
|
||||
)
|
||||
.load_script((&*self).into(), ScriptCategory::Ability, self.active_ability().name())
|
||||
.unwrap();
|
||||
if let Some(ability_script) = ability_script {
|
||||
self.ability_script
|
||||
@@ -772,8 +768,7 @@ impl VolatileScriptsOwner for Pokemon {
|
||||
}
|
||||
|
||||
fn load_volatile_script(&self, key: &StringKey) -> PkmnResult<Option<Arc<dyn Script>>> {
|
||||
self.library
|
||||
.load_script((self as *const Self).cast(), ScriptCategory::Pokemon, key)
|
||||
self.library.load_script(self.into(), ScriptCategory::Pokemon, key)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
0
src/dynamic_data/models/pokemon_builder.rs
Normal file → Executable file
0
src/dynamic_data/models/pokemon_builder.rs
Normal file → Executable file
13
src/dynamic_data/models/pokemon_party.rs
Normal file → Executable file
13
src/dynamic_data/models/pokemon_party.rs
Normal file → Executable file
@@ -4,6 +4,7 @@ use crate::dynamic_data::models::pokemon::Pokemon;
|
||||
|
||||
/// A list of Pokemon belonging to a trainer.
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
|
||||
pub struct PokemonParty {
|
||||
/// The underlying list of Pokemon.
|
||||
pokemon: Vec<Option<Arc<Pokemon>>>,
|
||||
@@ -89,4 +90,16 @@ impl PokemonParty {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if the party contains a given pokemon.
|
||||
pub fn has_pokemon(&self, pokemon: &Pokemon) -> bool {
|
||||
for p in &self.pokemon {
|
||||
if let Some(p) = p {
|
||||
if std::ptr::eq(p.as_ref(), pokemon) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user