use crate::defines::LevelInt; use crate::ffi::{ExternPointer, IdentifiablePointer, 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, ) -> IdentifiablePointer> { let b: Box = Box::new(LibrarySettingsImpl::new(max_level, shiny_rate)); b.into() } /// Drop a library settings object. #[no_mangle] unsafe extern "C" fn library_settings_drop(ptr: OwnedPtr>) { drop_in_place(ptr) } /// The highest level a Pokemon can be. #[no_mangle] extern "C" fn library_settings_maximum_level(ptr: ExternPointer>) -> 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>) -> u32 { ptr.as_ref().shiny_rate() }