62 lines
1.9 KiB
Rust
62 lines
1.9 KiB
Rust
|
use std::ops::Deref;
|
||
|
|
||
|
use crate::dynamic_data::{LearnedMove, Pokemon, TurnChoice};
|
||
|
use crate::script_implementations::wasm::export_registry::register;
|
||
|
use crate::script_implementations::wasm::extern_ref::ExternRef;
|
||
|
use crate::script_implementations::wasm::script_resolver::WebAssemblyEnv;
|
||
|
|
||
|
register! {
|
||
|
|
||
|
fn turn_choice_get_user<'a>(
|
||
|
env: &WebAssemblyEnv,
|
||
|
turn_choice: ExternRef<TurnChoice<'a, 'a>>,
|
||
|
) -> ExternRef<Pokemon<'a, 'a>> {
|
||
|
let turn_choice = turn_choice.value(env).unwrap();
|
||
|
ExternRef::new(env.data().as_ref(), turn_choice.user().as_ref().deref())
|
||
|
}
|
||
|
|
||
|
fn turn_choice_get_kind(
|
||
|
env: &WebAssemblyEnv,
|
||
|
turn_choice: ExternRef<TurnChoice>,
|
||
|
) -> u8 {
|
||
|
match turn_choice.value(env).unwrap() {
|
||
|
TurnChoice::Move(_) => 0,
|
||
|
TurnChoice::Item(_) => 1,
|
||
|
TurnChoice::Switch(_) => 2,
|
||
|
TurnChoice::Flee(_) => 3,
|
||
|
TurnChoice::Pass(_) => 4,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn turn_choice_move_used_move<'a>(
|
||
|
env: &WebAssemblyEnv,
|
||
|
turn_choice: ExternRef<TurnChoice<'a, 'a>>,
|
||
|
) -> ExternRef<LearnedMove<'a>> {
|
||
|
if let TurnChoice::Move(d) = turn_choice.value(env).unwrap() {
|
||
|
return ExternRef::new(env.data().as_ref(), d.used_move().as_ref());
|
||
|
}
|
||
|
panic!("Invalid turn choice");
|
||
|
}
|
||
|
|
||
|
fn turn_choice_move_target_side(
|
||
|
env: &WebAssemblyEnv,
|
||
|
turn_choice: ExternRef<TurnChoice>,
|
||
|
) -> u8 {
|
||
|
if let TurnChoice::Move(d) = turn_choice.value(env).unwrap() {
|
||
|
return d.target_side();
|
||
|
}
|
||
|
panic!("Invalid turn choice");
|
||
|
}
|
||
|
|
||
|
fn turn_choice_move_target_index(
|
||
|
env: &WebAssemblyEnv,
|
||
|
turn_choice: ExternRef<TurnChoice>,
|
||
|
) -> u8 {
|
||
|
if let TurnChoice::Move(d) = turn_choice.value(env).unwrap() {
|
||
|
return d.target_index();
|
||
|
}
|
||
|
panic!("Invalid turn choice");
|
||
|
}
|
||
|
|
||
|
}
|