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:
@@ -10,24 +10,24 @@ use project_root::get_project_root;
|
||||
use serde_json::Value;
|
||||
|
||||
use pkmn_lib::defines::LevelInt;
|
||||
use pkmn_lib::dynamic_data::DynamicLibrary;
|
||||
use pkmn_lib::dynamic_data::Gen7BattleStatCalculator;
|
||||
use pkmn_lib::dynamic_data::Gen7DamageLibrary;
|
||||
use pkmn_lib::dynamic_data::Gen7MiscLibrary;
|
||||
use pkmn_lib::dynamic_data::{DynamicLibrary, DynamicLibraryImpl};
|
||||
use pkmn_lib::script_implementations::wasm::script_resolver::WebAssemblyScriptResolver;
|
||||
use pkmn_lib::static_data::{
|
||||
AbilityImpl, AbilityLibrary, BattleItemCategory, DataLibrary, EffectParameter, Form, FormImpl, GrowthRateLibrary,
|
||||
ItemImpl, ItemLibrary, LearnableMoves, LearnableMovesImpl, LibrarySettings, LookupGrowthRate, MoveDataImpl,
|
||||
MoveLibrary, NatureImpl, NatureLibrary, SecondaryEffect, SecondaryEffectImpl, SpeciesImpl, StaticData,
|
||||
StaticStatisticSet, Statistic, TypeLibrary,
|
||||
AbilityImpl, AbilityLibrary, BattleItemCategory, EffectParameter, Form, FormImpl, GrowthRateLibrary, ItemImpl,
|
||||
ItemLibrary, LearnableMoves, LearnableMovesImpl, LibrarySettingsImpl, LookupGrowthRate, MoveDataImpl, MoveLibrary,
|
||||
NatureImpl, NatureLibrary, SecondaryEffect, SecondaryEffectImpl, SpeciesImpl, StaticData, StaticDataImpl,
|
||||
StaticStatisticSet, Statistic, TypeLibrary, TypeLibraryImpl,
|
||||
};
|
||||
use pkmn_lib::StringKey;
|
||||
|
||||
pub fn load_library() -> DynamicLibrary {
|
||||
pub fn load_library() -> Arc<dyn DynamicLibrary> {
|
||||
let mut path = get_project_root().unwrap();
|
||||
path.push("tests/data/");
|
||||
let path = path.to_str().unwrap().to_string();
|
||||
let mut data = StaticData::new(LibrarySettings::new(100));
|
||||
let mut data = StaticDataImpl::new(Box::new(LibrarySettingsImpl::new(100)));
|
||||
load_types(&path, data.types_mut());
|
||||
load_natures(&path, data.natures_mut());
|
||||
load_items(&path, data.items_mut());
|
||||
@@ -38,16 +38,16 @@ pub fn load_library() -> DynamicLibrary {
|
||||
let mut resolver = WebAssemblyScriptResolver::new();
|
||||
load_wasm(&path, resolver.as_mut());
|
||||
|
||||
DynamicLibrary::new(
|
||||
data,
|
||||
Arc::new(DynamicLibraryImpl::new(
|
||||
Box::new(data),
|
||||
Box::new(Gen7BattleStatCalculator::new()),
|
||||
Box::new(Gen7DamageLibrary::new(false)),
|
||||
Box::new(Gen7MiscLibrary::new()),
|
||||
resolver,
|
||||
)
|
||||
))
|
||||
}
|
||||
|
||||
pub fn load_types(path: &String, type_library: &mut TypeLibrary) {
|
||||
pub fn load_types(path: &String, type_library: &mut Box<dyn TypeLibrary>) {
|
||||
let mut reader = csv::ReaderBuilder::new()
|
||||
.delimiter(b'|')
|
||||
.from_path(path.to_string() + "Types.csv")
|
||||
@@ -69,7 +69,7 @@ pub fn load_types(path: &String, type_library: &mut TypeLibrary) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_natures(path: &String, nature_library: &mut NatureLibrary) {
|
||||
pub fn load_natures(path: &String, nature_library: &mut Box<dyn NatureLibrary>) {
|
||||
let mut reader = csv::ReaderBuilder::new()
|
||||
.delimiter(b'|')
|
||||
.from_path(path.to_string() + "Natures.csv")
|
||||
@@ -93,7 +93,7 @@ pub fn load_natures(path: &String, nature_library: &mut NatureLibrary) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_items(path: &String, lib: &mut ItemLibrary) {
|
||||
pub fn load_items(path: &String, lib: &mut Box<dyn ItemLibrary>) {
|
||||
let mut file = File::open(path.to_string() + "Items.json").unwrap();
|
||||
let mut data = String::new();
|
||||
file.read_to_string(&mut data).unwrap();
|
||||
@@ -123,7 +123,7 @@ pub fn load_items(path: &String, lib: &mut ItemLibrary) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_growth_rates(path: &String, growth_rate_library: &mut GrowthRateLibrary) {
|
||||
pub fn load_growth_rates(path: &String, growth_rate_library: &mut Box<dyn GrowthRateLibrary>) {
|
||||
let mut file = File::open(path.to_string() + "GrowthRates.json").unwrap();
|
||||
let mut data = String::new();
|
||||
file.read_to_string(&mut data).unwrap();
|
||||
@@ -142,7 +142,7 @@ pub fn load_growth_rates(path: &String, growth_rate_library: &mut GrowthRateLibr
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_abilities(path: &String, ability_library: &mut AbilityLibrary) {
|
||||
pub fn load_abilities(path: &String, ability_library: &mut Box<dyn AbilityLibrary>) {
|
||||
let mut file = File::open(path.to_string() + "Abilities.json").unwrap();
|
||||
let mut data = String::new();
|
||||
file.read_to_string(&mut data).unwrap();
|
||||
@@ -166,7 +166,7 @@ pub fn load_abilities(path: &String, ability_library: &mut AbilityLibrary) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_moves(path: &String, lib: &mut StaticData) {
|
||||
pub fn load_moves(path: &String, lib: &mut dyn StaticData) {
|
||||
let mut file = File::open(path.to_string() + "Moves.json").unwrap();
|
||||
let mut data = String::new();
|
||||
file.read_to_string(&mut data).unwrap();
|
||||
@@ -231,7 +231,7 @@ pub fn load_moves(path: &String, lib: &mut StaticData) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_species(path: &String, library: &mut StaticData) {
|
||||
pub fn load_species(path: &String, library: &mut dyn StaticData) {
|
||||
let mut file = File::open(path.to_string() + "Pokemon.json").unwrap();
|
||||
let mut data = String::new();
|
||||
file.read_to_string(&mut data).unwrap();
|
||||
@@ -285,7 +285,7 @@ fn load_wasm(path: &String, library: &mut WebAssemblyScriptResolver) {
|
||||
library.finalize();
|
||||
}
|
||||
|
||||
fn parse_form(name: StringKey, value: &Value, library: &mut StaticData) -> Arc<dyn Form> {
|
||||
fn parse_form(name: StringKey, value: &Value, library: &mut dyn StaticData) -> Arc<dyn Form> {
|
||||
let mut abilities = Vec::new();
|
||||
for a in value.get("abilities").unwrap().as_array().unwrap() {
|
||||
abilities.push(a.as_str().unwrap().into());
|
||||
@@ -308,7 +308,7 @@ fn parse_form(name: StringKey, value: &Value, library: &mut StaticData) -> Arc<d
|
||||
.map(|a| library.types().get_type_id(&a.as_str().unwrap().into()).unwrap())
|
||||
.collect();
|
||||
|
||||
let moves = parse_moves(value.get("moves").unwrap(), library.moves());
|
||||
let moves = parse_moves(value.get("moves").unwrap(), library.moves_mut());
|
||||
|
||||
Arc::new(FormImpl::new(
|
||||
&name,
|
||||
@@ -368,7 +368,7 @@ where
|
||||
)
|
||||
}
|
||||
|
||||
fn parse_moves(value: &Value, move_library: &MoveLibrary) -> Box<dyn LearnableMoves> {
|
||||
fn parse_moves(value: &Value, move_library: &mut Box<dyn MoveLibrary>) -> Box<dyn LearnableMoves> {
|
||||
let mut moves = LearnableMovesImpl::default();
|
||||
|
||||
let level_moves = value.get("levelMoves").unwrap().as_array().unwrap();
|
||||
@@ -410,7 +410,7 @@ fn parse_effect_parameter(value: &Value) -> EffectParameter {
|
||||
fn test_type_library_loaded() {
|
||||
let mut path = get_project_root().unwrap();
|
||||
path.push("tests/data/");
|
||||
let mut lib = TypeLibrary::new(18);
|
||||
let mut lib: Box<dyn TypeLibrary> = Box::new(TypeLibraryImpl::new(18));
|
||||
load_types(&path.to_str().unwrap().to_string(), &mut lib);
|
||||
|
||||
assert_eq!(
|
||||
|
||||
@@ -43,7 +43,7 @@ struct TestPokemon {
|
||||
}
|
||||
|
||||
impl TestCase {
|
||||
pub fn run_test(&self, library: Arc<DynamicLibrary>) {
|
||||
pub fn run_test(&self, library: Arc<dyn DynamicLibrary>) {
|
||||
let mut parties = Vec::new();
|
||||
for party in &self.battle_setup.parties {
|
||||
let pokemon = party
|
||||
@@ -73,7 +73,7 @@ impl TestCase {
|
||||
}
|
||||
|
||||
impl TestPokemon {
|
||||
fn to_pokemon(&self, library: Arc<DynamicLibrary>) -> Pokemon {
|
||||
fn to_pokemon(&self, library: Arc<dyn DynamicLibrary>) -> Pokemon {
|
||||
let mut builder = PokemonBuilder::new(library, self.species.as_str().into(), self.level);
|
||||
for move_name in &self.moves {
|
||||
builder = builder.learn_move(StringKey::new(move_name));
|
||||
|
||||
@@ -17,8 +17,8 @@ use crate::common::{library_loader, TestCase};
|
||||
|
||||
pub mod common;
|
||||
|
||||
fn get_library() -> Arc<DynamicLibrary> {
|
||||
Arc::new(library_loader::load_library())
|
||||
fn get_library() -> Arc<dyn DynamicLibrary> {
|
||||
library_loader::load_library()
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user