2022-06-17 17:53:33 +00:00
|
|
|
use serde::Deserialize;
|
2023-06-17 17:05:27 +00:00
|
|
|
use std::sync::Arc;
|
2022-06-17 17:53:33 +00:00
|
|
|
|
2022-06-19 19:34:08 +00:00
|
|
|
use pkmn_lib::dynamic_data::Battle;
|
|
|
|
use pkmn_lib::dynamic_data::{MoveChoice, PassChoice, TurnChoice};
|
|
|
|
use pkmn_lib::StringKey;
|
|
|
|
|
|
|
|
use super::data_getter::TestDataGetter;
|
|
|
|
|
2022-06-17 17:53:33 +00:00
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
pub enum TestStep {
|
|
|
|
SetPokemon {
|
|
|
|
place: [u8; 2],
|
|
|
|
from_party: [u8; 2],
|
|
|
|
},
|
|
|
|
SetMoveChoice {
|
|
|
|
#[serde(rename = "for")]
|
|
|
|
for_pokemon: [u8; 2],
|
|
|
|
#[serde(rename = "move")]
|
|
|
|
use_move: String,
|
|
|
|
target: [u8; 2],
|
|
|
|
},
|
|
|
|
SetPassChoice {
|
|
|
|
#[serde(rename = "for")]
|
|
|
|
for_pokemon: [u8; 2],
|
|
|
|
},
|
|
|
|
Assert {
|
|
|
|
value: TestDataGetter,
|
|
|
|
expected: String,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TestStep {
|
2023-06-17 17:05:27 +00:00
|
|
|
pub fn execute(&self, battle: &Arc<Battle>) {
|
2022-06-17 17:53:33 +00:00
|
|
|
match self {
|
|
|
|
TestStep::SetPokemon { place, from_party } => {
|
2022-10-15 09:16:41 +00:00
|
|
|
let p = battle.parties()[from_party[0] as usize].get_pokemon(from_party[1] as usize);
|
2023-06-17 17:05:27 +00:00
|
|
|
battle.sides()[place[0] as usize].set_pokemon(place[1], p).unwrap();
|
2022-06-17 17:53:33 +00:00
|
|
|
}
|
|
|
|
TestStep::SetMoveChoice {
|
|
|
|
for_pokemon,
|
|
|
|
use_move,
|
|
|
|
target,
|
|
|
|
} => {
|
2022-06-18 13:52:39 +00:00
|
|
|
let pokemon = battle.sides()[for_pokemon[0] as usize].pokemon()[for_pokemon[1] as usize]
|
2022-06-17 17:53:33 +00:00
|
|
|
.as_ref()
|
|
|
|
.unwrap()
|
|
|
|
.clone();
|
|
|
|
let mut used_move = None;
|
2022-06-18 13:52:39 +00:00
|
|
|
for learned_move in pokemon.learned_moves().read().iter().flatten() {
|
2022-06-18 12:17:29 +00:00
|
|
|
if learned_move.move_data().name() == &StringKey::new(use_move) {
|
2022-06-17 17:53:33 +00:00
|
|
|
used_move = Some(learned_move.clone());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert!(used_move.is_some());
|
|
|
|
|
|
|
|
assert!(battle
|
|
|
|
.try_set_choice(TurnChoice::Move(MoveChoice::new(
|
2022-06-18 13:52:39 +00:00
|
|
|
pokemon,
|
2022-06-17 17:53:33 +00:00
|
|
|
used_move.unwrap(),
|
|
|
|
target[0],
|
|
|
|
target[1],
|
|
|
|
)))
|
|
|
|
.unwrap());
|
|
|
|
}
|
|
|
|
TestStep::SetPassChoice { for_pokemon } => {
|
|
|
|
let p = battle.sides()[for_pokemon[0] as usize].pokemon()[for_pokemon[1] as usize]
|
|
|
|
.as_ref()
|
|
|
|
.unwrap()
|
|
|
|
.clone();
|
|
|
|
assert!(battle.try_set_choice(TurnChoice::Pass(PassChoice::new(p))).unwrap());
|
|
|
|
}
|
|
|
|
TestStep::Assert { value, expected } => {
|
2023-06-17 17:05:27 +00:00
|
|
|
let v = value.get(&battle);
|
2022-06-17 17:53:33 +00:00
|
|
|
assert_eq!(&v, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|