Major amounts of progress

This commit is contained in:
2022-06-03 16:35:18 +02:00
parent c194c5d209
commit 310bf857d2
37 changed files with 1558 additions and 29 deletions

View File

@@ -1,4 +1,5 @@
#[derive(Debug)]
#[repr(u8)]
pub enum ItemCategory {
MiscItem,
Pokeball,
@@ -11,6 +12,7 @@ pub enum ItemCategory {
}
#[derive(Debug)]
#[repr(u8)]
pub enum BattleItemCategory {
Healing,
StatusHealing,

View File

@@ -4,7 +4,7 @@ use std::collections::HashMap;
#[derive(Debug)]
pub struct ItemLibrary {
map: HashMap<String, Item>,
map: HashMap<String, Box<Item>>,
list: Vec<String>,
}
@@ -17,8 +17,8 @@ impl ItemLibrary {
}
}
impl DataLibrary<'_, Item> for ItemLibrary {
fn map(&self) -> &HashMap<String, Item> {
impl DataLibrary<'_, Box<Item>> for ItemLibrary {
fn map(&self) -> &HashMap<String, Box<Item>> {
&self.map
}
@@ -26,7 +26,7 @@ impl DataLibrary<'_, Item> for ItemLibrary {
&self.list
}
fn get_modify(&mut self) -> (&mut HashMap<String, Item>, &mut Vec<String>) {
fn get_modify(&mut self) -> (&mut HashMap<String, Box<Item>>, &mut Vec<String>) {
(&mut self.map, &mut self.list)
}
}
@@ -54,7 +54,7 @@ pub mod tests {
let m = build_item();
// Borrow as mut so we can insert
let w = &mut lib;
w.add("foo", m);
w.add("foo", Box::from(m));
// Drops borrow as mut
lib

View File

@@ -4,7 +4,7 @@ use std::collections::HashMap;
#[derive(Debug)]
pub struct SpeciesLibrary<'a> {
map: HashMap<String, Species<'a>>,
map: HashMap<String, Box<Species<'a>>>,
list: Vec<String>,
}
@@ -17,8 +17,8 @@ impl<'a> SpeciesLibrary<'a> {
}
}
impl<'a> DataLibrary<'a, Species<'a>> for SpeciesLibrary<'a> {
fn map(&self) -> &HashMap<String, Species<'a>> {
impl<'a> DataLibrary<'a, Box<Species<'a>>> for SpeciesLibrary<'a> {
fn map(&self) -> &HashMap<String, Box<Species<'a>>> {
&self.map
}
@@ -26,7 +26,7 @@ impl<'a> DataLibrary<'a, Species<'a>> for SpeciesLibrary<'a> {
&self.list
}
fn get_modify(&mut self) -> (&mut HashMap<String, Species<'a>>, &mut Vec<String>) {
fn get_modify(&mut self) -> (&mut HashMap<String, Box<Species<'a>>>, &mut Vec<String>) {
(&mut self.map, &mut self.list)
}
}
@@ -69,7 +69,7 @@ pub mod tests {
let species = build_species();
// Borrow as mut so we can insert
let w = &mut lib;
w.add("foo", species);
w.add("foo", Box::from(species));
// Drops borrow as mut
lib
@@ -84,7 +84,7 @@ pub mod tests {
let mon = r.get("foo");
assert!(mon.is_some());
assert_eq!(*mon.unwrap().id(), 0_u16);
assert_eq!(mon.unwrap().name(), "foo");
assert_eq!(mon.unwrap().as_ref().name(), "foo");
assert_eq!(r.len(), 1);
}

View File

@@ -1,6 +1,6 @@
// 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(Debug)]
#[derive(Eq, PartialEq, Debug)]
pub enum Gender {
Male,
Female,

View File

@@ -19,7 +19,7 @@ impl<T> StatisticSet<T>
where
T: PrimInt,
{
pub fn get_stat(&self, stat: Statistic) -> T {
pub const fn get_stat(&self, stat: Statistic) -> T {
match stat {
Statistic::HP => self.hp,
Statistic::Attack => self.attack,