50 lines
1.3 KiB
Rust
50 lines
1.3 KiB
Rust
use crate::app_interface::TimeOfDay;
|
|
use alloc::rc::Rc;
|
|
|
|
pub trait MiscLibraryTrait {
|
|
fn time_of_day(&self) -> PkmnResult<TimeOfDay>;
|
|
}
|
|
|
|
pub type MiscLibrary = Rc<dyn MiscLibraryTrait>;
|
|
|
|
#[cfg(not(feature = "mock_data"))]
|
|
mod implementation {
|
|
use super::*;
|
|
use crate::handling::extern_ref::{ExternRef, ExternalReferenceType};
|
|
use crate::handling::WasmResult;
|
|
|
|
#[derive(Clone)]
|
|
pub struct MiscLibraryImpl {
|
|
reference: ExternRef<Self>,
|
|
}
|
|
|
|
impl MiscLibraryImpl {
|
|
pub(crate) fn new(reference: ExternRef<Self>) -> Self {
|
|
Self { reference }
|
|
}
|
|
}
|
|
|
|
impl MiscLibraryTrait for MiscLibraryImpl {
|
|
fn time_of_day(&self) -> PkmnResult<TimeOfDay> {
|
|
unsafe {
|
|
let time_of_day = misc_library_get_time_of_day(self.reference).as_res()?;
|
|
Ok(core::mem::transmute::<u8, TimeOfDay>(time_of_day))
|
|
}
|
|
}
|
|
}
|
|
|
|
impl ExternalReferenceType for MiscLibraryImpl {
|
|
fn from_extern_value(reference: ExternRef<Self>) -> Self {
|
|
MiscLibraryImpl::new(reference)
|
|
}
|
|
}
|
|
|
|
extern "wasm" {
|
|
fn misc_library_get_time_of_day(ptr: ExternRef<MiscLibraryImpl>) -> WasmResult<u8>;
|
|
}
|
|
}
|
|
|
|
use crate::PkmnResult;
|
|
#[cfg(not(feature = "mock_data"))]
|
|
pub use implementation::*;
|