101 lines
2.9 KiB
Rust
Executable File
101 lines
2.9 KiB
Rust
Executable File
use crate::app_interface::MoveData;
|
|
use alloc::rc::Rc;
|
|
|
|
#[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,
|
|
}
|
|
|
|
pub trait LearnedMoveTrait {
|
|
fn move_data(&self) -> MoveData;
|
|
fn learn_method(&self) -> MoveLearnMethod;
|
|
fn restore_all_uses(&self);
|
|
fn restore_uses(&self, uses: u8);
|
|
}
|
|
|
|
pub type LearnedMove = Rc<dyn LearnedMoveTrait>;
|
|
|
|
#[cfg(not(feature = "mock_data"))]
|
|
mod implementation {
|
|
use super::*;
|
|
use crate::app_interface::MoveDataImpl;
|
|
use crate::handling::cached_value::CachedValue;
|
|
use crate::handling::extern_ref::{ExternRef, ExternalReferenceType};
|
|
use crate::handling::Cacheable;
|
|
use crate::{cached_value, cached_value_getters, wasm_value_getters};
|
|
use alloc::rc::Rc;
|
|
|
|
#[derive(Clone)]
|
|
pub struct LearnedMoveImpl {
|
|
inner: Rc<LearnedMoveInner>,
|
|
}
|
|
|
|
struct LearnedMoveInner {
|
|
reference: ExternRef<LearnedMoveImpl>,
|
|
move_data: CachedValue<MoveData>,
|
|
learn_method: CachedValue<MoveLearnMethod>,
|
|
}
|
|
|
|
crate::handling::cacheable::cacheable!(LearnedMoveImpl);
|
|
|
|
impl ExternalReferenceType for LearnedMoveImpl {
|
|
fn from_extern_value(reference: ExternRef<Self>) -> Self {
|
|
Self::new(reference)
|
|
}
|
|
}
|
|
|
|
impl LearnedMoveImpl {
|
|
pub fn new(reference: ExternRef<Self>) -> Self {
|
|
Self::from_ref(reference, &|reference| Self {
|
|
inner: Rc::new(LearnedMoveInner {
|
|
reference,
|
|
move_data: cached_value!({
|
|
Rc::new(learned_move_get_move_data(reference).get_value().unwrap())
|
|
}),
|
|
learn_method: cached_value!({ learned_move_get_learn_method(reference) }),
|
|
}),
|
|
})
|
|
}
|
|
}
|
|
|
|
impl LearnedMoveTrait for LearnedMoveImpl {
|
|
cached_value_getters! {
|
|
fn move_data(&self) -> MoveData;
|
|
fn learn_method(&self) -> MoveLearnMethod;
|
|
}
|
|
|
|
fn restore_all_uses(&self) {
|
|
unsafe {
|
|
learned_move_restore_all_uses(self.inner.reference);
|
|
}
|
|
}
|
|
|
|
fn restore_uses(&self, uses: u8) {
|
|
unsafe {
|
|
learned_move_restore_uses(self.inner.reference, uses);
|
|
}
|
|
}
|
|
}
|
|
|
|
wasm_value_getters! {
|
|
LearnedMoveImpl,
|
|
pub fn max_pp(&self) -> u8;
|
|
pub fn remaining_pp(&self) -> u8;
|
|
}
|
|
|
|
extern "wasm" {
|
|
fn learned_move_get_move_data(r: ExternRef<LearnedMoveImpl>) -> ExternRef<MoveDataImpl>;
|
|
fn learned_move_get_learn_method(r: ExternRef<LearnedMoveImpl>) -> MoveLearnMethod;
|
|
fn learned_move_restore_uses(r: ExternRef<LearnedMoveImpl>, uses: u8);
|
|
fn learned_move_restore_all_uses(r: ExternRef<LearnedMoveImpl>);
|
|
}
|
|
}
|
|
|
|
#[cfg(not(feature = "mock_data"))]
|
|
pub use implementation::*;
|