69 lines
2.4 KiB
Rust
69 lines
2.4 KiB
Rust
use crate::dynamic_data::{
|
|
BattleStatCalculator, DamageLibrary, DynamicLibrary, DynamicLibraryImpl, MiscLibrary, ScriptResolver,
|
|
};
|
|
use crate::ffi::{ExternPointer, IdentifiablePointer, OwnedPtr};
|
|
use crate::static_data::StaticData;
|
|
use std::ptr::drop_in_place;
|
|
use std::sync::Arc;
|
|
|
|
/// Instantiates a new DynamicLibrary with given parameters.
|
|
#[no_mangle]
|
|
extern "C" fn dynamic_library_new(
|
|
static_data: OwnedPtr<Arc<dyn StaticData>>,
|
|
stat_calculator: OwnedPtr<Arc<dyn BattleStatCalculator>>,
|
|
damage_library: OwnedPtr<Arc<dyn DamageLibrary>>,
|
|
misc_library: OwnedPtr<Arc<dyn MiscLibrary>>,
|
|
script_resolver: OwnedPtr<Box<dyn ScriptResolver>>,
|
|
) -> IdentifiablePointer<Arc<dyn DynamicLibrary>> {
|
|
unsafe {
|
|
let a: Arc<dyn DynamicLibrary> = Arc::new(DynamicLibraryImpl::new(
|
|
static_data.read(),
|
|
stat_calculator.read(),
|
|
damage_library.read(),
|
|
misc_library.read(),
|
|
*Box::from_raw(script_resolver),
|
|
));
|
|
a.into()
|
|
}
|
|
}
|
|
|
|
/// Drops a dynamic library.
|
|
#[no_mangle]
|
|
extern "C" fn dynamic_library_drop(ptr: OwnedPtr<Arc<dyn DynamicLibrary>>) {
|
|
unsafe { drop_in_place(ptr) };
|
|
}
|
|
|
|
/// The static data is the immutable storage data for this library.
|
|
#[no_mangle]
|
|
extern "C" fn dynamic_library_get_static_data(
|
|
ptr: ExternPointer<Arc<dyn DynamicLibrary>>,
|
|
) -> IdentifiablePointer<Arc<dyn StaticData>> {
|
|
ptr.as_ref().static_data().clone().into()
|
|
}
|
|
|
|
/// The stat calculator deals with the calculation of flat and boosted stats, based on the
|
|
/// Pokemons attributes.
|
|
#[no_mangle]
|
|
extern "C" fn dynamic_library_get_stat_calculator(
|
|
ptr: ExternPointer<Arc<dyn DynamicLibrary>>,
|
|
) -> IdentifiablePointer<Arc<dyn BattleStatCalculator>> {
|
|
ptr.as_ref().stat_calculator().clone().into()
|
|
}
|
|
|
|
/// The damage calculator deals with the calculation of things relating to damage.
|
|
#[no_mangle]
|
|
extern "C" fn dynamic_library_get_damage_calculator(
|
|
ptr: ExternPointer<Arc<dyn DynamicLibrary>>,
|
|
) -> IdentifiablePointer<Arc<dyn DamageLibrary>> {
|
|
ptr.as_ref().damage_calculator().clone().into()
|
|
}
|
|
|
|
/// The Misc Library holds minor functions that do not fall in any of the other libraries and
|
|
/// calculators.
|
|
#[no_mangle]
|
|
extern "C" fn dynamic_library_get_misc_library(
|
|
ptr: ExternPointer<Arc<dyn DynamicLibrary>>,
|
|
) -> IdentifiablePointer<Arc<dyn MiscLibrary>> {
|
|
ptr.as_ref().misc_library().clone().into()
|
|
}
|