86 lines
2.5 KiB
Rust
86 lines
2.5 KiB
Rust
use crate::ffi::{ExternPointer, IdentifiablePointer, OwnedPtr};
|
|
use crate::static_data::{
|
|
AbilityLibrary, GrowthRateLibrary, ItemLibrary, LibrarySettings, MoveLibrary, NatureLibrary, SpeciesLibrary,
|
|
StaticData, StaticDataImpl, TypeLibrary,
|
|
};
|
|
use std::ptr::drop_in_place;
|
|
|
|
/// Instantiates a new data collection.
|
|
#[no_mangle]
|
|
unsafe extern "C" fn static_data_new(
|
|
settings: OwnedPtr<Box<dyn LibrarySettings>>,
|
|
) -> IdentifiablePointer<Box<dyn StaticData>> {
|
|
let b: Box<dyn StaticData> = Box::new(StaticDataImpl::new(*Box::from_raw(settings)));
|
|
b.into()
|
|
}
|
|
|
|
/// Drop a static data.
|
|
#[no_mangle]
|
|
unsafe extern "C" fn static_data_drop(ptr: OwnedPtr<Box<dyn StaticData>>) {
|
|
drop_in_place(ptr)
|
|
}
|
|
|
|
/// Several misc settings for the library.
|
|
#[no_mangle]
|
|
unsafe extern "C" fn static_data_settings(
|
|
mut data: ExternPointer<Box<dyn StaticData>>,
|
|
) -> IdentifiablePointer<Box<dyn LibrarySettings>> {
|
|
data.as_mut().settings().into()
|
|
}
|
|
|
|
/// All data for Pokemon species.
|
|
#[no_mangle]
|
|
unsafe extern "C" fn static_data_species(
|
|
mut data: ExternPointer<Box<dyn StaticData>>,
|
|
) -> IdentifiablePointer<Box<dyn SpeciesLibrary>> {
|
|
data.as_mut().species().into()
|
|
}
|
|
|
|
/// All data for the moves.
|
|
#[no_mangle]
|
|
unsafe extern "C" fn static_data_moves(
|
|
mut data: ExternPointer<Box<dyn StaticData>>,
|
|
) -> IdentifiablePointer<Box<dyn MoveLibrary>> {
|
|
data.as_mut().moves().into()
|
|
}
|
|
|
|
/// All data for the items.
|
|
#[no_mangle]
|
|
unsafe extern "C" fn static_data_items(
|
|
mut data: ExternPointer<Box<dyn StaticData>>,
|
|
) -> IdentifiablePointer<Box<dyn ItemLibrary>> {
|
|
(data.as_mut().items()).into()
|
|
}
|
|
|
|
/// All data for growth rates.
|
|
#[no_mangle]
|
|
unsafe extern "C" fn static_data_growth_rates(
|
|
mut data: ExternPointer<Box<dyn StaticData>>,
|
|
) -> IdentifiablePointer<Box<dyn GrowthRateLibrary>> {
|
|
data.as_mut().growth_rates().into()
|
|
}
|
|
|
|
/// All data related to types and type effectiveness.
|
|
#[no_mangle]
|
|
unsafe extern "C" fn static_data_types(
|
|
mut data: ExternPointer<Box<dyn StaticData>>,
|
|
) -> IdentifiablePointer<Box<dyn TypeLibrary>> {
|
|
data.as_mut().types().into()
|
|
}
|
|
|
|
/// All data related to natures.
|
|
#[no_mangle]
|
|
unsafe extern "C" fn static_data_natures(
|
|
data: ExternPointer<Box<dyn StaticData>>,
|
|
) -> IdentifiablePointer<Box<dyn NatureLibrary>> {
|
|
data.as_ref().natures().into()
|
|
}
|
|
|
|
/// All data related to abilities.
|
|
#[no_mangle]
|
|
unsafe extern "C" fn static_data_abilities(
|
|
mut data: ExternPointer<Box<dyn StaticData>>,
|
|
) -> IdentifiablePointer<Box<dyn AbilityLibrary>> {
|
|
(data.as_mut().abilities()).into()
|
|
}
|