PkmnLib_rs/src/ffi/static_data/nature.rs

35 lines
1.2 KiB
Rust

use crate::ffi::ffi_handle::{FFIHandle, FromFFIHandle};
use crate::static_data::{Nature, NatureImpl, Statistic};
use std::sync::Arc;
/// Instantiates a new statistic.
#[no_mangle]
extern "C" fn nature_new(
increase_stat: Statistic,
decrease_stat: Statistic,
increase_modifier: f32,
decrease_modifier: f32,
) -> FFIHandle<Arc<dyn Nature>> {
let arc: Arc<dyn Nature> = NatureImpl::new(increase_stat, decrease_stat, increase_modifier, decrease_modifier);
FFIHandle::get_handle(arc.into())
}
/// The stat that should receive the increased modifier.
#[no_mangle]
extern "C" fn nature_increased_stat(ptr: FFIHandle<Arc<dyn Nature>>) -> Statistic {
ptr.from_ffi_handle().increased_stat()
}
/// The stat that should receive the decreased modifier.
#[no_mangle]
extern "C" fn nature_decreased_stat(ptr: FFIHandle<Arc<dyn Nature>>) -> Statistic {
ptr.from_ffi_handle().decreased_stat()
}
/// Calculates the modifier for a given stat. If it's the increased stat, returns the increased
/// modifier, if it's the decreased stat, returns the decreased modifier. Otherwise returns 1.0
#[no_mangle]
extern "C" fn nature_get_stat_modifier(ptr: FFIHandle<Arc<dyn Nature>>, stat: Statistic) -> f32 {
ptr.from_ffi_handle().get_stat_modifier(stat)
}