This commit is contained in:
@@ -25,7 +25,7 @@ impl AbilityLibrary {
|
||||
}
|
||||
}
|
||||
|
||||
impl DataLibrary<'_, Ability> for AbilityLibrary {
|
||||
impl DataLibrary<Ability> for AbilityLibrary {
|
||||
fn map(&self) -> &IndexMap<StringKey, Arc<Ability>> {
|
||||
&self.map
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::StringKey;
|
||||
|
||||
/// A data library is a collection of methods to set up a default library, where values are stored
|
||||
/// by both key, while keeping their insertion order.
|
||||
pub trait DataLibrary<'a, T: 'a> {
|
||||
pub trait DataLibrary<T: ?Sized> {
|
||||
/// Returns the underlying map.
|
||||
fn map(&self) -> &IndexMap<StringKey, Arc<T>>;
|
||||
/// Returns the underlying map in mutable manner.
|
||||
@@ -24,18 +24,18 @@ pub trait DataLibrary<'a, T: 'a> {
|
||||
}
|
||||
|
||||
/// Gets a value from the library.
|
||||
fn get(&'a self, key: &StringKey) -> Option<&Arc<T>> {
|
||||
fn get(&self, key: &StringKey) -> Option<&Arc<T>> {
|
||||
self.map().get::<StringKey>(key)
|
||||
}
|
||||
|
||||
/// Gets a value from the library.
|
||||
fn get_by_hash(&'a self, key: u32) -> Option<&Arc<T>> {
|
||||
fn get_by_hash(&self, key: u32) -> Option<&Arc<T>> {
|
||||
self.map().get::<u32>(&key)
|
||||
}
|
||||
|
||||
/// Gets a value from the library by the index where it is stored.
|
||||
fn get_key_by_index(&'a self, index: usize) -> Option<&StringKey> {
|
||||
self.map().get_index(index).map(|a| a.0)
|
||||
fn get_key_by_index(&self, index: usize) -> Option<StringKey> {
|
||||
self.map().get_index(index).map(|a| a.0.clone())
|
||||
}
|
||||
|
||||
/// Gets the amount of values in the library.
|
||||
|
||||
@@ -8,12 +8,12 @@ use crate::{StringKey, ValueIdentifiable, ValueIdentifier};
|
||||
|
||||
/// A library to store all items.
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
|
||||
|
||||
pub struct ItemLibrary {
|
||||
/// A unique identifier so we know what value this is.
|
||||
identifier: ValueIdentifier,
|
||||
/// The underlying data structure.
|
||||
map: IndexMap<StringKey, Arc<Item>>,
|
||||
map: IndexMap<StringKey, Arc<dyn Item>>,
|
||||
}
|
||||
|
||||
impl ItemLibrary {
|
||||
@@ -26,12 +26,12 @@ impl ItemLibrary {
|
||||
}
|
||||
}
|
||||
|
||||
impl DataLibrary<'_, Item> for ItemLibrary {
|
||||
fn map(&self) -> &IndexMap<StringKey, Arc<Item>> {
|
||||
impl DataLibrary<dyn Item> for ItemLibrary {
|
||||
fn map(&self) -> &IndexMap<StringKey, Arc<dyn Item>> {
|
||||
&self.map
|
||||
}
|
||||
|
||||
fn get_modify(&mut self) -> &mut IndexMap<StringKey, Arc<Item>> {
|
||||
fn get_modify(&mut self) -> &mut IndexMap<StringKey, Arc<dyn Item>> {
|
||||
&mut self.map
|
||||
}
|
||||
}
|
||||
@@ -49,11 +49,11 @@ pub mod tests {
|
||||
|
||||
use crate::static_data::libraries::data_library::DataLibrary;
|
||||
use crate::static_data::libraries::item_library::ItemLibrary;
|
||||
use crate::static_data::Item;
|
||||
use crate::static_data::ItemImpl;
|
||||
use crate::static_data::{BattleItemCategory, ItemCategory};
|
||||
|
||||
fn build_item() -> Item {
|
||||
Item::new(
|
||||
fn build_item() -> ItemImpl {
|
||||
ItemImpl::new(
|
||||
&"foo".into(),
|
||||
ItemCategory::MiscItem,
|
||||
BattleItemCategory::MiscBattleItem,
|
||||
|
||||
@@ -3,7 +3,6 @@ use crate::{ValueIdentifiable, ValueIdentifier};
|
||||
|
||||
/// This library holds several misc settings for the library.
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
|
||||
pub struct LibrarySettings {
|
||||
/// A unique identifier so we know what value this is.
|
||||
identifier: ValueIdentifier,
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::{StringKey, ValueIdentifiable, ValueIdentifier};
|
||||
|
||||
/// A library to store all data for moves.
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
|
||||
|
||||
pub struct MoveLibrary {
|
||||
/// A unique identifier so we know what value this is.
|
||||
identifier: ValueIdentifier,
|
||||
@@ -26,7 +26,7 @@ impl MoveLibrary {
|
||||
}
|
||||
}
|
||||
|
||||
impl DataLibrary<'_, MoveData> for MoveLibrary {
|
||||
impl DataLibrary<MoveData> for MoveLibrary {
|
||||
fn map(&self) -> &IndexMap<StringKey, Arc<MoveData>> {
|
||||
&self.map
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::{StringKey, ValueIdentifiable, ValueIdentifier};
|
||||
|
||||
/// A library to store all data for Pokemon species.
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
|
||||
|
||||
pub struct SpeciesLibrary {
|
||||
/// A unique identifier so we know what value this is.
|
||||
identifier: ValueIdentifier,
|
||||
@@ -26,7 +26,7 @@ impl SpeciesLibrary {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> DataLibrary<'a, Species> for SpeciesLibrary {
|
||||
impl DataLibrary<Species> for SpeciesLibrary {
|
||||
fn map(&self) -> &IndexMap<StringKey, Arc<Species>> {
|
||||
&self.map
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ use crate::{ValueIdentifiable, ValueIdentifier};
|
||||
|
||||
/// The storage for all different libraries.
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
|
||||
pub struct StaticData {
|
||||
/// A unique identifier so we know what value this is.
|
||||
identifier: ValueIdentifier,
|
||||
|
||||
@@ -26,7 +26,6 @@ impl From<TypeIdentifier> for u8 {
|
||||
|
||||
/// All data related to types and effectiveness.
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
|
||||
pub struct TypeLibrary {
|
||||
/// A unique identifier so we know what value this is.
|
||||
identifier: ValueIdentifier,
|
||||
|
||||
Reference in New Issue
Block a user