88 lines
2.6 KiB
Rust
Executable File
88 lines
2.6 KiB
Rust
Executable File
use crate::app_interface::Statistic;
|
|
use alloc::rc::Rc;
|
|
|
|
pub trait NatureTrait {
|
|
fn increase_stat(&self) -> Statistic;
|
|
fn decrease_stat(&self) -> Statistic;
|
|
fn increase_modifier(&self) -> f32;
|
|
fn decrease_modifier(&self) -> f32;
|
|
}
|
|
|
|
pub type Nature = Rc<dyn NatureTrait>;
|
|
|
|
#[cfg(not(feature = "mock_data"))]
|
|
mod implementation {
|
|
use super::*;
|
|
use crate::handling::extern_ref::{ExternRef, ExternalReferenceType};
|
|
use crate::handling::Cacheable;
|
|
|
|
struct NatureInner {
|
|
reference: ExternRef<NatureImpl>,
|
|
/// 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 NatureImpl {
|
|
inner: Rc<NatureInner>,
|
|
}
|
|
|
|
crate::handling::cacheable::cacheable!(NatureImpl);
|
|
|
|
impl NatureImpl {
|
|
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),
|
|
}),
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
impl NatureTrait for NatureImpl {
|
|
fn increase_stat(&self) -> Statistic {
|
|
self.inner.increase_stat
|
|
}
|
|
|
|
fn decrease_stat(&self) -> Statistic {
|
|
self.inner.decrease_stat
|
|
}
|
|
|
|
fn increase_modifier(&self) -> f32 {
|
|
self.inner.increase_modifier
|
|
}
|
|
|
|
fn decrease_modifier(&self) -> f32 {
|
|
self.inner.decrease_modifier
|
|
}
|
|
}
|
|
|
|
impl ExternalReferenceType for NatureImpl {
|
|
fn from_extern_value(reference: ExternRef<Self>) -> Self {
|
|
Self::new(reference)
|
|
}
|
|
}
|
|
|
|
extern "wasm" {
|
|
fn nature_get_increase_stat(r: ExternRef<NatureImpl>) -> Statistic;
|
|
fn nature_get_decrease_stat(r: ExternRef<NatureImpl>) -> Statistic;
|
|
fn nature_get_increase_modifier(r: ExternRef<NatureImpl>) -> f32;
|
|
fn nature_get_decrease_modifier(r: ExternRef<NatureImpl>) -> f32;
|
|
}
|
|
}
|
|
|
|
#[cfg(not(feature = "mock_data"))]
|
|
pub use implementation::*;
|