PkmnLib_rs/src/static_data/libraries/static_data.rs

151 lines
4.9 KiB
Rust
Executable File

use crate::static_data::AbilityLibrary;
use crate::static_data::GrowthRateLibrary;
use crate::static_data::ItemLibrary;
use crate::static_data::LibrarySettings;
use crate::static_data::MoveLibrary;
use crate::static_data::NatureLibrary;
use crate::static_data::SpeciesLibrary;
use crate::static_data::TypeLibrary;
use std::fmt::Debug;
use std::sync::Arc;
/// The storage for all different libraries.
pub trait StaticData: Debug {
/// Several misc settings for the library.
fn settings(&self) -> &Arc<dyn LibrarySettings>;
/// All data for Pokemon species.
fn species(&self) -> &Arc<dyn SpeciesLibrary>;
/// All data for the moves.
fn moves(&self) -> &Arc<dyn MoveLibrary>;
/// All data for the items.
fn items(&self) -> &Arc<dyn ItemLibrary>;
/// All data for growth rates.
fn growth_rates(&self) -> &Arc<dyn GrowthRateLibrary>;
/// All data related to types and type effectiveness.
fn types(&self) -> &Arc<dyn TypeLibrary>;
/// All data related to natures.
fn natures(&self) -> &Arc<dyn NatureLibrary>;
/// All data related to abilities.
fn abilities(&self) -> &Arc<dyn AbilityLibrary>;
}
/// The storage for all different libraries.
#[derive(Debug)]
pub struct StaticDataImpl {
/// Several misc settings for the library.
settings: Arc<dyn LibrarySettings>,
/// All data for Pokemon species.
species: Arc<dyn SpeciesLibrary>,
/// All data for the moves.
moves: Arc<dyn MoveLibrary>,
/// All data for the items.
items: Arc<dyn ItemLibrary>,
/// All data for growth rates.
growth_rates: Arc<dyn GrowthRateLibrary>,
/// All data related to types and type effectiveness.
types: Arc<dyn TypeLibrary>,
/// All data related to natures.
natures: Arc<dyn NatureLibrary>,
/// All data related to abilities.
abilities: Arc<dyn AbilityLibrary>,
}
impl StaticDataImpl {
/// Instantiates a new data collection.
pub fn new(
settings: Arc<dyn LibrarySettings>,
species: Arc<dyn SpeciesLibrary>,
moves: Arc<dyn MoveLibrary>,
items: Arc<dyn ItemLibrary>,
growth_rates: Arc<dyn GrowthRateLibrary>,
types: Arc<dyn TypeLibrary>,
natures: Arc<dyn NatureLibrary>,
abilities: Arc<dyn AbilityLibrary>,
) -> Self {
Self {
settings,
species,
moves,
items,
growth_rates,
types,
natures,
abilities,
}
}
}
impl StaticData for StaticDataImpl {
/// Several misc settings for the library.
fn settings(&self) -> &Arc<dyn LibrarySettings> {
&self.settings
}
/// All data for Pokemon species.
fn species(&self) -> &Arc<dyn SpeciesLibrary> {
&self.species
}
/// All data for the moves.
fn moves(&self) -> &Arc<dyn MoveLibrary> {
&self.moves
}
/// All data for the items.
fn items(&self) -> &Arc<dyn ItemLibrary> {
&self.items
}
/// All data for growth rates.
fn growth_rates(&self) -> &Arc<dyn GrowthRateLibrary> {
&self.growth_rates
}
/// All data related to types and type effectiveness.
fn types(&self) -> &Arc<dyn TypeLibrary> {
&self.types
}
/// All data related to natures.
fn natures(&self) -> &Arc<dyn NatureLibrary> {
&self.natures
}
/// All data related to abilities.
fn abilities(&self) -> &Arc<dyn AbilityLibrary> {
&self.abilities
}
}
#[cfg(test)]
#[allow(clippy::indexing_slicing)]
#[allow(clippy::unwrap_used)]
pub mod test {
use super::*;
use crate::static_data::LibrarySettingsImpl;
mockall::mock! {
#[derive(Debug)]
pub StaticData{}
impl StaticData for StaticData {
fn settings(&self) -> &Arc<dyn LibrarySettings>;
fn species(&self) -> &Arc<dyn SpeciesLibrary>;
fn moves(&self) -> &Arc<dyn MoveLibrary>;
fn items(&self) -> &Arc<dyn ItemLibrary>;
fn growth_rates(&self) -> & Arc<dyn GrowthRateLibrary>;
fn types(&self) -> &Arc<dyn TypeLibrary>;
fn natures(&self) -> &Arc<dyn NatureLibrary>;
fn abilities(&self) -> &Arc<dyn AbilityLibrary>;
}
}
pub fn build() -> StaticDataImpl {
StaticDataImpl {
settings: Arc::new(LibrarySettingsImpl::new(100, 100).unwrap()),
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: Arc::new(crate::static_data::libraries::growth_rate_library::tests::build()),
types: Arc::new(crate::static_data::libraries::type_library::tests::build()),
natures: Arc::new(crate::static_data::libraries::nature_library::tests::build()),
abilities: Arc::new(crate::static_data::libraries::ability_library::tests::build()),
}
}
}