Fix build without wasm feature enabled
This commit is contained in:
parent
df47976d97
commit
bd804ea280
|
@ -55,7 +55,7 @@ pub enum ScriptCategory {
|
|||
}
|
||||
|
||||
/// A basic empty script resolver, that always returns None.
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct EmptyScriptResolver {
|
||||
/// A unique identifier so we know what value this is.
|
||||
pub identifier: ValueIdentifier,
|
||||
|
|
|
@ -11,11 +11,10 @@ use project_root::get_project_root;
|
|||
use serde_json::Value;
|
||||
|
||||
use pkmn_lib::defines::LevelInt;
|
||||
use pkmn_lib::dynamic_data::Gen7BattleStatCalculator;
|
||||
use pkmn_lib::dynamic_data::Gen7DamageLibrary;
|
||||
use pkmn_lib::dynamic_data::Gen7MiscLibrary;
|
||||
use pkmn_lib::dynamic_data::{DynamicLibrary, DynamicLibraryImpl};
|
||||
use pkmn_lib::script_implementations::wasm::script_resolver::WebAssemblyScriptResolver;
|
||||
use pkmn_lib::dynamic_data::{EmptyScriptResolver, Gen7BattleStatCalculator, ScriptResolver};
|
||||
use pkmn_lib::static_data::{
|
||||
AbilityImpl, AbilityLibrary, AbilityLibraryImpl, BattleItemCategory, DataLibrary, EffectParameter, Form, FormImpl,
|
||||
GrowthRateLibrary, GrowthRateLibraryImpl, ItemImpl, ItemLibrary, ItemLibraryImpl, LearnableMoves,
|
||||
|
@ -77,8 +76,7 @@ pub fn load_library() -> LoadResult {
|
|||
);
|
||||
|
||||
let t1 = chrono::Utc::now();
|
||||
let mut resolver = WebAssemblyScriptResolver::new();
|
||||
load_wasm(&path, resolver.as_mut());
|
||||
let script_resolver = load_script_resolver(&path);
|
||||
let t2 = chrono::Utc::now();
|
||||
let wasm_load_time = t2 - t1;
|
||||
|
||||
|
@ -87,7 +85,7 @@ pub fn load_library() -> LoadResult {
|
|||
Box::new(Gen7BattleStatCalculator::new()),
|
||||
Box::new(Gen7DamageLibrary::new(false)),
|
||||
Box::new(Gen7MiscLibrary::new()),
|
||||
resolver,
|
||||
script_resolver,
|
||||
));
|
||||
|
||||
LoadResult {
|
||||
|
@ -352,13 +350,21 @@ pub fn load_species(
|
|||
species_library
|
||||
}
|
||||
|
||||
fn load_wasm(path: &String, library: &mut WebAssemblyScriptResolver) {
|
||||
#[cfg(not(feature = "wasm"))]
|
||||
fn load_script_resolver(path: &String) -> Box<dyn ScriptResolver> {
|
||||
Box::new(EmptyScriptResolver::default())
|
||||
}
|
||||
|
||||
#[cfg(feature = "wasm")]
|
||||
fn load_script_resolver(path: &String) -> Box<dyn ScriptResolver> {
|
||||
let mut resolver = pkmn_lib::script_implementations::wasm::script_resolver::WebAssemblyScriptResolver::new();
|
||||
let file = File::open(path.to_string() + "gen7_scripts.wasm").unwrap();
|
||||
let mut reader = BufReader::new(file);
|
||||
let mut buffer = Vec::new();
|
||||
reader.read_to_end(&mut buffer).unwrap();
|
||||
library.load_wasm_from_bytes(&buffer);
|
||||
library.finalize();
|
||||
resolver.load_wasm_from_bytes(&buffer);
|
||||
resolver.finalize();
|
||||
resolver
|
||||
}
|
||||
|
||||
fn parse_form(
|
||||
|
|
|
@ -9,10 +9,9 @@ use std::path::Path;
|
|||
use std::sync::Arc;
|
||||
|
||||
use pkmn_lib::dynamic_data::{
|
||||
Battle, BattleParty, DamageSource, DynamicLibrary, ExecutingMove, MoveChoice, PokemonBuilder, PokemonParty, Script,
|
||||
Battle, BattleParty, DamageSource, DynamicLibrary, ExecutingMove, MoveChoice, PokemonBuilder, PokemonParty,
|
||||
ScriptCategory, ScriptContainer, ScriptOwnerData, TurnChoice, VolatileScriptsOwner,
|
||||
};
|
||||
use pkmn_lib::script_implementations::wasm::script::WebAssemblyScript;
|
||||
|
||||
use crate::common::{library_loader, TestCase};
|
||||
|
||||
|
@ -113,7 +112,8 @@ fn validate_assurance() {
|
|||
assert_eq!(v, 20_u8);
|
||||
|
||||
let s = battle.sides()[1].get_volatile_script(&"assurance_data".into());
|
||||
let data_script = s.as_ref().unwrap().get_as::<WebAssemblyScript>();
|
||||
let binding = s.as_ref().unwrap().get().unwrap().read();
|
||||
let data_script = binding.as_ref().unwrap();
|
||||
|
||||
data_script.on_damage(&p2, DamageSource::Misc, 100, 50);
|
||||
|
Loading…
Reference in New Issue