PkmnLib_rs/src/ffi/static_data/nature.rs

42 lines
1.4 KiB
Rust
Raw Normal View History

use crate::ffi::{ExternPointer, IdentifiablePointer, OwnedPtr};
2022-11-27 16:36:42 +00:00
use crate::static_data::{Nature, NatureImpl, Statistic};
2022-09-18 16:02:13 +00:00
use std::ptr::drop_in_place;
use std::sync::Arc;
2022-09-18 16:02:13 +00:00
2022-10-14 14:53:30 +00:00
/// Instantiates a new statistic.
2022-09-18 16:02:13 +00:00
#[no_mangle]
extern "C" fn nature_new(
increase_stat: Statistic,
decrease_stat: Statistic,
increase_modifier: f32,
decrease_modifier: f32,
2022-11-27 16:47:51 +00:00
) -> IdentifiablePointer<Arc<dyn Nature>> {
let arc: Arc<dyn Nature> = NatureImpl::new(increase_stat, decrease_stat, increase_modifier, decrease_modifier);
arc.into()
2022-09-18 16:02:13 +00:00
}
2022-10-14 14:53:30 +00:00
/// Reduce the reference count for a nature.
2022-09-18 16:02:13 +00:00
#[no_mangle]
2022-11-27 16:47:51 +00:00
unsafe extern "C" fn nature_drop(ptr: OwnedPtr<Arc<dyn Nature>>) {
2022-09-18 16:02:13 +00:00
drop_in_place(ptr)
}
2022-10-14 14:53:30 +00:00
/// The stat that should receive the increased modifier.
#[no_mangle]
2022-11-27 16:36:42 +00:00
extern "C" fn nature_increased_stat(ptr: ExternPointer<Arc<dyn Nature>>) -> Statistic {
ptr.as_ref().increased_stat()
}
2022-10-14 14:53:30 +00:00
/// The stat that should receive the decreased modifier.
#[no_mangle]
2022-11-27 16:36:42 +00:00
extern "C" fn nature_decreased_stat(ptr: ExternPointer<Arc<dyn Nature>>) -> Statistic {
ptr.as_ref().decreased_stat()
}
2022-09-18 16:02:13 +00:00
2022-10-14 14:53:30 +00:00
/// 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
2022-09-18 16:02:13 +00:00
#[no_mangle]
2022-11-27 16:36:42 +00:00
extern "C" fn nature_get_stat_modifier(ptr: ExternPointer<Arc<dyn Nature>>, stat: Statistic) -> f32 {
2022-09-18 16:02:13 +00:00
ptr.as_ref().get_stat_modifier(stat)
}