56 lines
1.4 KiB
Rust
Executable File
56 lines
1.4 KiB
Rust
Executable File
use crate::app_interface::Pokemon;
|
|
#[cfg(not(feature = "mock_data"))]
|
|
use crate::app_interface::PokemonImpl;
|
|
use crate::{ExternRef, ExternalReferenceType};
|
|
use alloc::rc::Rc;
|
|
|
|
pub trait PartyTrait {
|
|
fn get_pokemon(&self, index: usize) -> Option<Pokemon>;
|
|
fn length(&self) -> usize;
|
|
}
|
|
|
|
pub type Party = Rc<dyn PartyTrait>;
|
|
|
|
#[derive(Clone)]
|
|
pub struct PartyImpl {
|
|
reference: ExternRef<Self>,
|
|
}
|
|
|
|
#[cfg(not(feature = "mock_data"))]
|
|
impl PartyImpl {
|
|
pub fn new(reference: ExternRef<PartyImpl>) -> Self {
|
|
Self { reference }
|
|
}
|
|
}
|
|
|
|
#[cfg(not(feature = "mock_data"))]
|
|
impl PartyTrait for PartyImpl {
|
|
fn get_pokemon(&self, index: usize) -> Option<Pokemon> {
|
|
unsafe {
|
|
let v = party_get_pokemon(self.reference, index).get_value();
|
|
if let Some(v) = v {
|
|
Some(Rc::new(v))
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
}
|
|
|
|
fn length(&self) -> usize {
|
|
unsafe { party_get_length(self.reference) }
|
|
}
|
|
}
|
|
|
|
#[cfg(not(feature = "mock_data"))]
|
|
impl ExternalReferenceType for PartyImpl {
|
|
fn from_extern_value(reference: ExternRef<Self>) -> Self {
|
|
Self::new(reference)
|
|
}
|
|
}
|
|
|
|
#[cfg(not(feature = "mock_data"))]
|
|
extern "wasm" {
|
|
fn party_get_pokemon(r: ExternRef<PartyImpl>, index: usize) -> ExternRef<PokemonImpl>;
|
|
fn party_get_length(r: ExternRef<PartyImpl>) -> usize;
|
|
}
|