Removes derive-getters, as it was incredibly annoying in IDEs, and couldn't figure out borrow lifetimes.
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
use super::item_category::{BattleItemCategory, ItemCategory};
|
||||
use derive_getters::Getters;
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[derive(Getters, Debug)]
|
||||
#[derive(Debug)]
|
||||
pub struct Item {
|
||||
name: String,
|
||||
category: ItemCategory,
|
||||
@@ -28,6 +27,22 @@ impl Item {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
pub fn category(&self) -> ItemCategory {
|
||||
self.category
|
||||
}
|
||||
pub fn battle_category(&self) -> BattleItemCategory {
|
||||
self.battle_category
|
||||
}
|
||||
pub fn price(&self) -> i32 {
|
||||
self.price
|
||||
}
|
||||
pub fn flags(&self) -> &HashSet<String> {
|
||||
&self.flags
|
||||
}
|
||||
|
||||
pub fn has_flag(&self, key: &str) -> bool {
|
||||
self.flags.contains(key)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
#[repr(u8)]
|
||||
pub enum ItemCategory {
|
||||
MiscItem,
|
||||
@@ -11,7 +11,7 @@ pub enum ItemCategory {
|
||||
Mail,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
#[repr(u8)]
|
||||
pub enum BattleItemCategory {
|
||||
Healing,
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
use crate::defines::LevelInt;
|
||||
use derive_getters::Getters;
|
||||
|
||||
#[derive(Getters, Debug)]
|
||||
#[derive(Debug)]
|
||||
pub struct LibrarySettings {
|
||||
pub(crate) maximum_level: LevelInt,
|
||||
maximum_level: LevelInt,
|
||||
}
|
||||
|
||||
impl LibrarySettings {
|
||||
pub fn new(maximum_level: LevelInt) -> Self {
|
||||
Self { maximum_level }
|
||||
}
|
||||
|
||||
pub fn maximum_level(&self) -> LevelInt {
|
||||
self.maximum_level
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ pub mod tests {
|
||||
let r = &lib;
|
||||
let mon = r.get("foo");
|
||||
assert!(mon.is_some());
|
||||
assert_eq!(*mon.unwrap().id(), 0_u16);
|
||||
assert_eq!(mon.unwrap().id(), 0_u16);
|
||||
assert_eq!(mon.unwrap().as_ref().name(), "foo");
|
||||
assert_eq!(r.len(), 1);
|
||||
}
|
||||
|
||||
@@ -5,9 +5,8 @@ use crate::static_data::libraries::move_library::MoveLibrary;
|
||||
use crate::static_data::libraries::species_library::SpeciesLibrary;
|
||||
use crate::static_data::libraries::type_library::TypeLibrary;
|
||||
use crate::static_data::natures::NatureLibrary;
|
||||
use derive_getters::Getters;
|
||||
|
||||
#[derive(Getters, Debug)]
|
||||
#[derive(Debug)]
|
||||
pub struct StaticData<'a> {
|
||||
settings: LibrarySettings,
|
||||
species: SpeciesLibrary<'a>,
|
||||
@@ -18,6 +17,50 @@ pub struct StaticData<'a> {
|
||||
natures: NatureLibrary,
|
||||
}
|
||||
|
||||
impl<'a> StaticData<'a> {
|
||||
pub fn new(
|
||||
settings: LibrarySettings,
|
||||
species: SpeciesLibrary<'a>,
|
||||
moves: MoveLibrary,
|
||||
items: ItemLibrary,
|
||||
growth_rates: GrowthRateLibrary,
|
||||
types: TypeLibrary,
|
||||
natures: NatureLibrary,
|
||||
) -> Self {
|
||||
Self {
|
||||
settings,
|
||||
species,
|
||||
moves,
|
||||
items,
|
||||
growth_rates,
|
||||
types,
|
||||
natures,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn settings(&self) -> &LibrarySettings {
|
||||
&self.settings
|
||||
}
|
||||
pub fn species(&self) -> &SpeciesLibrary<'a> {
|
||||
&self.species
|
||||
}
|
||||
pub fn moves(&self) -> &MoveLibrary {
|
||||
&self.moves
|
||||
}
|
||||
pub fn items(&self) -> &ItemLibrary {
|
||||
&self.items
|
||||
}
|
||||
pub fn growth_rates(&self) -> &GrowthRateLibrary {
|
||||
&self.growth_rates
|
||||
}
|
||||
pub fn types(&self) -> &TypeLibrary {
|
||||
&self.types
|
||||
}
|
||||
pub fn natures(&self) -> &NatureLibrary {
|
||||
&self.natures
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod test {
|
||||
use crate::static_data::libraries::library_settings::LibrarySettings;
|
||||
@@ -29,7 +72,7 @@ pub mod test {
|
||||
|
||||
pub fn build<'a>() -> StaticData<'a> {
|
||||
StaticData {
|
||||
settings: LibrarySettings { maximum_level: 100 },
|
||||
settings: LibrarySettings::new(100),
|
||||
species: species_library::tests::build(),
|
||||
moves: move_library::tests::build(),
|
||||
items: item_library::tests::build(),
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use derive_getters::Getters;
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub enum EffectParameter {
|
||||
Bool(bool),
|
||||
@@ -8,7 +6,7 @@ pub enum EffectParameter {
|
||||
String(String),
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug, Getters)]
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub struct SecondaryEffect {
|
||||
chance: f32,
|
||||
effect_name: String,
|
||||
@@ -34,6 +32,16 @@ impl SecondaryEffect {
|
||||
parameters,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chance(&self) -> f32 {
|
||||
self.chance
|
||||
}
|
||||
pub fn effect_name(&self) -> &str {
|
||||
&self.effect_name
|
||||
}
|
||||
pub fn parameters(&self) -> &Vec<EffectParameter> {
|
||||
&self.parameters
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -3,10 +3,9 @@ use crate::static_data::species_data::ability_index::AbilityIndex;
|
||||
use crate::static_data::statistic_set::StatisticSet;
|
||||
use crate::static_data::statistics::Statistic;
|
||||
use crate::utils::random::Random;
|
||||
use derive_getters::Getters;
|
||||
use hashbrown::HashSet;
|
||||
|
||||
#[derive(Getters, Debug)]
|
||||
#[derive(Debug)]
|
||||
pub struct Form<'a> {
|
||||
name: String,
|
||||
height: f32,
|
||||
@@ -47,6 +46,37 @@ impl<'a> Form<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
pub fn height(&self) -> f32 {
|
||||
self.height
|
||||
}
|
||||
pub fn weight(&self) -> f32 {
|
||||
self.weight
|
||||
}
|
||||
pub fn base_experience(&self) -> u32 {
|
||||
self.base_experience
|
||||
}
|
||||
pub fn types(&self) -> &Vec<u8> {
|
||||
&self.types
|
||||
}
|
||||
pub fn base_stats(&self) -> StatisticSet<u16> {
|
||||
self.base_stats
|
||||
}
|
||||
pub fn abilities(&self) -> &Vec<String> {
|
||||
&self.abilities
|
||||
}
|
||||
pub fn hidden_abilities(&self) -> &Vec<String> {
|
||||
&self.hidden_abilities
|
||||
}
|
||||
pub fn moves(&self) -> &LearnableMoves<'a> {
|
||||
&self.moves
|
||||
}
|
||||
pub fn flags(&self) -> &HashSet<String> {
|
||||
&self.flags
|
||||
}
|
||||
|
||||
pub fn get_type(&self, index: usize) -> u8 {
|
||||
self.types[index]
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// 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, Debug)]
|
||||
#[derive(Eq, PartialEq, Copy, Clone, Debug)]
|
||||
pub enum Gender {
|
||||
Male,
|
||||
Female,
|
||||
Genderless,
|
||||
Genderless = 0,
|
||||
Male = 1,
|
||||
Female = 2,
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
use self::super::form::Form;
|
||||
use crate::static_data::species_data::gender::Gender;
|
||||
use crate::utils::random::Random;
|
||||
use derive_getters::Getters;
|
||||
use hashbrown::{HashMap, HashSet};
|
||||
|
||||
#[derive(Debug, Getters)]
|
||||
#[derive(Debug)]
|
||||
pub struct Species<'a> {
|
||||
id: u16,
|
||||
name: String,
|
||||
@@ -37,6 +36,27 @@ impl<'a> Species<'a> {
|
||||
flags,
|
||||
}
|
||||
}
|
||||
pub fn id(&self) -> u16 {
|
||||
self.id
|
||||
}
|
||||
pub fn name(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
pub fn gender_rate(&self) -> f32 {
|
||||
self.gender_rate
|
||||
}
|
||||
pub fn growth_rate(&self) -> &str {
|
||||
&self.growth_rate
|
||||
}
|
||||
pub fn capture_rate(&self) -> u8 {
|
||||
self.capture_rate
|
||||
}
|
||||
pub fn forms(&self) -> &HashMap<String, Form<'a>> {
|
||||
&self.forms
|
||||
}
|
||||
pub fn flags(&self) -> &HashSet<String> {
|
||||
&self.flags
|
||||
}
|
||||
|
||||
pub fn add_form(&mut self, id: String, form: Form<'a>) {
|
||||
self.forms.insert(id, form);
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use super::statistics::Statistic;
|
||||
use derive_getters::Getters;
|
||||
use num_traits::PrimInt;
|
||||
|
||||
#[derive(Default, Eq, PartialEq, Copy, Clone, Debug, Getters)]
|
||||
#[derive(Default, Eq, PartialEq, Copy, Clone, Debug)]
|
||||
pub struct StatisticSet<T>
|
||||
where
|
||||
T: PrimInt,
|
||||
@@ -37,6 +36,25 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub fn hp(&self) -> T {
|
||||
self.hp
|
||||
}
|
||||
pub fn attack(&self) -> T {
|
||||
self.attack
|
||||
}
|
||||
pub fn defense(&self) -> T {
|
||||
self.defense
|
||||
}
|
||||
pub fn special_attack(&self) -> T {
|
||||
self.special_attack
|
||||
}
|
||||
pub fn special_defense(&self) -> T {
|
||||
self.special_defense
|
||||
}
|
||||
pub fn speed(&self) -> T {
|
||||
self.speed
|
||||
}
|
||||
|
||||
pub const fn get_stat(&self, stat: Statistic) -> T {
|
||||
match stat {
|
||||
Statistic::HP => self.hp,
|
||||
@@ -82,7 +100,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Eq, PartialEq, Copy, Clone, Debug, Getters)]
|
||||
#[derive(Default, Eq, PartialEq, Copy, Clone, Debug)]
|
||||
pub struct ClampedStatisticSet<T, const MIN: i64, const MAX: i64>
|
||||
where
|
||||
T: PrimInt,
|
||||
@@ -99,6 +117,25 @@ impl<T, const MIN: i64, const MAX: i64> ClampedStatisticSet<T, MIN, MAX>
|
||||
where
|
||||
T: PrimInt,
|
||||
{
|
||||
pub fn hp(&self) -> T {
|
||||
self.hp
|
||||
}
|
||||
pub fn attack(&self) -> T {
|
||||
self.attack
|
||||
}
|
||||
pub fn defense(&self) -> T {
|
||||
self.defense
|
||||
}
|
||||
pub fn special_attack(&self) -> T {
|
||||
self.special_attack
|
||||
}
|
||||
pub fn special_defense(&self) -> T {
|
||||
self.special_defense
|
||||
}
|
||||
pub fn speed(&self) -> T {
|
||||
self.speed
|
||||
}
|
||||
|
||||
pub const fn get_stat(&self, stat: Statistic) -> T {
|
||||
match stat {
|
||||
Statistic::HP => self.hp,
|
||||
|
||||
Reference in New Issue
Block a user