56 lines
1.8 KiB
Rust
Executable File
56 lines
1.8 KiB
Rust
Executable File
use crate::app_interface::Statistic;
|
|
use crate::handling::cacheable::Cacheable;
|
|
use crate::{ExternRef, ExternalReferenceType};
|
|
use alloc::rc::Rc;
|
|
|
|
struct NatureInner {
|
|
reference: ExternRef<Nature>,
|
|
/// The stat that should receive the increased modifier.
|
|
increase_stat: Statistic,
|
|
/// The stat that should receive the decreased modifier.
|
|
decrease_stat: Statistic,
|
|
/// The amount by which the increased stat is multiplied.
|
|
increase_modifier: f32,
|
|
/// The amount by which the decreased stat is multiplied.
|
|
decrease_modifier: f32,
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct Nature {
|
|
inner: Rc<NatureInner>,
|
|
}
|
|
|
|
crate::handling::cacheable::cacheable!(Nature);
|
|
|
|
impl Nature {
|
|
#[cfg(not(feature = "mock_data"))]
|
|
pub fn new(reference: ExternRef<Self>) -> Self {
|
|
Self::from_ref(reference, &|reference| unsafe {
|
|
Self {
|
|
inner: Rc::new(NatureInner {
|
|
reference,
|
|
increase_stat: nature_get_increase_stat(reference),
|
|
decrease_stat: nature_get_decrease_stat(reference),
|
|
increase_modifier: nature_get_increase_modifier(reference),
|
|
decrease_modifier: nature_get_decrease_modifier(reference),
|
|
}),
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
#[cfg(not(feature = "mock_data"))]
|
|
impl ExternalReferenceType for Nature {
|
|
fn from_extern_value(reference: ExternRef<Self>) -> Self {
|
|
Self::new(reference)
|
|
}
|
|
}
|
|
|
|
#[cfg(not(feature = "mock_data"))]
|
|
extern "wasm" {
|
|
fn nature_get_increase_stat(r: ExternRef<Nature>) -> Statistic;
|
|
fn nature_get_decrease_stat(r: ExternRef<Nature>) -> Statistic;
|
|
fn nature_get_increase_modifier(r: ExternRef<Nature>) -> f32;
|
|
fn nature_get_decrease_modifier(r: ExternRef<Nature>) -> f32;
|
|
}
|