Initial work on wasm scripting backend
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::fmt::Debug;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::io::{BufReader, Read};
|
||||
|
||||
use hashbrown::HashSet;
|
||||
use num_traits::PrimInt;
|
||||
@@ -13,6 +13,7 @@ use pkmn_lib::dynamic_data::Gen7BattleStatCalculator;
|
||||
use pkmn_lib::dynamic_data::Gen7DamageLibrary;
|
||||
use pkmn_lib::dynamic_data::Gen7MiscLibrary;
|
||||
use pkmn_lib::dynamic_data::{DynamicLibrary, EmptyScriptResolver};
|
||||
use pkmn_lib::script_implementations::wasm::script_resolver::WebAssemblyScriptResolver;
|
||||
use pkmn_lib::static_data::{
|
||||
Ability, AbilityLibrary, BattleItemCategory, DataLibrary, EffectParameter, Form, GrowthRateLibrary, Item,
|
||||
ItemLibrary, LearnableMoves, LibrarySettings, LookupGrowthRate, MoveData, MoveLibrary, Nature, NatureLibrary,
|
||||
@@ -32,12 +33,15 @@ pub fn load_library() -> DynamicLibrary {
|
||||
load_abilities(&path, data.abilities_mut());
|
||||
load_moves(&path, &mut data);
|
||||
load_species(&path, &mut data);
|
||||
let mut resolver = WebAssemblyScriptResolver::new();
|
||||
load_wasm(&path, &mut resolver);
|
||||
|
||||
let dynamic = DynamicLibrary::new(
|
||||
data,
|
||||
Box::new(Gen7BattleStatCalculator {}),
|
||||
Box::new(Gen7DamageLibrary::new(false)),
|
||||
Box::new(Gen7MiscLibrary::new()),
|
||||
Box::new(EmptyScriptResolver {}),
|
||||
Box::new(resolver),
|
||||
);
|
||||
dynamic
|
||||
}
|
||||
@@ -271,6 +275,14 @@ pub fn load_species(path: &String, library: &mut StaticData) {
|
||||
}
|
||||
}
|
||||
|
||||
fn load_wasm(path: &String, library: &mut WebAssemblyScriptResolver) {
|
||||
let mut file = File::open(path.to_string() + "gen7_scripts_rs.wasm").unwrap();
|
||||
let mut reader = BufReader::new(file);
|
||||
let mut buffer = Vec::new();
|
||||
reader.read_to_end(&mut buffer);
|
||||
library.load_wasm_from_bytes(&buffer);
|
||||
}
|
||||
|
||||
fn parse_form(name: StringKey, value: &Value, library: &mut StaticData) -> Form {
|
||||
let mut abilities = Vec::new();
|
||||
for a in value["abilities"].as_array().unwrap() {
|
||||
|
||||
Reference in New Issue
Block a user