44 lines
1.6 KiB
Rust
44 lines
1.6 KiB
Rust
use crate::defines::LevelInt;
|
|
use crate::ffi::{ExternPointer, IdentifiablePointer, NativeResult, OwnedPtr};
|
|
use crate::static_data::{LibrarySettings, LibrarySettingsImpl};
|
|
use std::ptr::drop_in_place;
|
|
|
|
/// Creates a new settings library.
|
|
/// - `maximum_level` is the highest level a Pokemon can be.
|
|
/// - `shiny_rate` is the chance of a Pokemon being shiny, as the denominator of a fraction, where
|
|
/// the nominator is 1. For example, if this is 1000, then the chance of a Pokemon being shiny is
|
|
/// 1/1000.
|
|
#[no_mangle]
|
|
extern "C" fn library_settings_new(
|
|
max_level: LevelInt,
|
|
shiny_rate: u32,
|
|
) -> NativeResult<IdentifiablePointer<Box<dyn LibrarySettings>>> {
|
|
match LibrarySettingsImpl::new(max_level, shiny_rate) {
|
|
Ok(settings) => {
|
|
let b: Box<dyn LibrarySettings> = Box::new(settings);
|
|
let p: IdentifiablePointer<Box<dyn LibrarySettings>> = b.into();
|
|
p.into()
|
|
}
|
|
Err(e) => NativeResult::err(e),
|
|
}
|
|
}
|
|
|
|
/// Drop a library settings object.
|
|
#[no_mangle]
|
|
unsafe extern "C" fn library_settings_drop(ptr: OwnedPtr<Box<dyn LibrarySettings>>) {
|
|
drop_in_place(ptr)
|
|
}
|
|
|
|
/// The highest level a Pokemon can be.
|
|
#[no_mangle]
|
|
extern "C" fn library_settings_maximum_level(ptr: ExternPointer<Box<dyn LibrarySettings>>) -> LevelInt {
|
|
ptr.as_ref().maximum_level()
|
|
}
|
|
|
|
/// The chance of a Pokemon being shiny, as the denominator of a fraction, where the nominator
|
|
/// is 1. For example, if this is 1000, then the chance of a Pokemon being shiny is 1/1000.
|
|
#[no_mangle]
|
|
extern "C" fn library_settings_shiny_rate(ptr: ExternPointer<Box<dyn LibrarySettings>>) -> u32 {
|
|
ptr.as_ref().shiny_rate()
|
|
}
|