57 lines
1.6 KiB
Rust
Executable File
57 lines
1.6 KiB
Rust
Executable File
use crate::app_interface::Pokemon;
|
|
use alloc::rc::Rc;
|
|
|
|
#[cfg_attr(feature = "mock_data", mockall::automock)]
|
|
pub trait ChoiceQueueTrait {
|
|
fn move_pokemon_choice_next(&self, pokemon: &Pokemon) -> PkmnResult<bool>;
|
|
}
|
|
|
|
pub type ChoiceQueue = Rc<dyn ChoiceQueueTrait>;
|
|
#[cfg(feature = "mock_data")]
|
|
pub type MockChoiceQueue = MockChoiceQueueTrait;
|
|
|
|
#[cfg(not(feature = "mock_data"))]
|
|
mod implementation {
|
|
use super::*;
|
|
use crate::app_interface::PokemonImpl;
|
|
use crate::handling::wasm_result::WasmResult;
|
|
use crate::{ExternRef, ExternalReferenceType, PkmnResult};
|
|
|
|
#[derive(Clone)]
|
|
pub struct ChoiceQueueImpl {
|
|
reference: ExternRef<ChoiceQueueImpl>,
|
|
}
|
|
|
|
impl ChoiceQueueImpl {
|
|
pub fn new(reference: ExternRef<ChoiceQueueImpl>) -> Self {
|
|
Self { reference }
|
|
}
|
|
}
|
|
|
|
impl ChoiceQueueTrait for ChoiceQueueImpl {
|
|
fn move_pokemon_choice_next(&self, pokemon: &Pokemon) -> PkmnResult<bool> {
|
|
unsafe {
|
|
choice_queue_move_pokemon_choice_next(self.reference, pokemon.reference().into())
|
|
.as_res()
|
|
}
|
|
}
|
|
}
|
|
|
|
impl ExternalReferenceType for ChoiceQueueImpl {
|
|
fn from_extern_value(reference: ExternRef<Self>) -> Self {
|
|
Self::new(reference)
|
|
}
|
|
}
|
|
|
|
extern "wasm" {
|
|
fn choice_queue_move_pokemon_choice_next(
|
|
r: ExternRef<ChoiceQueueImpl>,
|
|
pokemon: ExternRef<PokemonImpl>,
|
|
) -> WasmResult<bool>;
|
|
}
|
|
}
|
|
|
|
use crate::PkmnResult;
|
|
#[cfg(not(feature = "mock_data"))]
|
|
pub use implementation::*;
|