Initial work on creating a WASM interface for PkmnLibRs

This commit is contained in:
2022-07-24 09:25:37 +02:00
commit ce39ed9a9a
33 changed files with 36036 additions and 0 deletions

11
gen_7_scripts/Cargo.toml Normal file
View File

@@ -0,0 +1,11 @@
[package]
name = "gen7_scripts"
version = "0.1.0"
authors = ["Deukhoofd <Deukhoofd@gmail.com>"]
edition = "2018"
[lib]
crate-type = ["cdylib"]
[dependencies]
pkmn_lib_interface = { path = "../pkmn_lib_interface" }

20
gen_7_scripts/src/lib.rs Normal file
View File

@@ -0,0 +1,20 @@
#![feature(inline_const)]
#![feature(inline_const_pat)]
#![feature(wasm_abi)]
#![no_std]
#![allow(incomplete_features)]
extern crate alloc;
use alloc::boxed::Box;
use pkmn_lib_interface::set_load_script_fn;
#[macro_use]
pub mod registered_scripts;
pub mod test_script;
#[no_mangle]
extern "wasm" fn _init() {
set_load_script_fn(Box::new(registered_scripts::get_script));
}

View File

@@ -0,0 +1,41 @@
use crate::test_script::TestScript;
use alloc::boxed::Box;
use pkmn_lib_interface::app_interface::{get_hash, StringKey};
use pkmn_lib_interface::handling::{Script, ScriptCategory};
macro_rules! resolve_match {
(
$mid:expr,
$(
$key:expr => $script:ident,
)*
) => (
match $mid {
$(
const { get_hash($key) } => {
return Some(Box::new($script {}))
}
)*
_ => {}
}
)
}
pub fn get_script(category: ScriptCategory, name: &StringKey) -> Option<Box<dyn Script>> {
match category {
ScriptCategory::Move => {
resolve_match!(
name.hash(),
b"test" => TestScript,
);
}
ScriptCategory::Ability => {}
ScriptCategory::Status => {}
ScriptCategory::Pokemon => {}
ScriptCategory::Battle => {}
ScriptCategory::Side => {}
ScriptCategory::ItemBattleTrigger => {}
}
None
}

View File

@@ -0,0 +1,37 @@
use pkmn_lib_interface::app_interface::list::ImmutableList;
use pkmn_lib_interface::app_interface::{get_hash, BattleLibrary, DataLibrary, EffectParameter};
use pkmn_lib_interface::dbg;
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
pub struct TestScript {}
impl Script for TestScript {
fn new() -> Self {
TestScript {}
}
fn destroy(&self) {}
fn get_name(&self) -> &str {
"TestScript"
}
fn get_capabilities(&self) -> &[ScriptCapabilities] {
&[ScriptCapabilities::Initialize]
}
fn on_initialize(
&self,
library: &BattleLibrary,
parameters: Option<ImmutableList<EffectParameter>>,
) {
let l = library.data_library();
let ml = l.move_library();
let m = ml.get_by_hash(const { get_hash(b"tackle") }).unwrap();
dbg!("found move!");
dbg!("{:?} has {} base power", m.name().str(), m.base_power());
dbg!(
"Found a parameter with value: {}",
parameters.unwrap().get(0).unwrap()
)
}
}