49 lines
1.7 KiB
Rust
49 lines
1.7 KiB
Rust
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<Arc<dyn GrowthRateLibrary>> {
|
|
let b: Arc<dyn GrowthRateLibrary> = 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<Arc<dyn GrowthRateLibrary>>,
|
|
growth_rate: NonOwnedPtrString,
|
|
experience: u32,
|
|
) -> FFIResult<LevelInt> {
|
|
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<Arc<dyn GrowthRateLibrary>>,
|
|
growth_rate: NonOwnedPtrString,
|
|
level: LevelInt,
|
|
) -> FFIResult<u32> {
|
|
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<Arc<dyn GrowthRateLibrary>>,
|
|
name: NonOwnedPtrString,
|
|
growth_rate: FFIHandle<Arc<dyn GrowthRate>>,
|
|
) {
|
|
ptr.from_ffi_handle()
|
|
.add_growth_rate(&CStr::from_ptr(name).into(), growth_rate.from_ffi_handle());
|
|
}
|