Remove lifetime mess, replace a lot of code with Arc instead of borrows.
Some checks failed
continuous-integration/drone/push Build is failing

This cleans up the codebase massively, and allows me to maintain some semblance of sanity.
This commit is contained in:
2022-08-20 13:17:20 +02:00
parent 2d4253e155
commit 55cc0906c9
34 changed files with 320 additions and 366 deletions

View File

@@ -115,10 +115,7 @@ pub fn load_items(path: &String, lib: &mut ItemLibrary) {
}
}
lib.add(
&name,
Box::new(Item::new(&name, category, battle_category, price as i32, flags)),
);
lib.add(&name, Item::new(&name, category, battle_category, price as i32, flags));
}
}
@@ -161,7 +158,7 @@ pub fn load_abilities(path: &String, ability_library: &mut AbilityLibrary) {
}
}
ability_library.add(&name, Box::new(Ability::new(&name, &effect, parameters)));
ability_library.add(&name, Ability::new(&name, &effect, parameters));
}
}
@@ -262,7 +259,7 @@ pub fn load_species(path: &String, library: &mut StaticData) {
let default_form_value = &forms["default"];
let default_form = parse_form("default".into(), default_form_value, library);
let species = Box::new(Species::new(
let species = Species::new(
id as u16,
&name,
gender_rate as f32,
@@ -270,7 +267,7 @@ pub fn load_species(path: &String, library: &mut StaticData) {
catch_rate as u8,
default_form,
Default::default(),
));
);
library.species_mut().add(&name, species);
}
}

View File

@@ -43,13 +43,13 @@ struct TestPokemon {
}
impl TestCase {
pub fn run_test(&self, library: &DynamicLibrary) {
pub fn run_test(&self, library: Arc<DynamicLibrary>) {
let mut parties = Vec::new();
for party in &self.battle_setup.parties {
let pokemon = party
.pokemon
.iter()
.map(|a| Some(Arc::new(a.to_pokemon(library))))
.map(|a| Some(Arc::new(a.to_pokemon(library.clone()))))
.collect();
let indices = party.indices.iter().map(|a| (a[0], a[1])).collect();
parties.push((Arc::new(PokemonParty::new_from_vec(pokemon)), indices));
@@ -73,7 +73,7 @@ impl TestCase {
}
impl TestPokemon {
fn to_pokemon<'a>(&'a self, library: &'a DynamicLibrary) -> Pokemon {
fn to_pokemon(&self, library: Arc<DynamicLibrary>) -> Pokemon {
let mut builder = PokemonBuilder::new(library, StringKey::new(self.species.as_str()), self.level);
for move_name in &self.moves {
builder = builder.learn_move(StringKey::new(move_name));