Gen7ScriptsRs/pkmn_lib_interface/src/app_interface/dynamic_data/battle_party.rs

46 lines
1.2 KiB
Rust
Executable File

use crate::app_interface::Party;
use crate::handling::cached_value::CachedValue;
use crate::handling::Cacheable;
use crate::{cached_value, cached_value_getters, ExternRef, ExternalReferenceType};
use alloc::rc::Rc;
struct BattlePartyInner {
reference: ExternRef<BattleParty>,
party: CachedValue<Party>,
}
#[derive(Clone)]
pub struct BattleParty {
inner: Rc<BattlePartyInner>,
}
impl BattleParty {
#[cfg(not(feature = "mock_data"))]
pub fn new(reference: ExternRef<BattleParty>) -> Self {
Self::from_ref(reference, &|reference| Self {
inner: Rc::new(BattlePartyInner {
reference,
party: cached_value!({ battle_party_get_party(reference).get_value().unwrap() }),
}),
})
}
cached_value_getters! {
pub fn party(&self) -> Party;
}
}
crate::handling::cacheable::cacheable!(BattleParty);
#[cfg(not(feature = "mock_data"))]
impl ExternalReferenceType for BattleParty {
fn from_extern_value(reference: ExternRef<Self>) -> Self {
Self::new(reference)
}
}
#[cfg(not(feature = "mock_data"))]
extern "wasm" {
fn battle_party_get_party(r: ExternRef<BattleParty>) -> ExternRef<Party>;
}