81 lines
2.9 KiB
Rust
Executable File
81 lines
2.9 KiB
Rust
Executable File
use crate::dynamic_data::{ExecutingMove, HitData, LearnedMove, Pokemon};
|
|
use crate::script_implementations::wasm::export_registry::register;
|
|
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>,
|
|
) -> ExternRef<Pokemon> {
|
|
ExternRef::func_new(&env, executing_move.value_func(&env).unwrap().user().as_ref())
|
|
}
|
|
|
|
fn executing_move_get_use_move(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
executing_move: ExternRef<ExecutingMove>,
|
|
) -> ExternRef<dyn MoveData> {
|
|
ExternRef::func_new(&env, executing_move.value_func(&env).unwrap().use_move())
|
|
}
|
|
|
|
fn executing_move_get_chosen_move(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
executing_move: ExternRef<ExecutingMove>,
|
|
) -> ExternRef<LearnedMove> {
|
|
ExternRef::func_new(&env, executing_move.value_func_arc(&env).unwrap().chosen_move().as_ref())
|
|
}
|
|
|
|
fn executing_move_get_number_of_hits(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
executing_move: ExternRef<ExecutingMove>,
|
|
) -> u8 {
|
|
executing_move.value_func(&env).unwrap().number_of_hits()
|
|
}
|
|
|
|
fn executing_move_get_hit_data(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
executing_move: ExternRef<ExecutingMove>,
|
|
target: ExternRef<Pokemon>,
|
|
hit: u8
|
|
) -> ExternRef<HitData> {
|
|
ExternRef::func_new(&env, executing_move.value_func(&env).unwrap().get_hit_data(target.value_func(&env).unwrap(), hit).unwrap())
|
|
}
|
|
|
|
fn executing_move_get_number_of_targets(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
executing_move: ExternRef<ExecutingMove>,
|
|
) -> u32 {
|
|
executing_move.value_func(&env).unwrap().target_count() as u32
|
|
}
|
|
|
|
fn executing_move_is_pokemon_target(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
executing_move: ExternRef<ExecutingMove>,
|
|
pokemon: ExternRef<Pokemon>
|
|
) -> u8 {
|
|
let pokemon = pokemon.value_func_arc(&env).unwrap();
|
|
if executing_move.value_func(&env).unwrap().is_pokemon_target(&pokemon) { 1 } else { 0 }
|
|
}
|
|
|
|
|
|
|
|
fn executing_move_get_script(
|
|
env: FunctionEnvMut<WebAssemblyEnv>,
|
|
executing_move: ExternRef<ExecutingMove>,
|
|
) -> (u32 , u32) {
|
|
let executing_move = executing_move.value_func(&env).unwrap();
|
|
if let Some(script) = executing_move.script().get() {
|
|
let read_lock = script.read();
|
|
if let Some(script) = read_lock.as_ref() {
|
|
let s = script.as_any().downcast_ref::<WebAssemblyScript>().unwrap().get_wasm_pointer();
|
|
return (s, s + 4)
|
|
}
|
|
}
|
|
(0, 0)
|
|
}
|
|
|
|
}
|