2023-01-04 16:24:13 +00:00
|
|
|
use crate::app_interface::{Party, PartyImpl};
|
2022-08-14 11:37:17 +00:00
|
|
|
use crate::handling::cached_value::CachedValue;
|
|
|
|
use crate::handling::Cacheable;
|
|
|
|
use crate::{cached_value, cached_value_getters, ExternRef, ExternalReferenceType};
|
|
|
|
use alloc::rc::Rc;
|
|
|
|
|
2023-01-04 16:24:13 +00:00
|
|
|
pub trait BattlePartyTrait {
|
|
|
|
fn party(&self) -> Party;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub type BattleParty = Rc<dyn BattlePartyTrait>;
|
|
|
|
|
2022-08-14 11:37:17 +00:00
|
|
|
struct BattlePartyInner {
|
2023-01-04 16:24:13 +00:00
|
|
|
reference: ExternRef<BattlePartyImpl>,
|
|
|
|
party: CachedValue<Rc<PartyImpl>>,
|
2022-08-14 11:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
2023-01-04 16:24:13 +00:00
|
|
|
pub struct BattlePartyImpl {
|
2022-08-14 11:37:17 +00:00
|
|
|
inner: Rc<BattlePartyInner>,
|
|
|
|
}
|
|
|
|
|
2023-01-04 16:24:13 +00:00
|
|
|
#[cfg(not(feature = "mock_data"))]
|
|
|
|
impl BattlePartyImpl {
|
|
|
|
pub fn new(reference: ExternRef<BattlePartyImpl>) -> Self {
|
2022-08-14 11:37:17 +00:00
|
|
|
Self::from_ref(reference, &|reference| Self {
|
|
|
|
inner: Rc::new(BattlePartyInner {
|
|
|
|
reference,
|
2023-01-04 16:24:13 +00:00
|
|
|
party: cached_value!({
|
|
|
|
Rc::new(battle_party_get_party(reference).get_value().unwrap())
|
|
|
|
}),
|
2022-08-14 11:37:17 +00:00
|
|
|
}),
|
|
|
|
})
|
|
|
|
}
|
2023-01-04 16:24:13 +00:00
|
|
|
}
|
2022-08-14 11:37:17 +00:00
|
|
|
|
2023-01-04 16:24:13 +00:00
|
|
|
#[cfg(not(feature = "mock_data"))]
|
|
|
|
impl BattlePartyTrait for BattlePartyImpl {
|
2022-08-14 11:37:17 +00:00
|
|
|
cached_value_getters! {
|
2023-01-04 16:24:13 +00:00
|
|
|
fn party(&self) -> Party;
|
2022-08-14 11:37:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-04 16:24:13 +00:00
|
|
|
crate::handling::cacheable::cacheable!(BattlePartyImpl);
|
2022-08-14 11:37:17 +00:00
|
|
|
|
2022-08-17 16:05:38 +00:00
|
|
|
#[cfg(not(feature = "mock_data"))]
|
2023-01-04 16:24:13 +00:00
|
|
|
impl ExternalReferenceType for BattlePartyImpl {
|
2022-08-14 11:37:17 +00:00
|
|
|
fn from_extern_value(reference: ExternRef<Self>) -> Self {
|
|
|
|
Self::new(reference)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-17 16:05:38 +00:00
|
|
|
#[cfg(not(feature = "mock_data"))]
|
2022-08-14 11:37:17 +00:00
|
|
|
extern "wasm" {
|
2023-01-04 16:24:13 +00:00
|
|
|
fn battle_party_get_party(r: ExternRef<BattlePartyImpl>) -> ExternRef<PartyImpl>;
|
2022-08-14 11:37:17 +00:00
|
|
|
}
|