PkmnLib_rs/src/ffi/static_data/nature.rs

41 lines
1.3 KiB
Rust
Raw Normal View History

use crate::ffi::{ExternPointer, IdentifiablePointer, OwnedPtr};
2022-09-18 16:02:13 +00:00
use crate::static_data::{Nature, Statistic};
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,
) -> IdentifiablePointer<Arc<Nature>> {
Nature::new(increase_stat, decrease_stat, increase_modifier, decrease_modifier).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]
unsafe extern "C" fn nature_drop(ptr: OwnedPtr<Arc<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]
extern "C" fn nature_increased_stat(ptr: ExternPointer<Arc<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]
extern "C" fn nature_decreased_stat(ptr: ExternPointer<Arc<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]
extern "C" fn nature_get_stat_modifier(ptr: ExternPointer<Arc<Nature>>, stat: Statistic) -> f32 {
2022-09-18 16:02:13 +00:00
ptr.as_ref().get_stat_modifier(stat)
}