use std::sync::Arc; use serde::Deserialize; use pkmn_lib::defines::LevelInt; use pkmn_lib::dynamic_data::Battle; use pkmn_lib::dynamic_data::BattleParty; use pkmn_lib::dynamic_data::DynamicLibrary; use pkmn_lib::dynamic_data::Pokemon; use pkmn_lib::dynamic_data::PokemonBuilder; use pkmn_lib::dynamic_data::PokemonParty; use pkmn_lib::StringKey; use super::test_step::TestStep; #[derive(Deserialize)] pub struct TestCase { pub name: String, battle_setup: TestBattleSetup, actions: Vec, } #[derive(Deserialize)] struct TestBattleSetup { seed: u128, can_flee: bool, number_of_sides: u8, pokemon_per_side: u8, parties: Vec, } #[derive(Deserialize)] struct TestParty { indices: Vec<[u8; 2]>, pokemon: Vec, } #[derive(Deserialize)] struct TestPokemon { species: String, level: LevelInt, moves: Vec, } impl TestCase { pub fn run_test(&self, library: Arc) { let mut parties = Vec::new(); for party in &self.battle_setup.parties { let pokemon = party .pokemon .iter() .map(|a| Some(Arc::new(a.to_pokemon(library.clone())))) .collect(); let indices = party.indices.iter().map(|a| (a[0], a[1])).collect(); parties.push((Arc::new(PokemonParty::new_from_vec(pokemon)), indices)); } let mut battle_parties = Vec::new(); for party in parties { battle_parties.push(BattleParty::new(party.0.clone(), party.1)); } let mut battle = Battle::new( library, battle_parties, self.battle_setup.can_flee, self.battle_setup.number_of_sides, self.battle_setup.pokemon_per_side, Some(self.battle_setup.seed), ); for action in &self.actions { action.execute(&mut battle); } } } impl TestPokemon { fn to_pokemon(&self, library: Arc) -> Pokemon { let mut builder = PokemonBuilder::new(library, StringKey::new(self.species.as_str().into()), self.level); for move_name in &self.moves { builder = builder.learn_move(StringKey::new(move_name)); } builder.build() } }