Skip to main content

battler_data/datastore/
data_store.rs

1use alloc::vec::Vec;
2
3use anyhow::Result;
4
5use crate::{
6    AbilityData,
7    ClauseData,
8    ConditionData,
9    Id,
10    ItemData,
11    MoveData,
12    SpeciesData,
13    TypeChart,
14};
15
16/// Collection of tables for all resource data.
17///
18/// This trait can be implemented for different data sources, such as an external database or disk.
19///
20/// This collection is used for "raw lookup" of resources by ID. Individual dexes may implement
21/// specialized lookup rules over this table, such as resolving aliases or special names.
22pub trait DataStore: Send + Sync {
23    /// Gets all move IDs, applying the given filter on the underlying data.
24    fn all_move_ids(&self, filter: &dyn Fn(&MoveData) -> bool) -> Result<Vec<Id>>;
25
26    /// Gets the type chart.
27    fn get_type_chart(&self) -> Result<TypeChart>;
28
29    /// Translates the given alias to another ID, if the alias mapping exists.
30    fn translate_alias(&self, id: &Id) -> Result<Option<Id>>;
31
32    /// Gets an ability by ID.
33    fn get_ability(&self, id: &Id) -> Result<Option<AbilityData>>;
34    /// Gets a clause by ID.
35    fn get_clause(&self, id: &Id) -> Result<Option<ClauseData>>;
36    /// Gets a condition by ID.
37    fn get_condition(&self, id: &Id) -> Result<Option<ConditionData>>;
38    /// Gets an item by ID.
39    fn get_item(&self, id: &Id) -> Result<Option<ItemData>>;
40    /// Gets a move by ID.
41    fn get_move(&self, id: &Id) -> Result<Option<MoveData>>;
42    /// Gets a species by ID.
43    fn get_species(&self, id: &Id) -> Result<Option<SpeciesData>>;
44}
45
46/// An extension of [`DataStore`] for looking up resources by name.
47pub trait DataStoreByName: DataStore {
48    /// Gets an ability by name.
49    fn get_ability_by_name(&self, name: &str) -> Result<Option<AbilityData>>;
50    /// Gets a clause by name.
51    fn get_clause_by_name(&self, name: &str) -> Result<Option<ClauseData>>;
52    /// Gets a condition by name.
53    fn get_condition_by_name(&self, name: &str) -> Result<Option<ConditionData>>;
54    /// Gets an item by name.
55    fn get_item_by_name(&self, name: &str) -> Result<Option<ItemData>>;
56    /// Gets a move by name.
57    fn get_move_by_name(&self, name: &str) -> Result<Option<MoveData>>;
58    /// Gets a species by name.
59    fn get_species_by_name(&self, name: &str) -> Result<Option<SpeciesData>>;
60}