use crate::app_interface::StringKey; use alloc::rc::Rc; #[repr(u8)] #[derive(Clone, Eq, PartialEq)] pub enum MoveCategory { Physical = 0, Special = 1, Status = 2, } #[repr(u8)] #[derive(Clone, Eq, PartialEq)] pub enum MoveTarget { Adjacent, AdjacentAlly, AdjacentAllySelf, AdjacentOpponent, All, AllAdjacent, AllAdjacentOpponent, AllAlly, AllOpponent, Any, RandomOpponent, OnSelf, } pub trait MoveDataTrait { fn name(&self) -> StringKey; fn move_type(&self) -> u8; fn category(&self) -> MoveCategory; fn base_power(&self) -> u8; fn accuracy(&self) -> u8; fn base_usages(&self) -> u8; fn target(&self) -> MoveTarget; fn priority(&self) -> i8; fn has_flag(&self, flag: &str) -> bool; } pub type MoveData = Rc; #[cfg(not(feature = "mock_data"))] mod implementation { use super::*; use crate::app_interface::get_hash; use crate::handling::cached_value::CachedValue; use crate::handling::extern_ref::{ExternRef, ExternalReferenceType}; use crate::handling::Cacheable; use crate::{cached_value, cached_value_getters}; struct MoveDataInner { ptr: ExternRef, name: CachedValue, move_type: CachedValue, category: CachedValue, base_power: CachedValue, accuracy: CachedValue, base_usages: CachedValue, target: CachedValue, priority: CachedValue, } #[derive(Clone)] pub struct MoveDataImpl { inner: Rc, } impl MoveDataImpl { pub(crate) fn new(ptr: ExternRef) -> Self { MoveDataImpl::from_ref(ptr, &|ptr| Self { inner: Rc::new(MoveDataInner { ptr, name: cached_value!({ StringKey::new(move_data_get_name(ptr)) }), move_type: cached_value!({ move_data_get_type(ptr) }), category: cached_value!({ move_data_get_category(ptr) }), base_power: cached_value!({ move_data_get_base_power(ptr) }), accuracy: cached_value!({ move_data_get_accuracy(ptr) }), base_usages: cached_value!({ move_data_get_base_power(ptr) }), target: cached_value!({ move_data_get_target(ptr) }), priority: cached_value!({ move_data_get_priority(ptr) }), }), }) } } impl MoveDataTrait for MoveDataImpl { cached_value_getters! { fn name(&self) -> StringKey; fn move_type(&self) -> u8; fn category(&self) -> MoveCategory; fn base_power(&self) -> u8; fn accuracy(&self) -> u8; fn base_usages(&self) -> u8; fn target(&self) -> MoveTarget; fn priority(&self) -> i8; } fn has_flag(&self, flag: &str) -> bool { let hash = get_hash(flag); unsafe { move_data_has_flag_by_hash(self.inner.ptr, hash) } } } impl ExternalReferenceType for MoveDataImpl { fn from_extern_value(reference: ExternRef) -> Self { MoveDataImpl::new(reference) } } crate::handling::cacheable::cacheable!(MoveDataImpl); extern "wasm" { fn move_data_get_name(ptr: ExternRef) -> ExternRef; fn move_data_get_type(ptr: ExternRef) -> u8; fn move_data_get_category(ptr: ExternRef) -> MoveCategory; fn move_data_get_base_power(ptr: ExternRef) -> u8; fn move_data_get_accuracy(ptr: ExternRef) -> u8; fn move_data_get_base_usages(ptr: ExternRef) -> u8; fn move_data_get_target(ptr: ExternRef) -> MoveTarget; fn move_data_get_priority(ptr: ExternRef) -> i8; fn move_data_has_flag_by_hash(ptr: ExternRef, flag_hash: u32) -> bool; } } #[cfg(not(feature = "mock_data"))] pub use implementation::*;