Moves a bunch of libraries to traits
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:
@@ -12,6 +12,7 @@ use crate::dynamic_data::models::battle::Battle;
|
||||
use crate::dynamic_data::models::learned_move::{LearnedMove, MoveLearnMethod};
|
||||
use crate::dynamic_data::script_handling::{ScriptSource, ScriptSourceData, ScriptWrapper};
|
||||
use crate::dynamic_data::{DynamicLibrary, Script, ScriptCategory, ScriptContainer, ScriptSet, VolatileScriptsOwner};
|
||||
use crate::static_data::AbilityIndex;
|
||||
use crate::static_data::Form;
|
||||
use crate::static_data::Gender;
|
||||
use crate::static_data::Item;
|
||||
@@ -19,7 +20,6 @@ use crate::static_data::Nature;
|
||||
use crate::static_data::Species;
|
||||
use crate::static_data::TypeIdentifier;
|
||||
use crate::static_data::{Ability, Statistic};
|
||||
use crate::static_data::{AbilityIndex, DataLibrary};
|
||||
use crate::static_data::{ClampedStatisticSet, StatisticSet};
|
||||
use crate::utils::Random;
|
||||
use crate::{script_hook, PkmnResult, StringKey, ValueIdentifiable, ValueIdentifier};
|
||||
@@ -30,7 +30,7 @@ pub struct Pokemon {
|
||||
/// A unique identifier so we know what value this is.
|
||||
identifier: ValueIdentifier,
|
||||
/// The library data of the Pokemon.
|
||||
library: Arc<DynamicLibrary>,
|
||||
library: Arc<dyn DynamicLibrary>,
|
||||
/// The species of the Pokemon.
|
||||
species: RwLock<Arc<dyn Species>>,
|
||||
/// The form of the Pokemon.
|
||||
@@ -120,7 +120,7 @@ pub struct Pokemon {
|
||||
impl Pokemon {
|
||||
/// Instantiates a new Pokemon.
|
||||
pub fn new(
|
||||
library: Arc<DynamicLibrary>,
|
||||
library: Arc<dyn DynamicLibrary>,
|
||||
species: Arc<dyn Species>,
|
||||
form: &Arc<dyn Form>,
|
||||
ability: AbilityIndex,
|
||||
@@ -188,7 +188,7 @@ impl Pokemon {
|
||||
}
|
||||
|
||||
/// The library data of the Pokemon.
|
||||
pub fn library(&self) -> &Arc<DynamicLibrary> {
|
||||
pub fn library(&self) -> &Arc<dyn DynamicLibrary> {
|
||||
&self.library
|
||||
}
|
||||
/// The species of the Pokemon.
|
||||
@@ -416,9 +416,9 @@ impl Pokemon {
|
||||
self.override_ability.is_some()
|
||||
}
|
||||
/// Returns the currently active ability.
|
||||
pub fn active_ability(&self) -> &Arc<dyn Ability> {
|
||||
pub fn active_ability(&self) -> Arc<dyn Ability> {
|
||||
if let Some(v) = &self.override_ability {
|
||||
return v;
|
||||
return v.clone();
|
||||
}
|
||||
self.library
|
||||
.static_data()
|
||||
@@ -523,7 +523,7 @@ impl Pokemon {
|
||||
.set(ability_script)
|
||||
.as_ref()
|
||||
// Ensure the ability script gets initialized with the parameters for the ability.
|
||||
.on_initialize(self.library.as_ref(), self.active_ability().parameters().to_vec())
|
||||
.on_initialize(&self.library, self.active_ability().parameters().to_vec())
|
||||
} else {
|
||||
self.ability_script.clear();
|
||||
}
|
||||
@@ -829,14 +829,69 @@ pub enum DamageSource {
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod test {
|
||||
use crate::dynamic_data::libraries::test::MockDynamicLibrary;
|
||||
use crate::dynamic_data::models::pokemon::Pokemon;
|
||||
use crate::static_data::Gender;
|
||||
use crate::static_data::{AbilityIndex, DataLibrary};
|
||||
use crate::dynamic_data::tests::MockBattleStatCalculator;
|
||||
use crate::dynamic_data::DynamicLibrary;
|
||||
use crate::static_data::growth_rate_library::tests::MockGrowthRateLibrary;
|
||||
use crate::static_data::nature_library::tests::MockNatureLibrary;
|
||||
use crate::static_data::species_library::tests::MockSpeciesLibrary;
|
||||
use crate::static_data::test::MockStaticData;
|
||||
use crate::static_data::tests::{MockForm, MockNature, MockSpecies};
|
||||
use crate::static_data::{AbilityIndex, Species};
|
||||
use crate::static_data::{Form, Gender};
|
||||
use crate::StringKey;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub fn mock_library() -> Arc<dyn DynamicLibrary> {
|
||||
let mut species_lib = MockSpeciesLibrary::new();
|
||||
species_lib.expect_get().return_once(|_| {
|
||||
let mut species = MockSpecies::new();
|
||||
species.expect_get_form().return_once(|_| {
|
||||
let mut form = MockForm::new();
|
||||
form.expect_name().return_const(StringKey::new("default"));
|
||||
form.expect_weight().return_const(100.0);
|
||||
form.expect_height().return_const(20.0);
|
||||
form.expect_types().return_const(vec![0u8.into()]);
|
||||
let a: Arc<dyn Form> = Arc::new(form);
|
||||
Some(a)
|
||||
});
|
||||
species.expect_growth_rate().return_const(StringKey::empty());
|
||||
species.expect_name().return_const(StringKey::new("test_species"));
|
||||
|
||||
let s: Arc<dyn Species> = Arc::new(species);
|
||||
Some(s)
|
||||
});
|
||||
|
||||
let mut static_lib = MockStaticData::new();
|
||||
static_lib.expect_species().return_const(Box::new(species_lib));
|
||||
|
||||
let mut growth_rate_lib = MockGrowthRateLibrary::new();
|
||||
growth_rate_lib.expect_calculate_experience().return_const(1000u32);
|
||||
|
||||
let mut nature_lib = MockNatureLibrary::new();
|
||||
nature_lib.expect_get_nature().returning(|_| {
|
||||
let n = MockNature::new();
|
||||
Some(Arc::new(n))
|
||||
});
|
||||
|
||||
static_lib.expect_growth_rates().return_const(Box::new(growth_rate_lib));
|
||||
static_lib.expect_natures().return_const(Box::new(nature_lib));
|
||||
|
||||
let mut stat_calculator = MockBattleStatCalculator::new();
|
||||
stat_calculator.expect_calculate_flat_stats().returning(|_, _| {});
|
||||
stat_calculator.expect_calculate_boosted_stats().returning(|_, _| {});
|
||||
|
||||
let mut lib = MockDynamicLibrary::new();
|
||||
lib.expect_static_data().return_const(Box::new(static_lib));
|
||||
lib.expect_stat_calculator().return_const(Box::new(stat_calculator));
|
||||
|
||||
Arc::new(lib)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn construct_pokemon() {
|
||||
let lib = Arc::new(crate::dynamic_data::libraries::dynamic_library::test::build());
|
||||
let lib = mock_library();
|
||||
let species = lib.static_data().species().get(&"foo".into()).unwrap().clone();
|
||||
let form = species.get_form(&"default".into()).unwrap();
|
||||
|
||||
@@ -854,7 +909,7 @@ pub mod test {
|
||||
0,
|
||||
&"test_nature".into(),
|
||||
);
|
||||
assert_eq!(pokemon.species().name(), &"foo".into());
|
||||
assert_eq!(pokemon.species().name(), &"test_species".into());
|
||||
assert_eq!(pokemon.form().name(), &"default".into());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user