Initial work on adding documentation, reorganises modules
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-06-19 21:34:08 +02:00
parent 715f16e2b8
commit 314e9dbe1a
49 changed files with 806 additions and 473 deletions

View File

@@ -1,5 +1,9 @@
use crate::defines::LevelInt;
use crate::static_data::growth_rates::growth_rate::GrowthRate;
pub trait GrowthRate {
fn calculate_level(&self, experience: u32) -> LevelInt;
fn calculate_experience(&self, level: LevelInt) -> u32;
}
pub struct LookupGrowthRate {
experience: Vec<u32>,

View File

@@ -1,6 +0,0 @@
use crate::defines::LevelInt;
pub trait GrowthRate {
fn calculate_level(&self, experience: u32) -> LevelInt;
fn calculate_experience(&self, level: LevelInt) -> u32;
}

View File

@@ -1,5 +0,0 @@
pub mod growth_rate;
pub mod lookup_growth_rate;
pub use growth_rate::*;
pub use lookup_growth_rate::*;

View File

@@ -1,6 +1,33 @@
use super::item_category::{BattleItemCategory, ItemCategory};
use crate::StringKey;
use hashbrown::HashSet;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use crate::StringKey;
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(u8)]
pub enum ItemCategory {
MiscItem,
Pokeball,
Medicine,
Berry,
TMHM,
FormChanger,
KeyItem,
Mail,
}
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(u8)]
pub enum BattleItemCategory {
None,
Healing,
StatusHealing,
Pokeball,
MiscBattleItem,
}
#[derive(Debug)]
pub struct Item {

View File

@@ -1,27 +0,0 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(u8)]
pub enum ItemCategory {
MiscItem,
Pokeball,
Medicine,
Berry,
TMHM,
FormChanger,
KeyItem,
Mail,
}
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(u8)]
pub enum BattleItemCategory {
None,
Healing,
StatusHealing,
Pokeball,
MiscBattleItem,
}

View File

@@ -1,5 +0,0 @@
pub mod item;
pub mod item_category;
pub use item::*;
pub use item_category::*;

View File

