64 lines
1.8 KiB
Rust
Executable File
64 lines
1.8 KiB
Rust
Executable File
use crate::handling::cacheable::Cacheable;
|
|
use crate::handling::cached_value::CachedValue;
|
|
use crate::{
|
|
cached_value, cached_value_getters, EffectParameter, ExternRef, ExternalReferenceType,
|
|
ImmutableList, StringKey, VecExternRef,
|
|
};
|
|
use alloc::rc::Rc;
|
|
|
|
struct AbilityInner {
|
|
reference: ExternRef<Ability>,
|
|
name: CachedValue<StringKey>,
|
|
effect: CachedValue<StringKey>,
|
|
parameters: CachedValue<ImmutableList<EffectParameter>>,
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct Ability {
|
|
inner: Rc<AbilityInner>,
|
|
}
|
|
|
|
impl Ability {
|
|
#[cfg(not(feature = "mock_data"))]
|
|
pub fn new(reference: ExternRef<Self>) -> Self {
|
|
Self::from_ref(reference, &|reference| Self {
|
|
inner: Rc::new(AbilityInner {
|
|
reference,
|
|
name: cached_value!({ ability_get_name(reference).get_value().unwrap() }),
|
|
effect: cached_value!({ ability_get_effect(reference).get_value().unwrap() }),
|
|
parameters: cached_value!({
|
|
ability_get_parameters(reference).get_immutable_list()
|
|
}),
|
|
}),
|
|
})
|
|
}
|
|
|
|
cached_value_getters! {
|
|
pub fn name(&self) -> StringKey;
|
|
pub fn effect(&self) -> StringKey;
|
|
}
|
|
}
|
|
|
|
#[cfg(not(feature = "mock_data"))]
|
|
impl ExternalReferenceType for Ability {
|
|
fn from_extern_value(reference: ExternRef<Self>) -> Self {
|
|
Self::new(reference)
|
|
}
|
|
}
|
|
|
|
crate::handling::cacheable::cacheable!(Ability);
|
|
|
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
|
#[repr(C)]
|
|
pub struct AbilityIndex {
|
|
pub hidden: bool,
|
|
pub index: u8,
|
|
}
|
|
|
|
#[cfg(not(feature = "mock_data"))]
|
|
extern "wasm" {
|
|
fn ability_get_name(r: ExternRef<Ability>) -> ExternRef<StringKey>;
|
|
fn ability_get_effect(r: ExternRef<Ability>) -> ExternRef<StringKey>;
|
|
fn ability_get_parameters(r: ExternRef<Ability>) -> VecExternRef<EffectParameter>;
|
|
}
|