First chunk of battling is now fully working, along with integration tests! 🎉
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2022-06-17 19:53:33 +02:00
parent 59cc150643
commit b6ddd1ee13
34 changed files with 1934 additions and 1293 deletions

View File

@@ -20,7 +20,7 @@ pub trait DataLibrary<'a, T: 'a> {
modifies.1.remove(index);
}
fn get(&self, key: &StringKey) -> Option<&T> {
fn get(&'a self, key: &StringKey) -> Option<&'a T> {
self.map().get(key)
}

View File

@@ -38,7 +38,7 @@ pub mod tests {
use crate::static_data::items::item_category::{BattleItemCategory, ItemCategory};
use crate::static_data::libraries::data_library::DataLibrary;
use crate::static_data::libraries::item_library::ItemLibrary;
use std::collections::HashSet;
use hashbrown::HashSet;
fn build_item() -> Item {
Item::new(

View File

@@ -4,13 +4,13 @@ use crate::StringKey;
use hashbrown::HashMap;
#[derive(Debug)]
pub struct SpeciesLibrary<'a> {
map: HashMap<StringKey, Box<Species<'a>>>,
pub struct SpeciesLibrary {
map: HashMap<StringKey, Box<Species>>,
list: Vec<StringKey>,
}
impl<'a> SpeciesLibrary<'a> {
pub fn new(capacity: usize) -> SpeciesLibrary<'a> {
impl SpeciesLibrary {
pub fn new(capacity: usize) -> SpeciesLibrary {
SpeciesLibrary {
map: HashMap::with_capacity(capacity),
list: Vec::with_capacity(capacity),
@@ -18,8 +18,8 @@ impl<'a> SpeciesLibrary<'a> {
}
}
impl<'a> DataLibrary<'a, Box<Species<'a>>> for SpeciesLibrary<'a> {
fn map(&self) -> &HashMap<StringKey, Box<Species<'a>>> {
impl<'a> DataLibrary<'a, Box<Species>> for SpeciesLibrary {
fn map(&self) -> &HashMap<StringKey, Box<Species>> {
&self.map
}
@@ -27,7 +27,7 @@ impl<'a> DataLibrary<'a, Box<Species<'a>>> for SpeciesLibrary<'a> {
&self.list
}
fn get_modify(&mut self) -> (&mut HashMap<StringKey, Box<Species<'a>>>, &mut Vec<StringKey>) {
fn get_modify(&mut self) -> (&mut HashMap<StringKey, Box<Species>>, &mut Vec<StringKey>) {
(&mut self.map, &mut self.list)
}
}
@@ -42,7 +42,7 @@ pub mod tests {
use crate::static_data::statistic_set::StatisticSet;
use hashbrown::HashSet;
fn build_species<'a>() -> Species<'a> {
fn build_species<'a>() -> Species {
Species::new(
0,
&"foo".into(),
@@ -65,7 +65,7 @@ pub mod tests {
)
}
pub fn build<'a>() -> SpeciesLibrary<'a> {
pub fn build<'a>() -> SpeciesLibrary {
let mut lib = SpeciesLibrary::new(1);
let species = build_species();
// Borrow as mut so we can insert

View File

@@ -8,9 +8,9 @@ use crate::static_data::SpeciesLibrary;
use crate::static_data::TypeLibrary;
#[derive(Debug)]
pub struct StaticData<'a> {
pub struct StaticData {
settings: LibrarySettings,
species: SpeciesLibrary<'a>,
species: SpeciesLibrary,
moves: MoveLibrary,
items: ItemLibrary,
growth_rates: GrowthRateLibrary,
@@ -19,53 +19,66 @@ pub struct StaticData<'a> {
abilities: AbilityLibrary,
}
impl<'a> StaticData<'a> {
pub fn new(
settings: LibrarySettings,
species: SpeciesLibrary<'a>,
moves: MoveLibrary,
items: ItemLibrary,
growth_rates: GrowthRateLibrary,
types: TypeLibrary,
natures: NatureLibrary,
abilities: AbilityLibrary,
) -> Self {
impl StaticData {
pub fn new(settings: LibrarySettings) -> Self {
Self {
settings,
species,
moves,
items,
growth_rates,
types,
natures,
abilities,
species: SpeciesLibrary::new(0),
moves: MoveLibrary::new(0),
items: ItemLibrary::new(0),
growth_rates: GrowthRateLibrary::new(0),
types: TypeLibrary::new(0),
natures: NatureLibrary::new(0),
abilities: AbilityLibrary::new(0),
}
}
pub fn settings(&self) -> &LibrarySettings {
&self.settings
}
pub fn species(&self) -> &SpeciesLibrary<'a> {
pub fn species(&self) -> &SpeciesLibrary {
&self.species
}
pub fn species_mut(&mut self) -> &mut SpeciesLibrary {
&mut self.species
}
pub fn moves(&self) -> &MoveLibrary {
&self.moves
}
pub fn moves_mut(&mut self) -> &mut MoveLibrary {
&mut self.moves
}
pub fn items(&self) -> &ItemLibrary {
&self.items
}
pub fn items_mut(&mut self) -> &mut ItemLibrary {
&mut self.items
}
pub fn growth_rates(&self) -> &GrowthRateLibrary {
&self.growth_rates
}
pub fn growth_rates_mut(&mut self) -> &mut GrowthRateLibrary {
&mut self.growth_rates
}
pub fn types(&self) -> &TypeLibrary {
&self.types
}
pub fn types_mut(&mut self) -> &mut TypeLibrary {
&mut self.types
}
pub fn natures(&self) -> &NatureLibrary {
&self.natures
}
pub fn natures_mut(&mut self) -> &mut NatureLibrary {
&mut self.natures
}
pub fn abilities(&self) -> &AbilityLibrary {
&self.abilities
}
pub fn abilities_mut<'a>(&'a mut self) -> &'a mut AbilityLibrary {
&mut self.abilities
}
}
#[cfg(test)]
@@ -77,7 +90,7 @@ pub mod test {
};
use crate::static_data::natures;
pub fn build<'a>() -> StaticData<'a> {
pub fn build<'a>() -> StaticData {
StaticData {
settings: LibrarySettings::new(100),
species: species_library::tests::build(),