@@ -1,7 +1,8 @@
use hashbrown::HashMap;
use crate::static_data::Ability;
use crate::static_data::DataLibrary;
use crate::StringKey;
use hashbrown::HashMap;
#[derive(Debug)]
pub struct AbilityLibrary {
@@ -34,9 +35,9 @@ impl DataLibrary<'_, Box<Ability>> for AbilityLibrary {
#[cfg(test)]
pub mod tests {
use crate::static_data::libraries::ability_library::AbilityLibrary;
use crate::static_data::libraries::data_library::DataLibrary;
use crate::static_data::species_data::ability::Ability;
use crate::static_data::Ability;
use crate::static_data::AbilityLibrary;
use crate::static_data::DataLibrary;
use crate::StringKey;
pub fn build() -> AbilityLibrary {

View File

@@ -1,9 +1,11 @@
use std::fmt;
use std::fmt::{Debug, Formatter};
use hashbrown::HashMap;
use crate::defines::LevelInt;
use crate::static_data::GrowthRate;
use crate::StringKey;
use hashbrown::HashMap;
use std::fmt;
use std::fmt::{Debug, Formatter};
pub struct GrowthRateLibrary {
growth_rates: HashMap<StringKey, Box<dyn GrowthRate>>,
@@ -35,7 +37,7 @@ impl Debug for GrowthRateLibrary {
#[cfg(test)]
pub mod tests {
use crate::static_data::growth_rates::lookup_growth_rate::LookupGrowthRate;
use crate::static_data::growth_rates::LookupGrowthRate;
use crate::static_data::libraries::growth_rate_library::GrowthRateLibrary;
pub fn build() -> GrowthRateLibrary {

View File

@@ -1,7 +1,8 @@
use hashbrown::HashMap;
use crate::static_data::DataLibrary;
use crate::static_data::Item;
use crate::StringKey;
use hashbrown::HashMap;
#[derive(Debug)]
pub struct ItemLibrary {
@@ -34,11 +35,12 @@ impl DataLibrary<'_, Box<Item>> for ItemLibrary {
#[cfg(test)]
pub mod tests {
use crate::static_data::items::item::Item;
use crate::static_data::items::item_category::{BattleItemCategory, ItemCategory};
use hashbrown::HashSet;
use crate::static_data::libraries::data_library::DataLibrary;
use crate::static_data::libraries::item_library::ItemLibrary;
use hashbrown::HashSet;
use crate::static_data::Item;
use crate::static_data::{BattleItemCategory, ItemCategory};
fn build_item() -> Item {
Item::new(

View File

@@ -1,19 +1,28 @@
pub mod ability_library;
pub mod data_library;
pub mod growth_rate_library;
pub mod item_library;
pub mod library_settings;
pub mod move_library;
pub mod species_library;
pub mod static_data;
pub mod type_library;
#[doc(inline)]
pub use ability_library::AbilityLibrary;
#[doc(inline)]
pub use data_library::DataLibrary;
#[doc(inline)]
pub use growth_rate_library::GrowthRateLibrary;
#[doc(inline)]
pub use item_library::ItemLibrary;
#[doc(inline)]
pub use library_settings::LibrarySettings;
#[doc(inline)]
pub use move_library::MoveLibrary;
#[doc(inline)]
pub use species_library::SpeciesLibrary;
#[doc(inline)]
pub use static_data::StaticData;
#[doc(inline)]
pub use type_library::TypeLibrary;
mod ability_library;
mod data_library;
mod growth_rate_library;
mod item_library;
mod library_settings;
mod move_library;
mod species_library;
pub(crate) mod static_data;
mod type_library;

View File

@@ -1,7 +1,8 @@
use hashbrown::HashMap;
use crate::static_data::DataLibrary;
use crate::static_data::MoveData;
use crate::StringKey;
use hashbrown::HashMap;
#[derive(Debug)]
pub struct MoveLibrary {
@@ -34,11 +35,12 @@ impl DataLibrary<'_, MoveData> for MoveLibrary {
#[cfg(test)]
pub mod tests {
use hashbrown::HashSet;
use crate::static_data::libraries::data_library::DataLibrary;
use crate::static_data::libraries::move_library::MoveLibrary;
use crate::static_data::moves::move_data::{MoveCategory, MoveData, MoveTarget};
use crate::static_data::{MoveCategory, MoveData, MoveTarget};
use crate::StringKey;
use hashbrown::HashSet;
fn build_move() -> MoveData {
MoveData::new(

View File

@@ -1,7 +1,8 @@
use hashbrown::HashMap;
use crate::static_data::DataLibrary;
use crate::static_data::Species;
use crate::StringKey;
use hashbrown::HashMap;
#[derive(Debug)]
pub struct SpeciesLibrary {
@@ -34,13 +35,14 @@ impl<'a> DataLibrary<'a, Box<Species>> for SpeciesLibrary {
#[cfg(test)]
pub mod tests {
use hashbrown::HashSet;
use crate::static_data::libraries::data_library::DataLibrary;
use crate::static_data::libraries::species_library::SpeciesLibrary;
use crate::static_data::species_data::form::Form;
use crate::static_data::species_data::learnable_moves::LearnableMoves;
use crate::static_data::species_data::species::Species;
use crate::static_data::Form;
use crate::static_data::LearnableMoves;
use crate::static_data::Species;
use crate::static_data::StaticStatisticSet;
use hashbrown::HashSet;
fn build_species() -> Species {
Species::new(

View File

@@ -1,17 +1,25 @@
pub mod growth_rates;
pub mod items;
pub mod libraries;
pub mod moves;
pub mod natures;
pub mod species_data;
pub mod statistic_set;
pub mod statistics;
#[doc(inline)]
pub use growth_rates::*;
#[doc(inline)]
pub use items::*;
#[doc(inline)]
pub use libraries::*;
#[doc(inline)]
pub use moves::*;
#[doc(inline)]
pub use natures::*;
#[doc(inline)]
pub use species_data::*;
#[doc(inline)]
pub use statistic_set::*;
#[doc(inline)]
pub use statistics::*;
mod growth_rates;
mod items;
pub(crate) mod libraries;
mod moves;
mod natures;
mod species_data;
mod statistic_set;
mod statistics;

View File

@@ -1,9 +1,7 @@
pub mod move_data;
pub mod secondary_effect;
#[doc(inline)]
pub use move_data::*;
#[doc(inline)]
pub use secondary_effect::*;
pub use move_data::MoveCategory;
pub use move_data::MoveData;
pub use move_data::MoveTarget;
pub use secondary_effect::EffectParameter;
pub use secondary_effect::SecondaryEffect;
mod move_data;
mod secondary_effect;

View File

@@ -1,13 +1,19 @@
pub mod ability;
pub mod ability_index;
pub mod form;
pub mod gender;
pub mod learnable_moves;
pub mod species;
#[doc(inline)]
pub use ability::Ability;
#[doc(inline)]
pub use ability_index::AbilityIndex;
#[doc(inline)]
pub use form::Form;
#[doc(inline)]
pub use gender::Gender;
#[doc(inline)]
pub use learnable_moves::LearnableMoves;
#[doc(inline)]
pub use species::Species;
mod ability;
mod ability_index;
mod form;
mod gender;
mod learnable_moves;
mod species;

View File

@@ -1,18 +1,30 @@
use super::statistics::Statistic;
use atomic_prim_traits::AtomicInt;
use num_traits::{clamp, NumCast, PrimInt};
use std::sync::atomic::Ordering;
use atomic_prim_traits::AtomicInt;
use num_traits::{clamp, NumCast, PrimInt};
use super::statistics::Statistic;
/// A collection of every individual stat. This set can hold any value that is valid for its integer
/// type, and can be modified at will.
///
/// As all data in this type is atomic, threaded access to this struct is completely legal.
#[derive(Default, Eq, PartialEq, Clone, Debug)]
pub struct StatisticSet<T>
where
T: AtomicInt,
{
/// The health point stat value.
hp: T,
/// The physical attack stat value.
attack: T,
/// The physical defense stat value.
defense: T,
/// The special attack stat value.
special_attack: T,
/// The special defense stat value.
special_defense: T,
/// The speed stat value.
speed: T,
}
@@ -20,6 +32,7 @@ impl<T> StatisticSet<T>
where
T: AtomicInt,
{
/// Creates a new statistic set with given stats.
pub fn new(
hp: T::Prim,
attack: T::Prim,
@@ -38,25 +51,32 @@ where
}
}
/// The health point stat value.
pub fn hp(&self) -> T::Prim {
self.hp.load(Ordering::Relaxed)
}
/// The physical attack stat value.
pub fn attack(&self) -> T::Prim {
self.attack.load(Ordering::Relaxed)
}
/// The physical defense stat value.
pub fn defense(&self) -> T::Prim {
self.defense.load(Ordering::Relaxed)
}
/// The special attack stat value.
pub fn special_attack(&self) -> T::Prim {
self.special_attack.load(Ordering::Relaxed)
}
/// The special defense stat value.
pub fn special_defense(&self) -> T::Prim {
self.special_defense.load(Ordering::Relaxed)
}
/// The speed stat value.
pub fn speed(&self) -> T::Prim {
self.speed.load(Ordering::Relaxed)
}
/// Get the value of a specific stat
pub fn get_stat(&self, stat: Statistic) -> T::Prim {
match stat {
Statistic::HP => self.hp.load(Ordering::Relaxed),
@@ -68,6 +88,7 @@ where
}
}
/// Modify the value of a specific stat.
pub fn set_stat(&self, stat: Statistic, value: T::Prim) {
match stat {
Statistic::HP => self.hp.store(value, Ordering::SeqCst),
@@ -79,6 +100,7 @@ where
}
}
/// Increase the value of a given stat by a value.
pub fn increase_stat(&self, stat: Statistic, value: T::Prim) {
match stat {
Statistic::HP => self.hp.fetch_add(value, Ordering::SeqCst),
@@ -90,6 +112,7 @@ where
};
}
/// Decrease the value of a given stat by a value.
pub fn decrease_stat(&self, stat: Statistic, value: T::Prim) {
match stat {
Statistic::HP => self.hp.fetch_sub(value, Ordering::SeqCst),
@@ -102,16 +125,25 @@ where
}
}
/// A collection of statistics that can not be modified after creation.
///
/// As no modifications happen, this struct does not use atomics.
#[derive(Default, Eq, PartialEq, Clone, Debug)]
pub struct StaticStatisticSet<T>
where
T: PrimInt,
{
/// The health point stat value.
hp: T,
/// The physical attack stat value.
attack: T,
/// The physical defense stat value.
defense: T,
/// The special attack stat value.
special_attack: T,
/// The special defense stat value.
special_defense: T,
/// The speed stat value.
speed: T,
}
@@ -119,6 +151,7 @@ impl<T> StaticStatisticSet<T>
where
T: PrimInt,
{
/// Create a new static statistic set.
pub const fn new(hp: T, attack: T, defense: T, special_attack: T, special_defense: T, speed: T) -> Self {
Self {
hp,
@@ -130,25 +163,32 @@ where
}
}
/// The health point stat value.=
pub const fn hp(&self) -> T {
self.hp
}
/// The physical attack stat value.
pub const fn attack(&self) -> T {
self.attack
}
/// The physical defense stat value.
pub const fn defense(&self) -> T {
self.defense
}
/// The special attack stat value.
pub const fn special_attack(&self) -> T {
self.special_attack
}
/// The special defense stat value.
pub const fn special_defense(&self) -> T {
self.special_defense
}
/// The speed stat value.
pub const fn speed(&self) -> T {
self.speed
}
/// Get the value of a specific stat
pub const fn get_stat(&self, stat: Statistic) -> T {
match stat {
Statistic::HP => self.hp,
@@ -166,14 +206,22 @@ pub struct ClampedStatisticSet<T, const MIN: i64, const MAX: i64>
where
T: AtomicInt,
{
/// The health point stat value.
hp: T,
/// The physical attack stat value.
attack: T,
/// The physical defense stat value.
defense: T,
/// The special attack stat value.
special_attack: T,
/// The special defense stat value.
special_defense: T,
/// The speed stat value.
speed: T,
}
/// A clamped statistic set is a collection of each statistics that can be modified, but that will
/// always remain between two compile time constant values (Min, Max).
impl<T, const MIN: i64, const MAX: i64> ClampedStatisticSet<T, MIN, MAX>
where
T: AtomicInt,
@@ -302,9 +350,10 @@ where
#[cfg(test)]
mod tests {
use super::*;
use std::sync::atomic::AtomicI32;
use super::*;
#[test]
fn create_get_values() {
let set = StatisticSet::<AtomicI32>::new(1, 2, 3, 4, 5, 6);