use crate::app_interface::MoveData; use crate::handling::cacheable::Cacheable; use crate::handling::cached_value::CachedValue; use crate::{ cached_value, cached_value_getters, wasm_value_getters, ExternRef, ExternalReferenceType, }; use alloc::rc::Rc; struct LearnedMoveInner { reference: ExternRef, move_data: CachedValue, learn_method: CachedValue, } #[derive(Copy, Clone, Debug, Default)] #[repr(u8)] pub enum MoveLearnMethod { /// We do not know the learn method. #[default] Unknown = 0, /// The move was learned through level up. Level = 1, } #[derive(Clone)] pub struct LearnedMove { inner: Rc, } crate::handling::cacheable::cacheable!(LearnedMove); #[cfg(not(feature = "mock_data"))] impl ExternalReferenceType for LearnedMove { fn from_extern_value(reference: ExternRef) -> Self { Self::new(reference) } } impl LearnedMove { #[cfg(not(feature = "mock_data"))] pub fn new(reference: ExternRef) -> Self { Self::from_ref(reference, &|reference| Self { inner: Rc::new(LearnedMoveInner { reference, move_data: cached_value!({ learned_move_get_move_data(reference).get_value().unwrap() }), learn_method: cached_value!({ learned_move_get_learn_method(reference) }), }), }) } cached_value_getters! { pub fn move_data(&self) -> MoveData; pub fn learn_method(&self) -> MoveLearnMethod; } #[cfg(not(feature = "mock_data"))] pub fn restore_all_uses(&self) { unsafe { learned_move_restore_all_uses(self.inner.reference); } } #[cfg(not(feature = "mock_data"))] pub fn restore_uses(&self, uses: u8) { unsafe { learned_move_restore_uses(self.inner.reference, uses); } } } wasm_value_getters! { LearnedMove, pub fn max_pp(&self) -> u8; pub fn remaining_pp(&self) -> u8; } #[cfg(not(feature = "mock_data"))] extern "wasm" { fn learned_move_get_move_data(r: ExternRef) -> ExternRef; fn learned_move_get_learn_method(r: ExternRef) -> MoveLearnMethod; fn learned_move_restore_uses(r: ExternRef, uses: u8); fn learned_move_restore_all_uses(r: ExternRef); }