84 lines
2.6 KiB
Rust
Executable File
84 lines
2.6 KiB
Rust
Executable File
use serde::Deserialize;
|
|
use std::sync::Arc;
|
|
|
|
use pkmn_lib::dynamic_data::Battle;
|
|
use pkmn_lib::dynamic_data::{MoveChoice, PassChoice, TurnChoice};
|
|
use pkmn_lib::StringKey;
|
|
|
|
use super::data_getter::TestDataGetter;
|
|
|
|
#[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 {
|
|
pub fn execute(&self, battle: &Battle) {
|
|
match self {
|
|
TestStep::SetPokemon { place, from_party } => {
|
|
let p = battle.parties()[from_party[0] as usize].get_pokemon(from_party[1] as usize);
|
|
battle.sides()[place[0] as usize].set_pokemon(place[1], p).unwrap();
|
|
}
|
|
TestStep::SetMoveChoice {
|
|
for_pokemon,
|
|
use_move,
|
|
target,
|
|
} => {
|
|
let pokemon = battle.sides()[for_pokemon[0] as usize].pokemon()[for_pokemon[1] as usize]
|
|
.as_ref()
|
|
.unwrap()
|
|
.clone();
|
|
let mut used_move = None;
|
|
for learned_move in pokemon.learned_moves().read().iter().flatten() {
|
|
if learned_move.move_data().name() == &StringKey::new(use_move) {
|
|
used_move = Some(learned_move.clone());
|
|
break;
|
|
}
|
|
}
|
|
assert!(used_move.is_some());
|
|
|
|
assert!(battle
|
|
.try_set_choice(Arc::new(TurnChoice::Move(MoveChoice::new(
|
|
pokemon,
|
|
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(Arc::new(TurnChoice::Pass(PassChoice::new(p))))
|
|
.unwrap());
|
|
}
|
|
TestStep::Assert { value, expected } => {
|
|
let v = value.get(battle);
|
|
assert_eq!(&v, expected)
|
|
}
|
|
}
|
|
}
|
|
}
|