70 lines
2.1 KiB
Rust
Executable File
70 lines
2.1 KiB
Rust
Executable File
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;
|
|
use wasmer::FunctionEnvMut;
|
|
|
|
register! {
|
|
|
|
fn turn_choice_get_user(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
turn_choice: ExternRef<TurnChoice>,
|
|
) -> ExternRef<Pokemon> {
|
|
let turn_choice = turn_choice.value_func(&env).unwrap();
|
|
ExternRef::func_new(&env, turn_choice.user().as_ref().deref())
|
|
}
|
|
|
|
fn turn_choice_get_kind(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
turn_choice: ExternRef<TurnChoice>,
|
|
) -> u8 {
|
|
match turn_choice.value_func(&env).unwrap() {
|
|
TurnChoice::Move(_) => 0,
|
|
TurnChoice::Item(_) => 1,
|
|
TurnChoice::Switch(_) => 2,
|
|
TurnChoice::Flee(_) => 3,
|
|
TurnChoice::Pass(_) => 4,
|
|
}
|
|
}
|
|
|
|
fn turn_choice_move_used_move(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
turn_choice: ExternRef<TurnChoice>,
|
|
) -> ExternRef<LearnedMove> {
|
|
if let TurnChoice::Move(d) = turn_choice.value_func(&env).unwrap() {
|
|
return ExternRef::func_new(&env, d.used_move().as_ref());
|
|
}
|
|
panic!("Invalid turn choice");
|
|
}
|
|
|
|
fn turn_choice_move_target_side(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
turn_choice: ExternRef<TurnChoice>,
|
|
) -> u8 {
|
|
if let TurnChoice::Move(d) = turn_choice.value_func(&env).unwrap() {
|
|
return d.target_side();
|
|
}
|
|
panic!("Invalid turn choice");
|
|
}
|
|
|
|
fn turn_choice_move_target_index(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
turn_choice: ExternRef<TurnChoice>,
|
|
) -> u8 {
|
|
if let TurnChoice::Move(d) = turn_choice.value_func(&env).unwrap() {
|
|
return d.target_index();
|
|
}
|
|
panic!("Invalid turn choice");
|
|
}
|
|
|
|
fn turn_choice_fail(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
turn_choice: ExternRef<TurnChoice>,
|
|
) {
|
|
turn_choice.value_func(&env).unwrap().fail();
|
|
}
|
|
|
|
}
|