PkmnLib_rs/src/static_data/libraries/static_data.rs

204 lines
7.5 KiB
Rust
Executable File

use crate::static_data::MoveLibrary;
use crate::static_data::NatureLibrary;
use crate::static_data::SpeciesLibrary;
use crate::static_data::TypeLibrary;
use crate::static_data::{AbilityLibrary, AbilityLibraryImpl, ItemLibraryImpl, MoveLibraryImpl, SpeciesLibraryImpl};
use crate::static_data::{GrowthRateLibrary, GrowthRateLibraryImpl};
use crate::static_data::{ItemLibrary, NatureLibraryImpl};
use crate::static_data::{LibrarySettings, TypeLibraryImpl};
use crate::{ValueIdentifiable, ValueIdentifier};
use std::fmt::Debug;
/// The storage for all different libraries.
pub trait StaticData: Debug + ValueIdentifiable {
/// Several misc settings for the library.
fn settings(&self) -> &Box<dyn LibrarySettings>;
/// All data for Pokemon species.
fn species(&self) -> &Box<dyn SpeciesLibrary>;
/// All data for Pokemon species.
fn species_mut(&mut self) -> &mut Box<dyn SpeciesLibrary>;
/// All data for the moves.
fn moves(&self) -> &Box<dyn MoveLibrary>;
/// All data for the moves.
fn moves_mut(&mut self) -> &mut Box<dyn MoveLibrary>;
/// All data for the items.
fn items(&self) -> &Box<dyn ItemLibrary>;
/// All data for the items.
fn items_mut(&mut self) -> &mut Box<dyn ItemLibrary>;
/// All data for growth rates.
fn growth_rates(&self) -> &Box<dyn GrowthRateLibrary>;
/// All data for growth rates.
fn growth_rates_mut(&mut self) -> &mut Box<dyn GrowthRateLibrary>;
/// All data related to types and type effectiveness.
fn types(&self) -> &Box<dyn TypeLibrary>;
/// All data related to types and type effectiveness.
fn types_mut(&mut self) -> &mut Box<dyn TypeLibrary>;
/// All data related to natures.
fn natures(&self) -> &Box<dyn NatureLibrary>;
/// All data related to natures.
fn natures_mut(&mut self) -> &mut Box<dyn NatureLibrary>;
/// All data related to abilities.
fn abilities(&self) -> &Box<dyn AbilityLibrary>;
/// All data related to abilities.
fn abilities_mut(&mut self) -> &mut Box<dyn AbilityLibrary>;
}
/// The storage for all different libraries.
#[derive(Debug)]
pub struct StaticDataImpl {
/// A unique identifier so we know what value this is.
identifier: ValueIdentifier,
/// Several misc settings for the library.
settings: Box<dyn LibrarySettings>,
/// All data for Pokemon species.
species: Box<dyn SpeciesLibrary>,
/// All data for the moves.
moves: Box<dyn MoveLibrary>,
/// All data for the items.
items: Box<dyn ItemLibrary>,
/// All data for growth rates.
growth_rates: Box<dyn GrowthRateLibrary>,
/// All data related to types and type effectiveness.
types: Box<dyn TypeLibrary>,
/// All data related to natures.
natures: Box<dyn NatureLibrary>,
/// All data related to abilities.
abilities: Box<dyn AbilityLibrary>,
}
impl StaticDataImpl {
/// Instantiates a new data collection.
pub fn new(settings: Box<dyn LibrarySettings>) -> Self {
Self {
identifier: Default::default(),
settings,
species: Box::new(SpeciesLibraryImpl::new(0)),
moves: Box::new(MoveLibraryImpl::new(0)),
items: Box::new(ItemLibraryImpl::new(0)),
growth_rates: Box::new(GrowthRateLibraryImpl::new(0)),
types: Box::new(TypeLibraryImpl::new(0)),
natures: Box::new(NatureLibraryImpl::new(0)),
abilities: Box::new(AbilityLibraryImpl::new(0)),
}
}
}
impl StaticData for StaticDataImpl {
/// Several misc settings for the library.
fn settings(&self) -> &Box<dyn LibrarySettings> {
&self.settings
}
/// All data for Pokemon species.
fn species(&self) -> &Box<dyn SpeciesLibrary> {
&self.species
}
/// All data for Pokemon species.
fn species_mut(&mut self) -> &mut Box<dyn SpeciesLibrary> {
&mut self.species
}
/// All data for the moves.
fn moves(&self) -> &Box<dyn MoveLibrary> {
&self.moves
}
/// All data for the moves.
fn moves_mut(&mut self) -> &mut Box<dyn MoveLibrary> {
&mut self.moves
}
/// All data for the items.
fn items(&self) -> &Box<dyn ItemLibrary> {
&self.items
}
/// All data for the items.
fn items_mut(&mut self) -> &mut Box<dyn ItemLibrary> {
&mut self.items
}
/// All data for growth rates.
fn growth_rates(&self) -> &Box<dyn GrowthRateLibrary> {
&self.growth_rates
}
/// All data for growth rates.
fn growth_rates_mut(&mut self) -> &mut Box<dyn GrowthRateLibrary> {
&mut self.growth_rates
}
/// All data related to types and type effectiveness.
fn types(&self) -> &Box<dyn TypeLibrary> {
&self.types
}
/// All data related to types and type effectiveness.
fn types_mut(&mut self) -> &mut Box<dyn TypeLibrary> {
&mut self.types
}
/// All data related to natures.
fn natures(&self) -> &Box<dyn NatureLibrary> {
&self.natures
}
/// All data related to natures.
fn natures_mut(&mut self) -> &mut Box<dyn NatureLibrary> {
&mut self.natures
}
/// All data related to abilities.
fn abilities(&self) -> &Box<dyn AbilityLibrary> {
&self.abilities
}
/// All data related to abilities.
fn abilities_mut(&mut self) -> &mut Box<dyn AbilityLibrary> {
&mut self.abilities
}
}
impl ValueIdentifiable for StaticDataImpl {
fn value_identifier(&self) -> ValueIdentifier {
self.identifier
}
}
#[cfg(test)]
pub mod test {
use super::*;
use crate::static_data::LibrarySettingsImpl;
mockall::mock! {
#[derive(Debug)]
pub StaticData{}
impl StaticData for StaticData {
fn settings(&self) -> &Box<dyn LibrarySettings>;
fn species(&self) -> &Box<dyn SpeciesLibrary>;
fn species_mut(&mut self) -> &mut Box<dyn SpeciesLibrary>;
fn moves(&self) -> &Box<dyn MoveLibrary>;
fn moves_mut(&mut self) -> &mut Box<dyn MoveLibrary>;
fn items(&self) -> &Box<dyn ItemLibrary>;
fn items_mut(&mut self) -> &mut Box<dyn ItemLibrary>;
fn growth_rates(&self) -> & Box<dyn GrowthRateLibrary>;
fn growth_rates_mut(&mut self) -> &mut Box<dyn GrowthRateLibrary>;
fn types(&self) -> &Box<dyn TypeLibrary>;
fn types_mut(&mut self) -> &mut Box<dyn TypeLibrary>;
fn natures(&self) -> &Box<dyn NatureLibrary>;
fn natures_mut(&mut self) -> &mut Box<dyn NatureLibrary>;
fn abilities(&self) -> &Box<dyn AbilityLibrary>;
fn abilities_mut(&mut self) -> &mut Box<dyn AbilityLibrary>;
}
impl ValueIdentifiable for StaticData {
fn value_identifier(&self) -> ValueIdentifier{
ValueIdentifier::new(0)
}
}
}
pub fn build() -> StaticDataImpl {
StaticDataImpl {
identifier: Default::default(),
settings: Box::new(LibrarySettingsImpl::new(100)),
species: crate::static_data::libraries::species_library::tests::build(),
moves: crate::static_data::libraries::move_library::tests::build(),
items: crate::static_data::libraries::item_library::tests::build(),
growth_rates: Box::new(crate::static_data::libraries::growth_rate_library::tests::build()),
types: Box::new(crate::static_data::libraries::type_library::tests::build()),
natures: Box::new(crate::static_data::libraries::nature_library::tests::build()),
abilities: Box::new(crate::static_data::libraries::ability_library::tests::build()),
}
}
}