Adds functions to get current time of day
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
c44621d1cb
commit
48ff2c4536
|
@ -1,8 +1,9 @@
|
|||
use crate::app_interface::StaticData;
|
||||
use crate::app_interface::{MiscLibrary, StaticData};
|
||||
use alloc::rc::Rc;
|
||||
|
||||
pub trait DynamicLibraryTrait {
|
||||
fn data_library(&self) -> StaticData;
|
||||
fn misc_library(&self) -> MiscLibrary;
|
||||
}
|
||||
|
||||
pub type DynamicLibrary = Rc<dyn DynamicLibraryTrait>;
|
||||
|
@ -11,7 +12,7 @@ pub type DynamicLibrary = Rc<dyn DynamicLibraryTrait>;
|
|||
mod implementation {
|
||||
use super::*;
|
||||
use crate::app_interface::dynamic_data::dynamic_library::DynamicLibraryTrait;
|
||||
use crate::app_interface::StaticDataImpl;
|
||||
use crate::app_interface::{MiscLibraryImpl, StaticDataImpl};
|
||||
use crate::cached_value;
|
||||
use crate::handling::cached_value::CachedValue;
|
||||
use crate::handling::extern_ref::{ExternRef, ExternalReferenceType};
|
||||
|
@ -22,6 +23,7 @@ mod implementation {
|
|||
struct DynamicLibraryInner {
|
||||
ptr: ExternRef<DynamicLibraryImpl>,
|
||||
static_data: CachedValue<StaticData>,
|
||||
misc_library: CachedValue<MiscLibrary>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -44,6 +46,14 @@ mod implementation {
|
|||
.unwrap(),
|
||||
)
|
||||
}),
|
||||
misc_library: cached_value!({
|
||||
Rc::new(
|
||||
dynamic_library_get_misc_library(ptr)
|
||||
.unwrap()
|
||||
.get_value()
|
||||
.unwrap(),
|
||||
)
|
||||
}),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
@ -53,6 +63,10 @@ mod implementation {
|
|||
fn data_library(&self) -> StaticData {
|
||||
self.inner.static_data.value()
|
||||
}
|
||||
|
||||
fn misc_library(&self) -> MiscLibrary {
|
||||
self.inner.misc_library.value()
|
||||
}
|
||||
}
|
||||
|
||||
impl ExternalReferenceType for DynamicLibraryImpl {
|
||||
|
@ -65,6 +79,9 @@ mod implementation {
|
|||
fn dynamic_library_get_static_data(
|
||||
ptr: ExternRef<DynamicLibraryImpl>,
|
||||
) -> WasmResult<ExternRef<StaticDataImpl>>;
|
||||
fn dynamic_library_get_misc_library(
|
||||
ptr: ExternRef<DynamicLibraryImpl>,
|
||||
) -> WasmResult<ExternRef<MiscLibraryImpl>>;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
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::*;
|
|
@ -6,6 +6,7 @@ mod choice_queue;
|
|||
mod dynamic_library;
|
||||
mod executing_move;
|
||||
mod learned_move;
|
||||
mod misc_library;
|
||||
mod party;
|
||||
mod pokemon;
|
||||
mod statistic_set;
|
||||
|
@ -20,6 +21,7 @@ pub use choice_queue::*;
|
|||
pub use dynamic_library::*;
|
||||
pub use executing_move::*;
|
||||
pub use learned_move::*;
|
||||
pub use misc_library::*;
|
||||
pub use party::*;
|
||||
pub use pokemon::*;
|
||||
pub use statistic_set::*;
|
||||
|
@ -41,4 +43,4 @@ impl EventBatchId {
|
|||
id: uuid::Uuid::from_u64_pair(a, b),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ pub mod move_data;
|
|||
mod nature;
|
||||
pub mod species;
|
||||
pub mod statistics;
|
||||
mod time_of_day;
|
||||
|
||||
pub use ability::*;
|
||||
pub use data_libraries::*;
|
||||
|
@ -15,6 +16,7 @@ pub use move_data::*;
|
|||
pub use nature::*;
|
||||
pub use species::*;
|
||||
pub use statistics::*;
|
||||
pub use time_of_day::*;
|
||||
|
||||
pub type LevelInt = u8;
|
||||
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
/// The time of day. These values are the 4 different groups of time of day in Pokemon games since
|
||||
/// gen 5. The exact times these correspond to differ between games.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[repr(u8)]
|
||||
pub enum TimeOfDay {
|
||||
/// The morning.
|
||||
Morning = 0,
|
||||
/// The day.
|
||||
Day = 1,
|
||||
/// The evening.
|
||||
Evening = 2,
|
||||
/// The night.
|
||||
Night = 3,
|
||||
}
|
||||
|
||||
impl Default for TimeOfDay {
|
||||
fn default() -> Self {
|
||||
TimeOfDay::Day
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue