42 lines
1.4 KiB
Rust
42 lines
1.4 KiB
Rust
use crate::ffi::{ExternPointer, IdentifiablePointer, OwnedPtr};
|
|
use crate::static_data::{Nature, NatureImpl, Statistic};
|
|
use std::ptr::drop_in_place;
|
|
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,
|
|
) -> IdentifiablePointer<Arc<dyn Nature>> {
|
|
let arc: Arc<dyn Nature> = NatureImpl::new(increase_stat, decrease_stat, increase_modifier, decrease_modifier);
|
|
arc.into()
|
|
}
|
|
|
|
/// Reduce the reference count for a nature.
|
|
#[no_mangle]
|
|
unsafe extern "C" fn nature_drop(ptr: OwnedPtr<Arc<dyn Nature>>) {
|
|
drop_in_place(ptr)
|
|
}
|
|
|
|
/// The stat that should receive the increased modifier.
|
|
#[no_mangle]
|
|
extern "C" fn nature_increased_stat(ptr: ExternPointer<Arc<dyn Nature>>) -> Statistic {
|
|
ptr.as_ref().increased_stat()
|
|
}
|
|
|
|
/// The stat that should receive the decreased modifier.
|
|
#[no_mangle]
|
|
extern "C" fn nature_decreased_stat(ptr: ExternPointer<Arc<dyn Nature>>) -> Statistic {
|
|
ptr.as_ref().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: ExternPointer<Arc<dyn Nature>>, stat: Statistic) -> f32 {
|
|
ptr.as_ref().get_stat_modifier(stat)
|
|
}
|