More work on mocking and removing the impls from the interface
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
extern crate alloc;
|
||||
|
||||
use alloc::boxed::Box;
|
||||
#[cfg(not(test))]
|
||||
use pkmn_lib_interface::set_load_script_fn;
|
||||
|
||||
#[macro_use]
|
||||
|
||||
@@ -39,3 +39,36 @@ impl Script for AfterYou {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use alloc::rc::Rc;
|
||||
use pkmn_lib_interface::app_interface::{
|
||||
MockBattle, MockChoiceQueue, MockExecutingMove, MockPokemon,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn move_pokemon_choice_next_gets_called_once() {
|
||||
let mut battle = MockBattle::new();
|
||||
battle.expect_choice_queue().once().return_once_st(move || {
|
||||
let mut choice_queue = MockChoiceQueue::new();
|
||||
choice_queue
|
||||
.expect_move_pokemon_choice_next()
|
||||
.once()
|
||||
.return_const(true);
|
||||
Rc::new(choice_queue)
|
||||
});
|
||||
|
||||
let battle = Rc::new(battle);
|
||||
let mut target = MockPokemon::new();
|
||||
target
|
||||
.expect_battle()
|
||||
.once()
|
||||
.return_once_st(move || Some(battle.clone()));
|
||||
let target = Rc::new(target);
|
||||
|
||||
let script = AfterYou::new();
|
||||
script.on_secondary_effect(Rc::new(MockExecutingMove::new()), target, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,7 @@ use alloc::boxed::Box;
|
||||
use core::any::Any;
|
||||
use core::sync::atomic::{AtomicBool, Ordering};
|
||||
use pkmn_lib_interface::app_interface::{
|
||||
BattleSide, BattleSideImpl, DamageSource, DataLibrary, ExecutingMove, Pokemon, TurnChoice,
|
||||
WithVolatile,
|
||||
BattleSide, DamageSource, DataLibrary, ExecutingMove, Pokemon, TurnChoice, WithVolatile,
|
||||
};
|
||||
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
|
||||
|
||||
@@ -26,10 +25,9 @@ impl Script for Assurance {
|
||||
]
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
fn on_before_turn(&self, choice: TurnChoice) {
|
||||
if let TurnChoice::Move(data) = &choice {
|
||||
let side: BattleSideImpl = choice
|
||||
let side: BattleSide = choice
|
||||
.user()
|
||||
.battle()
|
||||
.unwrap()
|
||||
@@ -90,7 +88,7 @@ impl Script for AssuranceData {
|
||||
|
||||
#[cfg(not(test))]
|
||||
fn on_end_turn(&self) {
|
||||
let side: BattleSideImpl = self.get_owner().unwrap();
|
||||
let side: pkmn_lib_interface::app_interface::BattleSideImpl = self.get_owner().unwrap();
|
||||
side.remove_volatile(self);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use alloc::boxed::Box;
|
||||
use core::any::Any;
|
||||
use core::sync::atomic::{AtomicU32, Ordering};
|
||||
use pkmn_lib_interface::app_interface::{
|
||||
BattleSide, BattleSideImpl, ExecutingMove, MoveCategory, Pokemon, WithVolatile,
|
||||
BattleSide, ExecutingMove, MoveCategory, Pokemon, WithVolatile,
|
||||
};
|
||||
use pkmn_lib_interface::handling::ScriptCapabilities::OnEndTurn;
|
||||
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
|
||||
@@ -76,7 +76,7 @@ impl Script for AuroraVeilEffect {
|
||||
if mv.get_hit_data(&target, hit).is_critical() {
|
||||
return;
|
||||
}
|
||||
let side: BattleSideImpl = self.get_owner().unwrap();
|
||||
let side: pkmn_lib_interface::app_interface::BattleSideImpl = self.get_owner().unwrap();
|
||||
if side.has_volatile(ReflectEffect::get_const_name())
|
||||
&& mv.use_move().category() == MoveCategory::Physical
|
||||
{
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use crate::script;
|
||||
use alloc::rc::Rc;
|
||||
use core::any::Any;
|
||||
use core::sync::atomic::{AtomicI8, Ordering};
|
||||
use pkmn_lib_interface::app_interface::list::ImmutableList;
|
||||
use pkmn_lib_interface::app_interface::list::{ImmutableList, ImmutableListTrait};
|
||||
use pkmn_lib_interface::app_interface::{
|
||||
DynamicLibrary, EffectParameter, ExecutingMove, Pokemon, Statistic,
|
||||
};
|
||||
@@ -34,7 +35,7 @@ impl Script for ChangeAllTargetStats {
|
||||
fn on_initialize(
|
||||
&self,
|
||||
_library: &DynamicLibrary,
|
||||
parameters: Option<ImmutableList<EffectParameter>>,
|
||||
parameters: Option<ImmutableList<Rc<EffectParameter>>>,
|
||||
) {
|
||||
self.amount.store(
|
||||
parameters.unwrap().get(0).unwrap().as_int() as i8,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use alloc::rc::Rc;
|
||||
use core::any::Any;
|
||||
use core::sync::atomic::{AtomicI8, Ordering};
|
||||
use pkmn_lib_interface::app_interface::list::ImmutableList;
|
||||
@@ -42,7 +43,7 @@ macro_rules! change_stat_effect {
|
||||
fn on_initialize(
|
||||
&self,
|
||||
_library: &DynamicLibrary,
|
||||
parameters: Option<ImmutableList<EffectParameter>>,
|
||||
parameters: Option<ImmutableList<Rc<EffectParameter>>>,
|
||||
) {
|
||||
self.amount.store(
|
||||
parameters.unwrap().get(0).unwrap().as_int() as i8,
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
use crate::script;
|
||||
use alloc::rc::Rc;
|
||||
use atomic_float::AtomicF32;
|
||||
use core::any::Any;
|
||||
use core::sync::atomic::Ordering;
|
||||
use pkmn_lib_interface::app_interface::list::ImmutableList;
|
||||
use pkmn_lib_interface::app_interface::list::{ImmutableList, ImmutableListTrait};
|
||||
use pkmn_lib_interface::app_interface::{DynamicLibrary, EffectParameter, ExecutingMove, Pokemon};
|
||||
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
|
||||
|
||||
@@ -29,7 +30,7 @@ impl Script for Drain {
|
||||
fn on_initialize(
|
||||
&self,
|
||||
_library: &DynamicLibrary,
|
||||
parameters: Option<ImmutableList<EffectParameter>>,
|
||||
parameters: Option<ImmutableList<Rc<EffectParameter>>>,
|
||||
) {
|
||||
self.heal_modifier.store(
|
||||
parameters.unwrap().get(0).unwrap().as_float(),
|
||||
|
||||
Reference in New Issue
Block a user