47 lines
1.3 KiB
Rust
Executable File
47 lines
1.3 KiB
Rust
Executable File
use crate::{ExternRef, ExternalReferenceType};
|
|
use alloc::rc::Rc;
|
|
|
|
pub trait BattleRandomTrait {
|
|
fn get(&self) -> i32;
|
|
fn get_max(&self, max: i32) -> i32;
|
|
fn get_between(&self, min: i32, max: i32) -> i32;
|
|
}
|
|
|
|
pub type BattleRandom = Rc<dyn BattleRandomTrait>;
|
|
|
|
#[derive(Clone)]
|
|
pub struct BattleRandomImpl {
|
|
reference: ExternRef<Self>,
|
|
}
|
|
|
|
#[cfg(not(feature = "mock_data"))]
|
|
impl BattleRandomTrait for BattleRandomImpl {
|
|
#[cfg(not(feature = "mock_data"))]
|
|
fn get(&self) -> i32 {
|
|
unsafe { battle_random_get(self.reference) }
|
|
}
|
|
#[cfg(not(feature = "mock_data"))]
|
|
fn get_max(&self, max: i32) -> i32 {
|
|
unsafe { battle_random_get_max(self.reference, max) }
|
|
}
|
|
#[cfg(not(feature = "mock_data"))]
|
|
fn get_between(&self, min: i32, max: i32) -> i32 {
|
|
unsafe { battle_random_get_between(self.reference, min, max) }
|
|
}
|
|
// TODO: effect_chance()
|
|
}
|
|
|
|
impl ExternalReferenceType for BattleRandomImpl {
|
|
fn from_extern_value(reference: ExternRef<Self>) -> Self {
|
|
Self { reference }
|
|
}
|
|
}
|
|
|
|
#[cfg(not(feature = "mock_data"))]
|
|
extern "wasm" {
|
|
fn battle_random_get(r: ExternRef<BattleRandomImpl>) -> i32;
|
|
fn battle_random_get_max(r: ExternRef<BattleRandomImpl>, max: i32) -> i32;
|
|
fn battle_random_get_between(r: ExternRef<BattleRandomImpl>, min: i32, max: i32) -> i32;
|
|
|
|
}
|