Moves a bunch of libraries to traits
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -37,8 +37,8 @@ register! {
|
||||
fn battle_get_library(
|
||||
env: FunctionEnvMut<WebAssemblyEnv>,
|
||||
battle: ExternRef<Battle>,
|
||||
) -> ExternRef<DynamicLibrary> {
|
||||
ExternRef::func_new(&env, battle.value_func(&env).unwrap().library().as_ref())
|
||||
) -> ExternRef<dyn DynamicLibrary> {
|
||||
ExternRef::func_new(&env, &battle.value_func_arc(&env).unwrap().library().clone())
|
||||
}
|
||||
|
||||
fn battle_get_sides(
|
||||
|
||||
@@ -31,9 +31,9 @@ mod turn_choice;
|
||||
register! {
|
||||
fn dynamic_library_get_static_data(
|
||||
env: FunctionEnvMut<WebAssemblyEnv>,
|
||||
dynamic_lib: ExternRef<DynamicLibrary>,
|
||||
) -> ExternRef<StaticData> {
|
||||
ExternRef::func_new(&env, dynamic_lib.value_func(&env).unwrap().static_data())
|
||||
dynamic_lib: ExternRef<dyn DynamicLibrary>,
|
||||
) -> ExternRef<dyn StaticData> {
|
||||
ExternRef::func_new(&env, dynamic_lib.value_func_arc(&env).unwrap().static_data())
|
||||
}
|
||||
|
||||
fn script_get_owner(
|
||||
|
||||
@@ -15,9 +15,9 @@ register! {
|
||||
fn pokemon_get_library(
|
||||
env: FunctionEnvMut<WebAssemblyEnv>,
|
||||
pokemon: ExternRef<Pokemon>,
|
||||
) -> ExternRef<DynamicLibrary> {
|
||||
let lib = pokemon.value_func(&env).unwrap().library().as_ref();
|
||||
ExternRef::func_new(&env, lib)
|
||||
) -> ExternRef<dyn DynamicLibrary> {
|
||||
let lib = pokemon.value_func(&env).unwrap().library().clone();
|
||||
ExternRef::func_new(&env, &lib)
|
||||
}
|
||||
|
||||
fn pokemon_get_boosted_stats(
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
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 crate::static_data::{DataLibrary, Item, ItemLibrary};
|
||||
use crate::static_data::Item;
|
||||
use crate::static_data::ItemLibrary;
|
||||
use crate::StringKey;
|
||||
use std::mem::transmute;
|
||||
use wasmer::FunctionEnvMut;
|
||||
@@ -9,23 +10,23 @@ use wasmer::FunctionEnvMut;
|
||||
register! {
|
||||
fn item_library_get_item(
|
||||
env: FunctionEnvMut<WebAssemblyEnv>,
|
||||
lib: ExternRef<ItemLibrary>,
|
||||
lib: ExternRef<dyn ItemLibrary>,
|
||||
string_key: ExternRef<StringKey>,
|
||||
) -> ExternRef<dyn Item> {
|
||||
let lib = lib.value_func(&env).unwrap();
|
||||
let lib = lib.value_func_box(&env).unwrap();
|
||||
let m = lib.get(string_key.value_func(&env).unwrap());
|
||||
if let Some(v) = m {
|
||||
ExternRef::func_new(&env, v)
|
||||
ExternRef::func_new(&env, &v)
|
||||
} else {
|
||||
ExternRef::null()
|
||||
}
|
||||
}
|
||||
|
||||
fn item_library_get_item_by_hash(env: FunctionEnvMut<WebAssemblyEnv>, lib: ExternRef<ItemLibrary>, hash: u32) -> ExternRef<dyn Item> {
|
||||
let lib = lib.value_func(&env).unwrap();
|
||||
fn item_library_get_item_by_hash(env: FunctionEnvMut<WebAssemblyEnv>, lib: ExternRef<dyn ItemLibrary>, hash: u32) -> ExternRef<dyn Item> {
|
||||
let lib = lib.value_func_box(&env).unwrap();
|
||||
let m = lib.get_by_hash(hash);
|
||||
if let Some(v) = m {
|
||||
ExternRef::func_new(&env, v)
|
||||
ExternRef::func_new(&env, &v)
|
||||
} else {
|
||||
ExternRef::null()
|
||||
}
|
||||
|
||||
@@ -17,34 +17,34 @@ mod moves;
|
||||
mod species;
|
||||
|
||||
register! {
|
||||
fn static_data_get_move_library(env: FunctionEnvMut<WebAssemblyEnv>, data_library: ExternRef<StaticData>) -> ExternRef<MoveLibrary> {
|
||||
ExternRef::func_new(&env, data_library.value_func(&env).unwrap().moves())
|
||||
fn static_data_get_move_library(env: FunctionEnvMut<WebAssemblyEnv>, data_library: ExternRef<dyn StaticData>) -> ExternRef<dyn MoveLibrary> {
|
||||
ExternRef::func_new(&env, data_library.value_func_box(&env).unwrap().moves())
|
||||
}
|
||||
|
||||
fn static_data_get_species_library(
|
||||
env: FunctionEnvMut<WebAssemblyEnv>,
|
||||
data_library: ExternRef<StaticData>,
|
||||
) -> ExternRef<SpeciesLibrary> {
|
||||
ExternRef::func_new(&env, data_library.value_func(&env).unwrap().species())
|
||||
data_library: ExternRef<dyn StaticData>,
|
||||
) -> ExternRef<dyn SpeciesLibrary> {
|
||||
ExternRef::func_new(&env, data_library.value_func_box(&env).unwrap().species())
|
||||
}
|
||||
|
||||
fn static_data_get_item_library(env: FunctionEnvMut<WebAssemblyEnv>, data_library: ExternRef<StaticData>) -> ExternRef<ItemLibrary> {
|
||||
ExternRef::func_new(&env, data_library.value_func(&env).unwrap().items())
|
||||
fn static_data_get_item_library(env: FunctionEnvMut<WebAssemblyEnv>, data_library: ExternRef<dyn StaticData>) -> ExternRef<dyn ItemLibrary> {
|
||||
ExternRef::func_new(&env, data_library.value_func_box(&env).unwrap().items())
|
||||
}
|
||||
|
||||
fn static_data_get_type_library(env: FunctionEnvMut<WebAssemblyEnv>, data_library: ExternRef<StaticData>) -> ExternRef<TypeLibrary> {
|
||||
ExternRef::func_new(&env, data_library.value_func(&env).unwrap().types())
|
||||
fn static_data_get_type_library(env: FunctionEnvMut<WebAssemblyEnv>, data_library: ExternRef<dyn StaticData>) -> ExternRef<dyn TypeLibrary> {
|
||||
ExternRef::func_new(&env, data_library.value_func_box(&env).unwrap().types())
|
||||
}
|
||||
|
||||
fn static_data_get_library_settings(
|
||||
env: FunctionEnvMut<WebAssemblyEnv>,
|
||||
data_library: ExternRef<StaticData>,
|
||||
) -> ExternRef<LibrarySettings> {
|
||||
ExternRef::func_new(&env, data_library.value_func(&env).unwrap().settings())
|
||||
data_library: ExternRef<dyn StaticData>,
|
||||
) -> ExternRef<dyn LibrarySettings> {
|
||||
ExternRef::func_new(&env, data_library.value_func_box(&env).unwrap().settings())
|
||||
}
|
||||
|
||||
fn library_settings_get_maximum_level(env: FunctionEnvMut<WebAssemblyEnv>, data_library: ExternRef<LibrarySettings>) -> LevelInt {
|
||||
data_library.value_func(&env).unwrap().maximum_level()
|
||||
fn library_settings_get_maximum_level(env: FunctionEnvMut<WebAssemblyEnv>, data_library: ExternRef<dyn LibrarySettings>) -> LevelInt {
|
||||
data_library.value_func_box(&env).unwrap().maximum_level()
|
||||
}
|
||||
|
||||
fn statistic_set_get(env: FunctionEnvMut<WebAssemblyEnv>, statistics_set: ExternRef<StatisticSet<u32>>, stat: u8) -> i64 {
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
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 crate::static_data::{DataLibrary, MoveData, MoveLibrary};
|
||||
use crate::static_data::{MoveData, MoveLibrary};
|
||||
use crate::StringKey;
|
||||
use wasmer::FunctionEnvMut;
|
||||
|
||||
register! {
|
||||
fn move_library_get_move(
|
||||
env: FunctionEnvMut<WebAssemblyEnv>,
|
||||
lib: ExternRef<MoveLibrary>,
|
||||
lib: ExternRef<dyn MoveLibrary>,
|
||||
string_key: ExternRef<StringKey>,
|
||||
) -> ExternRef<dyn MoveData> {
|
||||
let lib = lib.value_func(&env).unwrap();
|
||||
let lib = lib.value_func_box(&env).unwrap();
|
||||
let m = lib.get(string_key.value_func(&env).unwrap());
|
||||
if let Some(v) = m {
|
||||
ExternRef::func_new(&env, v)
|
||||
ExternRef::func_new(&env, &v)
|
||||
} else {
|
||||
ExternRef::null()
|
||||
}
|
||||
}
|
||||
|
||||
fn move_library_get_move_by_hash(env: FunctionEnvMut<WebAssemblyEnv>, lib: ExternRef<MoveLibrary>, hash: u32) -> ExternRef<dyn MoveData> {
|
||||
let lib = lib.value_func(&env).unwrap();
|
||||
fn move_library_get_move_by_hash(env: FunctionEnvMut<WebAssemblyEnv>, lib: ExternRef<dyn MoveLibrary>, hash: u32) -> ExternRef<dyn MoveData> {
|
||||
let lib = lib.value_func_box(&env).unwrap();
|
||||
let m = lib.get_by_hash(hash);
|
||||
if let Some(v) = m {
|
||||
ExternRef::func_new(&env, v)
|
||||
ExternRef::func_new(&env, &v)
|
||||
} else {
|
||||
ExternRef::null()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
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 crate::static_data::{DataLibrary, Species, SpeciesLibrary};
|
||||
use crate::static_data::Species;
|
||||
use crate::static_data::SpeciesLibrary;
|
||||
use crate::StringKey;
|
||||
use wasmer::FunctionEnvMut;
|
||||
|
||||
@@ -9,13 +10,13 @@ register! {
|
||||
|
||||
fn species_library_get_species(
|
||||
env: FunctionEnvMut<WebAssemblyEnv>,
|
||||
lib: ExternRef<SpeciesLibrary>,
|
||||
lib: ExternRef<dyn SpeciesLibrary>,
|
||||
string_key: ExternRef<StringKey>,
|
||||
) -> ExternRef<dyn Species> {
|
||||
let lib = lib.value_func(&env).unwrap();
|
||||
let lib = lib.value_func_box(&env).unwrap();
|
||||
let m = lib.get(string_key.value_func(&env).unwrap());
|
||||
if let Some(v) = m {
|
||||
ExternRef::func_new(&env, v)
|
||||
ExternRef::func_new(&env, &v)
|
||||
} else {
|
||||
ExternRef::null()
|
||||
}
|
||||
|
||||
@@ -74,6 +74,15 @@ impl<T: ValueIdentifiable + ?Sized> ExternRef<T> {
|
||||
self.value_arc(&env.data().data())
|
||||
}
|
||||
|
||||
/// Returns the real value for a given ExternRef. Note that the requested type must be the same as the type of the
|
||||
/// value when it was passed before. If these types do not match, this will panic.
|
||||
pub fn value_func_box(&self, env: &FunctionEnvMut<WebAssemblyEnv>) -> Option<&Box<T>>
|
||||
where
|
||||
T: 'static,
|
||||
{
|
||||
self.value_box(&env.data().data())
|
||||
}
|
||||
|
||||
/// Returns the real value for a given ExternRef. Note that the requested type must be the same as the type of the
|
||||
/// value when it was passed before. If these types do not match, this will panic.
|
||||
pub fn value<'a, 'b, 'c>(&'a self, env: &'b Arc<WebAssemblyEnvironmentData>) -> Option<&'c T>
|
||||
@@ -93,6 +102,15 @@ impl<T: ValueIdentifiable + ?Sized> ExternRef<T> {
|
||||
.downcast_ref::<Arc<T>>()
|
||||
.cloned()
|
||||
}
|
||||
|
||||
/// Returns the real value for a given ExternRef. Note that the requested type must be the same as the type of the
|
||||
/// value when it was passed before. If these types do not match, this will panic.
|
||||
pub fn value_box(&self, env: &Arc<WebAssemblyEnvironmentData>) -> Option<&Box<T>>
|
||||
where
|
||||
T: 'static,
|
||||
{
|
||||
env.get_extern_ref_value::<T>(self.index).downcast_ref::<Box<T>>()
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<T: ?Sized> FromToNativeWasmType for ExternRef<T> {
|
||||
|
||||
@@ -125,7 +125,7 @@ impl Script for WebAssemblyScript {
|
||||
}
|
||||
}
|
||||
|
||||
fn on_initialize(&self, library: &DynamicLibrary, pars: Vec<EffectParameter>) {
|
||||
fn on_initialize(&self, library: &Arc<dyn DynamicLibrary>, pars: Vec<EffectParameter>) {
|
||||
if !self.has_capability(&WebAssemblyScriptCapabilities::Initialize) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ unsafe impl<T> FromToNativeWasmType for WasmPtr<T> {
|
||||
script_function_cache! {
|
||||
stack()
|
||||
on_remove()
|
||||
on_initialize(ExternRef<DynamicLibrary>, VecExternRef<EffectParameter>)
|
||||
on_initialize(ExternRef<dyn DynamicLibrary>, VecExternRef<EffectParameter>)
|
||||
on_before_turn(ExternRef<TurnChoice>)
|
||||
change_speed(ExternRef<TurnChoice>, WasmPtr<u32>)
|
||||
change_priority(ExternRef<TurnChoice>, WasmPtr<i8>)
|
||||
|
||||
Reference in New Issue
Block a user