use crate::defines::LevelInt; use crate::ffi::ffi_handle::{FFIHandle, FromFFIHandle}; use crate::ffi::{FFIResult, NonOwnedPtrString}; use crate::static_data::{GrowthRate, GrowthRateLibrary, GrowthRateLibraryImpl}; use std::ffi::CStr; use std::sync::Arc; /// Instantiates a new growth rate library with a capacity #[no_mangle] extern "C" fn growth_rate_library_new(capacity: usize) -> FFIHandle> { let b: Arc = Arc::new(GrowthRateLibraryImpl::new(capacity)); FFIHandle::get_handle(b.into()) } /// Calculates the level for a given growth key name and a certain experience. #[no_mangle] unsafe extern "C" fn growth_rate_library_calculate_level( ptr: FFIHandle>, growth_rate: NonOwnedPtrString, experience: u32, ) -> FFIResult { ptr.from_ffi_handle() .calculate_level(&CStr::from_ptr(growth_rate).into(), experience) .into() } /// Calculates the experience for a given growth key name and a certain level. #[no_mangle] unsafe extern "C" fn growth_rate_library_calculate_experience( ptr: FFIHandle>, growth_rate: NonOwnedPtrString, level: LevelInt, ) -> FFIResult { ptr.from_ffi_handle() .calculate_experience(&CStr::from_ptr(growth_rate).into(), level) .into() } /// Adds a new growth rate with a name and value. #[no_mangle] unsafe extern "C" fn growth_rate_library_add_growth_rate( ptr: FFIHandle>, name: NonOwnedPtrString, growth_rate: FFIHandle>, ) { ptr.from_ffi_handle() .add_growth_rate(&CStr::from_ptr(name).into(), growth_rate.from_ffi_handle()); }