Reworks static library initialiser
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-12-24 12:48:00 +01:00
parent 02e3d7ecc7
commit efdaf730e6
3 changed files with 107 additions and 46 deletions

View File

@@ -9,8 +9,24 @@ use std::ptr::drop_in_place;
#[no_mangle]
unsafe extern "C" fn static_data_new(
settings: OwnedPtr<Box<dyn LibrarySettings>>,
species: OwnedPtr<Box<dyn SpeciesLibrary>>,
moves: OwnedPtr<Box<dyn MoveLibrary>>,
items: OwnedPtr<Box<dyn ItemLibrary>>,
growth_rates: OwnedPtr<Box<dyn GrowthRateLibrary>>,
types: OwnedPtr<Box<dyn TypeLibrary>>,
natures: OwnedPtr<Box<dyn NatureLibrary>>,
abilities: OwnedPtr<Box<dyn AbilityLibrary>>,
) -> IdentifiablePointer<Box<dyn StaticData>> {
let b: Box<dyn StaticData> = Box::new(StaticDataImpl::new(*Box::from_raw(settings)));
let b: Box<dyn StaticData> = Box::new(StaticDataImpl::new(
*Box::from_raw(settings),
*Box::from_raw(species),
*Box::from_raw(moves),
*Box::from_raw(items),
*Box::from_raw(growth_rates),
*Box::from_raw(types),
*Box::from_raw(natures),
*Box::from_raw(abilities),
));
b.into()
}

View File

@@ -1,11 +1,11 @@
use crate::static_data::AbilityLibrary;
use crate::static_data::GrowthRateLibrary;
use crate::static_data::ItemLibrary;
use crate::static_data::LibrarySettings;
use crate::static_data::MoveLibrary;
use crate::static_data::NatureLibrary;
use crate::static_data::SpeciesLibrary;
use crate::static_data::TypeLibrary;
use crate::static_data::{AbilityLibrary, AbilityLibraryImpl, ItemLibraryImpl, MoveLibraryImpl, SpeciesLibraryImpl};
use crate::static_data::{GrowthRateLibrary, GrowthRateLibraryImpl};
use crate::static_data::{ItemLibrary, NatureLibraryImpl};
use crate::static_data::{LibrarySettings, TypeLibraryImpl};
use crate::{ValueIdentifiable, ValueIdentifier};
use std::fmt::Debug;
@@ -69,17 +69,26 @@ pub struct StaticDataImpl {
impl StaticDataImpl {
/// Instantiates a new data collection.
pub fn new(settings: Box<dyn LibrarySettings>) -> Self {
pub fn new(
settings: Box<dyn LibrarySettings>,
species: Box<dyn SpeciesLibrary>,
moves: Box<dyn MoveLibrary>,
items: Box<dyn ItemLibrary>,
growth_rates: Box<dyn GrowthRateLibrary>,
types: Box<dyn TypeLibrary>,
natures: Box<dyn NatureLibrary>,
abilities: Box<dyn AbilityLibrary>,
) -> Self {
Self {
identifier: Default::default(),
settings,
species: Box::new(SpeciesLibraryImpl::new(0)),
moves: Box::new(MoveLibraryImpl::new(0)),
items: Box::new(ItemLibraryImpl::new(0)),
growth_rates: Box::new(GrowthRateLibraryImpl::new(0)),
types: Box::new(TypeLibraryImpl::new(0)),
natures: Box::new(NatureLibraryImpl::new(0)),
abilities: Box::new(AbilityLibraryImpl::new(0)),
species,
moves,
items,
growth_rates,
types,
natures,
abilities,
}
}
}