use alloc::vec::Vec;
use anyhow::Result;
use battler_data::{
DataStore,
Id,
MoveData,
TypeChart,
};
use crate::dex::{
AbilityDex,
ClauseDex,
ConditionDex,
ItemDex,
MoveDex,
SingleValueDex,
SpeciesDex,
};
#[derive(Clone)]
pub struct Dex<'d> {
pub abilities: AbilityDex<'d>,
pub clauses: ClauseDex<'d>,
pub conditions: ConditionDex<'d>,
pub items: ItemDex<'d>,
pub moves: MoveDex<'d>,
pub species: SpeciesDex<'d>,
type_chart: SingleValueDex<'d, TypeChart>,
data: &'d dyn DataStore,
}
impl<'d> Dex<'d> {
pub fn new(data: &'d dyn DataStore) -> Result<Self> {
let type_chart = SingleValueDex::new(data, data.get_type_chart()?);
Ok(Self {
abilities: AbilityDex::new(data),
clauses: ClauseDex::new(data),
conditions: ConditionDex::new(data),
items: ItemDex::new(data),
moves: MoveDex::new(data),
species: SpeciesDex::new(data),
type_chart,
data,
})
}
pub fn type_chart(&self) -> &TypeChart {
self.type_chart.get()
}
pub fn all_move_ids(&self, filter: &dyn Fn(&MoveData) -> bool) -> Result<Vec<Id>> {
self.data.all_move_ids(filter)
}
}