Loads of cleanup
Some checks reported errors
continuous-integration/drone/push Build was killed

This commit is contained in:
2022-11-27 17:29:29 +01:00
parent aa3ceaed3e
commit efd1acdfa5
45 changed files with 259 additions and 162 deletions

View File

@@ -1,6 +1,8 @@
use hashbrown::HashSet;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::any::Any;
use std::fmt::Debug;
use crate::{StringKey, ValueIdentifiable, ValueIdentifier};
@@ -44,10 +46,26 @@ pub enum BattleItemCategory {
MiscBattleItem,
}
/// An item is an object which the player can pick up, keep in their Bag, and use in some manner
pub trait Item: ValueIdentifiable + Debug + Any {
/// The name of the item.
fn name(&self) -> &StringKey;
/// Which bag slot items are stored in.
fn category(&self) -> ItemCategory;
/// How the item is categorized when in battle.
fn battle_category(&self) -> BattleItemCategory;
/// The buying value of the item.
fn price(&self) -> i32;
/// A set of arbitrary flags that can be set on the item.
fn flags(&self) -> &HashSet<StringKey>;
/// Checks whether the item has a specific flag.
fn has_flag(&self, key: &StringKey) -> bool;
}
/// An item is an object which the player can pick up, keep in their Bag, and use in some manner
#[derive(Debug)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub struct Item {
pub struct ItemImpl {
/// A unique identifier so we know what value this is.
identifier: ValueIdentifier,
/// The name of the item.
@@ -62,7 +80,7 @@ pub struct Item {
flags: HashSet<StringKey>,
}
impl Item {
impl ItemImpl {
/// Instantiates an item.
pub fn new(
name: &StringKey,
@@ -70,8 +88,8 @@ impl Item {
battle_category: BattleItemCategory,
price: i32,
flags: HashSet<StringKey>,
) -> Item {
Item {
) -> ItemImpl {
ItemImpl {
identifier: Default::default(),
name: name.clone(),
category,
@@ -80,35 +98,37 @@ impl Item {
flags,
}
}
}
impl Item for ItemImpl {
/// The name of the item.
pub fn name(&self) -> &StringKey {
fn name(&self) -> &StringKey {
&self.name
}
/// Which bag slot items are stored in.
pub fn category(&self) -> ItemCategory {
fn category(&self) -> ItemCategory {
self.category
}
/// How the item is categorized when in battle.
pub fn battle_category(&self) -> BattleItemCategory {
fn battle_category(&self) -> BattleItemCategory {
self.battle_category
}
/// The buying value of the item.
pub fn price(&self) -> i32 {
fn price(&self) -> i32 {
self.price
}
/// A set of arbitrary flags that can be set on the item.
pub fn flags(&self) -> &HashSet<StringKey> {
fn flags(&self) -> &HashSet<StringKey> {
&self.flags
}
/// Checks whether the item has a specific flag.
pub fn has_flag(&self, key: &StringKey) -> bool {
fn has_flag(&self, key: &StringKey) -> bool {
self.flags.contains(key)
}
}
impl ValueIdentifiable for Item {
impl ValueIdentifiable for ItemImpl {
fn value_identifier(&self) -> ValueIdentifier {
self.identifier
}

View File

@@ -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
}

View File

@@ -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.

View File

@@ -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,

View File

@@ -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,

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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,

View File

@@ -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,

View File

@@ -36,8 +36,7 @@ mod statistics;
/// A parameter for an effect. This is basically a simple way to dynamically store multiple different
/// primitives on data.
#[derive(PartialEq, Debug)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
#[derive(PartialEq, Debug, Clone)]
pub enum EffectParameter {
/// A boolean value.
Bool(ValueIdentifier, bool),

View File

@@ -61,7 +61,6 @@ pub enum MoveTarget {
/// A move is the skill Pokémon primarily use in battle. This is the data related to that.
#[derive(PartialEq, Debug)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub struct MoveData {
/// A unique identifier so we know what value this is.
identifier: ValueIdentifier,

View File

@@ -11,7 +11,6 @@ use crate::{Random, ValueIdentifiable, ValueIdentifier};
/// The data belonging to a Pokemon with certain characteristics.
#[derive(Debug)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub struct Species {
/// A unique identifier so we know what value this is.
identifier: ValueIdentifier,

View File

@@ -12,7 +12,6 @@ use super::statistics::Statistic;
///
/// As all data in this type is atomic, threaded access to this struct is completely legal.
#[derive(Default, Debug)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub struct StatisticSet<T>
where
T: PrimitiveAtom,
@@ -236,7 +235,6 @@ where
/// A clamped statistic set holds the 6 normal stats for a Pokemon, but ensures it always remains
/// between two values (inclusive on the two values).
#[derive(Default, Debug)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub struct ClampedStatisticSet<T, const MIN: i64, const MAX: i64>
where
T: PrimitiveAtom,