PkmnLib_rs/src/ffi/static_data/libraries/library_settings.rs

39 lines
1.5 KiB
Rust

use crate::defines::LevelInt;
use crate::ffi::ffi_handle::{FFIHandle, FromFFIHandle};
use crate::ffi::FFIResult;
use crate::static_data::{LibrarySettings, LibrarySettingsImpl};
use std::sync::Arc;
/// 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,
) -> FFIResult<FFIHandle<Arc<dyn LibrarySettings>>> {
match LibrarySettingsImpl::new(max_level, shiny_rate) {
Ok(settings) => {
let b: Arc<dyn LibrarySettings> = Arc::new(settings);
let p: FFIHandle<Arc<dyn LibrarySettings>> = FFIHandle::get_handle(b.into());
FFIResult::ok(p)
}
Err(e) => FFIResult::err(e),
}
}
/// The highest level a Pokemon can be.
#[no_mangle]
extern "C" fn library_settings_maximum_level(ptr: FFIHandle<Arc<dyn LibrarySettings>>) -> LevelInt {
ptr.from_ffi_handle().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: FFIHandle<Arc<dyn LibrarySettings>>) -> u32 {
ptr.from_ffi_handle().shiny_rate()
}