90 lines
3.5 KiB
Rust
Executable File
90 lines
3.5 KiB
Rust
Executable File
use crate::dynamic_data::{ExecutingMove, HitData, LearnedMove, Pokemon};
|
|
use crate::script_implementations::wasm::export_registry::wasm_result::get_value_arc;
|
|
use crate::script_implementations::wasm::export_registry::{get_value, register, try_wasm, wasm_ok, 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>> {
|
|
let executing_move = get_value_arc!(executing_move, env);
|
|
wasm_ok(ExternRef::<Pokemon>::func_new(&env, executing_move.user().into()))
|
|
}
|
|
|
|
fn executing_move_get_use_move(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
executing_move: ExternRef<ExecutingMove>,
|
|
) -> WasmResult<ExternRef<dyn MoveData>> {
|
|
let executing_move = get_value_arc!(executing_move, env);
|
|
wasm_ok(ExternRef::<dyn MoveData>::func_new(&env, executing_move.use_move().into()))
|
|
}
|
|
|
|
fn executing_move_get_chosen_move(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
executing_move: ExternRef<ExecutingMove>,
|
|
) -> WasmResult<ExternRef<LearnedMove>> {
|
|
let executing_move = get_value_arc!(executing_move, env);
|
|
wasm_ok(ExternRef::<LearnedMove>::func_new(&env, executing_move.chosen_move().into()))
|
|
}
|
|
|
|
fn executing_move_get_number_of_hits(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
executing_move: ExternRef<ExecutingMove>,
|
|
) -> WasmResult<u8> {
|
|
let executing_move = get_value_arc!(executing_move, env);
|
|
wasm_ok(executing_move.number_of_hits())
|
|
}
|
|
|
|
fn executing_move_get_hit_data(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
executing_move: ExternRef<ExecutingMove>,
|
|
target: ExternRef<Pokemon>,
|
|
hit: u8
|
|
) -> WasmResult<ExternRef<HitData>> {
|
|
let executing_move = get_value_arc!(executing_move, env);
|
|
let target = get_value!(target, env);
|
|
let hit_data = try_wasm!(executing_move.get_hit_data(&target, hit), env);
|
|
wasm_ok(ExternRef::<HitData>::func_new(&env, hit_data.into()))
|
|
}
|
|
|
|
fn executing_move_get_number_of_targets(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
executing_move: ExternRef<ExecutingMove>,
|
|
) -> WasmResult<u32> {
|
|
let executing_move = get_value_arc!(executing_move, env);
|
|
wasm_ok(executing_move.target_count() as u32)
|
|
}
|
|
|
|
fn executing_move_is_pokemon_target(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
executing_move: ExternRef<ExecutingMove>,
|
|
pokemon: ExternRef<Pokemon>
|
|
) -> WasmResult<u8> {
|
|
let executing_move = get_value_arc!(executing_move, env);
|
|
let pokemon = get_value!(pokemon, env);
|
|
wasm_ok(if executing_move.is_pokemon_target(&pokemon) { 1 } else { 0 })
|
|
}
|
|
|
|
|
|
|
|
fn executing_move_get_script(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
executing_move: ExternRef<ExecutingMove>,
|
|
) -> WasmResult<u32> {
|
|
let executing_move = get_value_arc!(executing_move, env);
|
|
let script = executing_move.script();
|
|
if script.is_any() {
|
|
let script = try_wasm!(script.get_as::<WebAssemblyScript>(), env);
|
|
let s = script.get_wasm_pointer();
|
|
return wasm_ok(s)
|
|
}
|
|
wasm_ok(0u32)
|
|
}
|
|
|
|
}
|