82 lines
3.1 KiB
Rust
82 lines
3.1 KiB
Rust
use crate::ffi::ffi_handle::{FFIHandle, FromFFIHandle};
|
|
use crate::static_data::{
|
|
AbilityLibrary, GrowthRateLibrary, ItemLibrary, LibrarySettings, MoveLibrary, NatureLibrary, SpeciesLibrary,
|
|
StaticData, StaticDataImpl, TypeLibrary,
|
|
};
|
|
use std::sync::Arc;
|
|
|
|
/// Instantiates a new data collection.
|
|
#[no_mangle]
|
|
unsafe extern "C" fn static_data_new(
|
|
settings: FFIHandle<Arc<dyn LibrarySettings>>,
|
|
species: FFIHandle<Arc<dyn SpeciesLibrary>>,
|
|
moves: FFIHandle<Arc<dyn MoveLibrary>>,
|
|
items: FFIHandle<Arc<dyn ItemLibrary>>,
|
|
growth_rates: FFIHandle<Arc<dyn GrowthRateLibrary>>,
|
|
types: FFIHandle<Arc<dyn TypeLibrary>>,
|
|
natures: FFIHandle<Arc<dyn NatureLibrary>>,
|
|
abilities: FFIHandle<Arc<dyn AbilityLibrary>>,
|
|
) -> FFIHandle<Arc<dyn StaticData>> {
|
|
let b: Arc<dyn StaticData> = Arc::new(StaticDataImpl::new(
|
|
settings.from_ffi_handle(),
|
|
species.from_ffi_handle(),
|
|
moves.from_ffi_handle(),
|
|
items.from_ffi_handle(),
|
|
growth_rates.from_ffi_handle(),
|
|
types.from_ffi_handle(),
|
|
natures.from_ffi_handle(),
|
|
abilities.from_ffi_handle(),
|
|
));
|
|
FFIHandle::get_handle(b.into())
|
|
}
|
|
|
|
/// Several misc settings for the library.
|
|
#[no_mangle]
|
|
unsafe extern "C" fn static_data_settings(data: FFIHandle<Arc<dyn StaticData>>) -> FFIHandle<Arc<dyn LibrarySettings>> {
|
|
FFIHandle::get_handle(data.from_ffi_handle().settings().clone().into())
|
|
}
|
|
|
|
/// All data for Pokemon species.
|
|
#[no_mangle]
|
|
unsafe extern "C" fn static_data_species(data: FFIHandle<Arc<dyn StaticData>>) -> FFIHandle<Arc<dyn SpeciesLibrary>> {
|
|
FFIHandle::get_handle(data.from_ffi_handle().species().clone().into())
|
|
}
|
|
|
|
/// All data for the moves.
|
|
#[no_mangle]
|
|
unsafe extern "C" fn static_data_moves(data: FFIHandle<Arc<dyn StaticData>>) -> FFIHandle<Arc<dyn MoveLibrary>> {
|
|
FFIHandle::get_handle(data.from_ffi_handle().moves().clone().into())
|
|
}
|
|
|
|
/// All data for the items.
|
|
#[no_mangle]
|
|
unsafe extern "C" fn static_data_items(data: FFIHandle<Arc<dyn StaticData>>) -> FFIHandle<Arc<dyn ItemLibrary>> {
|
|
FFIHandle::get_handle((data.from_ffi_handle().items()).clone().into())
|
|
}
|
|
|
|
/// All data for growth rates.
|
|
#[no_mangle]
|
|
unsafe extern "C" fn static_data_growth_rates(
|
|
data: FFIHandle<Arc<dyn StaticData>>,
|
|
) -> FFIHandle<Arc<dyn GrowthRateLibrary>> {
|
|
FFIHandle::get_handle(data.from_ffi_handle().growth_rates().clone().into())
|
|
}
|
|
|
|
/// All data related to types and type effectiveness.
|
|
#[no_mangle]
|
|
unsafe extern "C" fn static_data_types(data: FFIHandle<Arc<dyn StaticData>>) -> FFIHandle<Arc<dyn TypeLibrary>> {
|
|
FFIHandle::get_handle(data.from_ffi_handle().types().clone().into())
|
|
}
|
|
|
|
/// All data related to natures.
|
|
#[no_mangle]
|
|
unsafe extern "C" fn static_data_natures(data: FFIHandle<Arc<dyn StaticData>>) -> FFIHandle<Arc<dyn NatureLibrary>> {
|
|
FFIHandle::get_handle(data.from_ffi_handle().natures().clone().into())
|
|
}
|
|
|
|
/// All data related to abilities.
|
|
#[no_mangle]
|
|
unsafe extern "C" fn static_data_abilities(data: FFIHandle<Arc<dyn StaticData>>) -> FFIHandle<Arc<dyn AbilityLibrary>> {
|
|
FFIHandle::get_handle((data.from_ffi_handle().abilities()).clone().into())
|
|
}
|