From 717fcdefda593c61fe3e22199b71062c3e6d8d1b Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 1 Jul 2022 17:52:00 +0200 Subject: [PATCH] Finished documenting all public interfaces. --- src/lib.rs | 2 +- src/static_data/species_data/ability.rs | 8 +++++ src/static_data/species_data/ability_index.rs | 4 +++ src/static_data/species_data/gender.rs | 9 ++++-- .../species_data/learnable_moves.rs | 12 +++++-- src/static_data/species_data/species.rs | 31 +++++++++++++++++-- src/static_data/statistics.rs | 7 +++++ 7 files changed, 66 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 27d6e60..fc31dad 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ // The too many arguments is annoying, especially for when we create constructor, disable. #![allow(clippy::too_many_arguments, clippy::needless_range_loop)] #![allow(clippy::not_unsafe_ptr_arg_deref)] -#![warn(missing_docs)] +#![deny(missing_docs)] #![warn(clippy::missing_docs_in_private_items)] #![feature(test)] #![feature(bench_black_box)] diff --git a/src/static_data/species_data/ability.rs b/src/static_data/species_data/ability.rs index db534e6..47d0187 100644 --- a/src/static_data/species_data/ability.rs +++ b/src/static_data/species_data/ability.rs @@ -1,14 +1,19 @@ use crate::static_data::EffectParameter; use crate::StringKey; +/// An ability is a passive effect in battle that is attached to a Pokemon. #[derive(Debug)] pub struct Ability { + /// The name of the ability. name: StringKey, + /// The name of the script effect of the ability. effect: StringKey, + /// The parameters for the script effect of the ability. parameters: Vec, } impl Ability { + /// Instantiates a new ability. pub fn new(name: &StringKey, effect: &StringKey, parameters: Vec) -> Self { Self { name: name.clone(), @@ -17,12 +22,15 @@ impl Ability { } } + /// The name of the ability. pub fn name(&self) -> &StringKey { &self.name } + /// The name of the script effect of the ability. pub fn effect(&self) -> &StringKey { &self.effect } + /// The parameters for the script effect of the ability. pub fn parameters(&self) -> &Vec { &self.parameters } diff --git a/src/static_data/species_data/ability_index.rs b/src/static_data/species_data/ability_index.rs index 372d4f4..d5fda1f 100644 --- a/src/static_data/species_data/ability_index.rs +++ b/src/static_data/species_data/ability_index.rs @@ -1,5 +1,9 @@ +/// An ability index allows us to find an ability on a form. It combines a bool for whether the +/// ability is hidden or not, and then an index of the ability. #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct AbilityIndex { + /// Whether or not the ability we're referring to is a hidden ability. pub hidden: bool, + /// The index of the ability. pub index: u8, } diff --git a/src/static_data/species_data/gender.rs b/src/static_data/species_data/gender.rs index 3ab8e40..d47e283 100644 --- a/src/static_data/species_data/gender.rs +++ b/src/static_data/species_data/gender.rs @@ -1,8 +1,13 @@ -// Required for standard pokemon functions, but somewhat controversial nowadays. Consider adding a feature -// that allows for a more progressive gender system for those that want it? +/// Gender is a Pokemon characteristic. +/// +/// Required for standard pokemon functions, but somewhat controversial nowadays. Consider adding a feature +/// that allows for a more progressive gender system for those that want it? #[derive(Eq, PartialEq, Copy, Clone, Debug)] pub enum Gender { + /// The Pokemon has no gender. Genderless = 0, + /// The Pokemon is male. Male = 1, + /// The Pokemon is female. Female = 2, } diff --git a/src/static_data/species_data/learnable_moves.rs b/src/static_data/species_data/learnable_moves.rs index e30d8a1..e913d69 100644 --- a/src/static_data/species_data/learnable_moves.rs +++ b/src/static_data/species_data/learnable_moves.rs @@ -1,19 +1,25 @@ -use crate::defines::LevelInt; -use crate::StringKey; use hashbrown::hash_map::Entry::{Occupied, Vacant}; use hashbrown::HashMap; +use crate::defines::LevelInt; +use crate::StringKey; + +/// This allows for storage of the moves a Pokemon can learn. #[derive(Default, PartialEq, Eq, Debug)] pub struct LearnableMoves { + /// A map of the moves a Pokemon can learn per level. learned_by_level: HashMap>, + /// A list of the distinct moves a Pokemon can learn through leveling up. distinct_level_moves: Vec, } impl LearnableMoves { + /// Instantiates a new Learnable Moves. pub fn new() -> LearnableMoves { LearnableMoves::default() } + /// Adds a new level move the Pokemon can learn. pub fn add_level_move(&mut self, level: LevelInt, m: &StringKey) { match self.learned_by_level.entry(level) { Occupied(x) => { @@ -28,10 +34,12 @@ impl LearnableMoves { } } + /// Gets all moves a Pokemon can learn when leveling up to a specific level. pub fn get_learned_by_level(&self, level: LevelInt) -> Option<&Vec> { self.learned_by_level.get(&level) } + /// Gets the distinct moves a Pokemon can learn through leveling up. pub fn get_distinct_level_moves(&self) -> &Vec { &self.distinct_level_moves } diff --git a/src/static_data/species_data/species.rs b/src/static_data/species_data/species.rs index 0724eed..fdc6dfd 100644 --- a/src/static_data/species_data/species.rs +++ b/src/static_data/species_data/species.rs @@ -1,24 +1,37 @@ +use std::lazy::SyncLazy; + +use hashbrown::{HashMap, HashSet}; + use crate::static_data::Form; use crate::static_data::Gender; use crate::Random; use crate::StringKey; -use hashbrown::{HashMap, HashSet}; -use std::lazy::SyncLazy; +/// The data belonging to a Pokemon with certain characteristics. #[derive(Debug)] pub struct Species { + /// The national dex identifier of the Pokemon. id: u16, + /// The name of the Pokemon. name: StringKey, + /// The chance between 0.0 and 1.0 that a Pokemon is female. gender_rate: f32, + /// How much experience is required for a level. growth_rate: StringKey, + /// How hard it is to capture a Pokemon. 255 means this will be always caught, 0 means this is + /// uncatchable. capture_rate: u8, + /// The forms that belong to this Pokemon. forms: HashMap, + /// The arbitrary flags that can be set on a Pokemon for script use. flags: HashSet, } +/// A cached String Key to get the default form. static DEFAULT_KEY: SyncLazy = SyncLazy::new(|| StringKey::new("default")); impl Species { + /// Creates a new species. pub fn new( id: u16, name: &StringKey, @@ -40,40 +53,53 @@ impl Species { flags, } } + + /// The national dex identifier of the Pokemon. pub fn id(&self) -> u16 { self.id } + /// The name of the Pokemon. pub fn name(&self) -> &StringKey { &self.name } + /// The chance between 0.0 and 1.0 that a Pokemon is female. pub fn gender_rate(&self) -> f32 { self.gender_rate } + /// How much experience is required for a level. pub fn growth_rate(&self) -> &StringKey { &self.growth_rate } + /// How hard it is to capture a Pokemon. 255 means this will be always caught, 0 means this is + /// uncatchable. pub fn capture_rate(&self) -> u8 { self.capture_rate } + /// The forms that belong to this Pokemon. pub fn forms(&self) -> &HashMap { &self.forms } + /// The arbitrary flags that can be set on a Pokemon for script use. pub fn flags(&self) -> &HashSet { &self.flags } + /// Adds a new form to the species. pub fn add_form(&mut self, id: StringKey, form: Form) { self.forms.insert(id, form); } + /// Gets a form by name. pub fn get_form(&self, id: &StringKey) -> Option<&Form> { self.forms.get(id) } + /// Gets the form the Pokemon will have by default, if no other form is specified. pub fn get_default_form(&self) -> &Form { self.forms.get(&DEFAULT_KEY).unwrap() } + /// Gets a random gender. pub fn get_random_gender(&self, rand: &mut Random) -> Gender { if self.gender_rate < 0.0 { Gender::Genderless @@ -84,6 +110,7 @@ impl Species { } } + /// Check whether the Pokemon has a specific flag set. pub fn has_flag(&self, key: &StringKey) -> bool { self.flags.contains(key) } diff --git a/src/static_data/statistics.rs b/src/static_data/statistics.rs index 5045d3a..c0ce8e3 100644 --- a/src/static_data/statistics.rs +++ b/src/static_data/statistics.rs @@ -1,13 +1,20 @@ #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; +/// Stats are numerical values on Pokemon that are used in battle. #[derive(Debug, PartialEq, Eq, Copy, Clone)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum Statistic { + /// Health Points determine how much damage a Pokemon can receive before fainting. HP, + /// Attack determines how much damage a Pokemon deals when using a physical attack. Attack, + /// Defense determines how much damage a Pokemon receives when it is hit by a physical attack. Defense, + /// Special Attack determines how much damage a Pokemon deals when using a special attack. SpecialAttack, + /// Special Defense determines how much damage a Pokemon receives when it is hit by a special attack. SpecialDefense, + /// Speed determines the order that a Pokemon can act in battle. Speed, }