131 lines
4.0 KiB
Rust
Executable File
131 lines
4.0 KiB
Rust
Executable File
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<dyn MoveDataTrait>;
|
|
|
|
#[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<MoveDataImpl>,
|
|
name: CachedValue<StringKey>,
|
|
move_type: CachedValue<u8>,
|
|
category: CachedValue<MoveCategory>,
|
|
base_power: CachedValue<u8>,
|
|
accuracy: CachedValue<u8>,
|
|
base_usages: CachedValue<u8>,
|
|
target: CachedValue<MoveTarget>,
|
|
priority: CachedValue<i8>,
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct MoveDataImpl {
|
|
inner: Rc<MoveDataInner>,
|
|
}
|
|
|
|
impl MoveDataImpl {
|
|
pub(crate) fn new(ptr: ExternRef<Self>) -> 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>) -> Self {
|
|
MoveDataImpl::new(reference)
|
|
}
|
|
}
|
|
|
|
crate::handling::cacheable::cacheable!(MoveDataImpl);
|
|
|
|
extern "wasm" {
|
|
fn move_data_get_name(ptr: ExternRef<MoveDataImpl>) -> ExternRef<StringKey>;
|
|
fn move_data_get_type(ptr: ExternRef<MoveDataImpl>) -> u8;
|
|
fn move_data_get_category(ptr: ExternRef<MoveDataImpl>) -> MoveCategory;
|
|
fn move_data_get_base_power(ptr: ExternRef<MoveDataImpl>) -> u8;
|
|
fn move_data_get_accuracy(ptr: ExternRef<MoveDataImpl>) -> u8;
|
|
fn move_data_get_base_usages(ptr: ExternRef<MoveDataImpl>) -> u8;
|
|
fn move_data_get_target(ptr: ExternRef<MoveDataImpl>) -> MoveTarget;
|
|
fn move_data_get_priority(ptr: ExternRef<MoveDataImpl>) -> i8;
|
|
fn move_data_has_flag_by_hash(ptr: ExternRef<MoveDataImpl>, flag_hash: u32) -> bool;
|
|
}
|
|
}
|
|
|
|
#[cfg(not(feature = "mock_data"))]
|
|
pub use implementation::*;
|