79 lines
2.9 KiB
Rust
Executable File
79 lines
2.9 KiB
Rust
Executable File
use crate::dynamic_data::{ExecutingMove, HitData, LearnedMove, Pokemon};
|
|
use crate::script_implementations::wasm::export_registry::{register, WasmResult};
|
|
use crate::script_implementations::wasm::extern_ref::ExternRef;
|
|
use crate::script_implementations::wasm::script::WebAssemblyScript;
|
|
use crate::script_implementations::wasm::script_resolver::WebAssemblyEnv;
|
|
use crate::static_data::MoveData;
|
|
use wasmer::FunctionEnvMut;
|
|
|
|
register! {
|
|
fn executing_move_get_user(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
executing_move: ExternRef<ExecutingMove>,
|
|
) -> WasmResult<ExternRef<Pokemon>> {
|
|
Ok(ExternRef::func_new(&env, executing_move.value_func(&env)?.user().as_ref())).into()
|
|
}
|
|
|
|
fn executing_move_get_use_move(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
executing_move: ExternRef<ExecutingMove>,
|
|
) -> WasmResult<ExternRef<dyn MoveData>> {
|
|
Ok(ExternRef::func_new(&env, executing_move.value_func(&env)?.use_move())).into()
|
|
}
|
|
|
|
fn executing_move_get_chosen_move(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
executing_move: ExternRef<ExecutingMove>,
|
|
) -> WasmResult<ExternRef<LearnedMove>> {
|
|
Ok(ExternRef::func_new(&env, executing_move.value_func(&env)?.chosen_move().as_ref())).into()
|
|
}
|
|
|
|
fn executing_move_get_number_of_hits(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
executing_move: ExternRef<ExecutingMove>,
|
|
) -> WasmResult<u8> {
|
|
Ok(executing_move.value_func(&env)?.number_of_hits()).into()
|
|
}
|
|
|
|
fn executing_move_get_hit_data(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
executing_move: ExternRef<ExecutingMove>,
|
|
target: ExternRef<Pokemon>,
|
|
hit: u8
|
|
) -> WasmResult<ExternRef<HitData>> {
|
|
Ok(ExternRef::func_new(&env, executing_move.value_func(&env)?.get_hit_data(target.value_func(&env)?, hit)?)).into()
|
|
}
|
|
|
|
fn executing_move_get_number_of_targets(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
executing_move: ExternRef<ExecutingMove>,
|
|
) -> WasmResult<u32> {
|
|
Ok(executing_move.value_func(&env)?.target_count() as u32).into()
|
|
}
|
|
|
|
fn executing_move_is_pokemon_target(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
executing_move: ExternRef<ExecutingMove>,
|
|
pokemon: ExternRef<Pokemon>
|
|
) -> WasmResult<u8> {
|
|
let pokemon = pokemon.value_func_arc(&env)?;
|
|
Ok(if executing_move.value_func(&env)?.is_pokemon_target(&pokemon) { 1 } else { 0 }).into()
|
|
}
|
|
|
|
|
|
|
|
fn executing_move_get_script(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
executing_move: ExternRef<ExecutingMove>,
|
|
) -> WasmResult<(u32 , u32)> {
|
|
let executing_move = executing_move.value_func(&env)?;
|
|
let script = executing_move.script();
|
|
if script.is_any() {
|
|
let s = script.get_as::<WebAssemblyScript>()?.get_wasm_pointer();
|
|
return Ok((s, s + 4)).into()
|
|
}
|
|
Ok((0, 0)).into()
|
|
}
|
|
|
|
}
|