Initial work on wasm scripting backend

This commit is contained in:
2022-07-18 10:16:47 +02:00
parent 8eb1159d64
commit 7682704945
21 changed files with 651 additions and 31 deletions

View File

@@ -1,4 +1,3 @@
use std::ffi::c_void;
use std::ops::Deref;
use std::sync::Arc;
@@ -15,6 +14,7 @@ use crate::{PkmnResult, StringKey};
/// The dynamic library stores a static data library, as well as holding different libraries and
/// calculators that might be customized between different generations and implementations.
#[derive(Debug)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub struct DynamicLibrary {
/// The static data is the immutable storage data for this library.
static_data: StaticData,
@@ -75,7 +75,7 @@ impl DynamicLibrary {
/// can be created with this combination, returns None.
pub fn load_script(
&self,
owner: *const c_void,
owner: *const u8,
_category: ScriptCategory,
_key: &StringKey,
) -> PkmnResult<Option<Arc<dyn Script>>> {

View File

@@ -1,4 +1,3 @@
use std::ffi::c_void;
use std::fmt::Debug;
use std::sync::Arc;
@@ -14,7 +13,7 @@ pub trait ScriptResolver: Debug {
/// can be created with this combination, returns None.
fn load_script(
&self,
owner: *const c_void,
owner: *const u8,
category: ScriptCategory,
script_key: &StringKey,
) -> PkmnResult<Option<Arc<dyn Script>>>;
@@ -29,7 +28,8 @@ pub trait ScriptResolver: Debug {
/// the same name, but a different script. It should be completely valid for a move to have the same
/// name as an ability, or more commonly: for a script attached to a Pokemon to have the same name as
/// a move that placed it there.
#[derive(Debug, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(u8)]
pub enum ScriptCategory {
/// A script that belongs to a move. This generally is only the script that is attached to a
/// [`MoveChoice`](crate::dynamic_data::MoveChoice) and [`ExecutingMove`](crate::dynamic_data::ExecutingMove)
@@ -58,7 +58,7 @@ pub struct EmptyScriptResolver {}
impl ScriptResolver for EmptyScriptResolver {
fn load_script(
&self,
_owner: *const c_void,
_owner: *const u8,
_category: ScriptCategory,
_script_key: &StringKey,
) -> PkmnResult<Option<Arc<dyn Script>>> {