Style and Clippy fixes.
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:
@@ -12,14 +12,14 @@ register! {
|
||||
env: FunctionEnvMut<WebAssemblyEnv>,
|
||||
side: ExternRef<BattleSide>,
|
||||
) -> u8 {
|
||||
if side.value_func(&env).unwrap().has_fled_battle() { 1 } else { 0 }
|
||||
u8::from(side.value_func(&env).unwrap().has_fled_battle())
|
||||
}
|
||||
|
||||
fn battleside_is_defeated(
|
||||
env: FunctionEnvMut<WebAssemblyEnv>,
|
||||
side: ExternRef<BattleSide>,
|
||||
) -> u8 {
|
||||
if side.value_func(&env).unwrap().is_defeated() { 1 } else { 0 }
|
||||
u8::from(side.value_func(&env).unwrap().is_defeated())
|
||||
}
|
||||
|
||||
fn battleside_get_side_index(
|
||||
@@ -102,7 +102,7 @@ register! {
|
||||
) -> u8 {
|
||||
unsafe {
|
||||
let c_name = CStr::from_ptr(env.data().data().get_raw_pointer(name_ptr));
|
||||
if side.value_func(&env).unwrap().has_volatile_script(&c_name.as_ref().into()) { 1 } else { 0 }
|
||||
u8::from(side.value_func(&env).unwrap().has_volatile_script(&c_name.as_ref().into()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,10 +10,6 @@ register! {
|
||||
battle_random: ExternRef<ChoiceQueue>,
|
||||
pokemon: ExternRef<Pokemon>
|
||||
) -> u8 {
|
||||
if battle_random.value_func(&env).unwrap().move_pokemon_choice_next(pokemon.value_func(&env).unwrap()) {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
u8::from(battle_random.value_func(&env).unwrap().move_pokemon_choice_next(pokemon.value_func(&env).unwrap()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ register! {
|
||||
env: FunctionEnvMut<WebAssemblyEnv>,
|
||||
hit: ExternRef<HitData>,
|
||||
) -> u8 {
|
||||
if hit.value_func(&env).unwrap().is_critical() { 1 } else { 0 }
|
||||
u8::from(hit.value_func(&env).unwrap().is_critical())
|
||||
}
|
||||
|
||||
fn hit_data_fail(
|
||||
|
||||
@@ -7,20 +7,26 @@ use wasmer::{FunctionEnv, FunctionEnvMut, Imports, StoreMut};
|
||||
use crate::script_implementations::wasm::script_resolver::WebAssemblyEnv;
|
||||
use crate::static_data::StaticData;
|
||||
|
||||
/// The battle registration
|
||||
mod battle;
|
||||
/// Battle random registration
|
||||
mod battle_random;
|
||||
/// Battle side registration
|
||||
mod battle_side;
|
||||
/// Choice queue registration.
|
||||
mod choice_queue;
|
||||
/// The executing move registration/
|
||||
mod executing_move;
|
||||
/// The hit data registration/
|
||||
mod hit_data;
|
||||
/// Learned move registration
|
||||
mod learned_move;
|
||||
/// The party registration.
|
||||
mod party;
|
||||
/// Pokemon registration
|
||||
mod pokemon;
|
||||
/// Turn choice registration
|
||||
mod turn_choice;
|
||||
mod hit_data;
|
||||
mod battle;
|
||||
|
||||
register! {
|
||||
fn dynamic_library_get_static_data(
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::script_implementations::wasm::script::WebAssemblyScript;
|
||||
use crate::script_implementations::wasm::script_resolver::WebAssemblyEnv;
|
||||
use crate::static_data::{ClampedStatisticSet, Species};
|
||||
use crate::static_data::{Item, StatisticSet};
|
||||
use crate::{ScriptCategory, StringKey};
|
||||
use crate::ScriptCategory;
|
||||
use std::ffi::{c_char, CStr};
|
||||
use wasmer::FunctionEnvMut;
|
||||
|
||||
@@ -134,11 +134,7 @@ register! {
|
||||
self_inflicted: u8
|
||||
) -> u8 {
|
||||
unsafe{
|
||||
if pokemon.value_func(&env).unwrap().change_stat_boost(transmute(stat), amount, self_inflicted == 1) {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
u8::from(pokemon.value_func(&env).unwrap().change_stat_boost(transmute(stat), amount, self_inflicted == 1))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,8 +190,7 @@ register! {
|
||||
) -> u8 {
|
||||
let name : *mut c_char = env.data().data().get_raw_pointer(name);
|
||||
let name = unsafe { CStr::from_ptr(name) };
|
||||
let key = StringKey::new(name.to_str().unwrap().into());
|
||||
if pokemon.value_func(&env).unwrap().has_held_item(&key) { 1 } else { 0 }
|
||||
u8::from(pokemon.value_func(&env).unwrap().has_held_item(&name.into()))
|
||||
}
|
||||
|
||||
fn pokemon_heal(
|
||||
@@ -204,7 +199,7 @@ register! {
|
||||
amount: u32,
|
||||
allow_revive: u8
|
||||
) -> u8 {
|
||||
if pokemon.value_func(&env).unwrap().heal(amount, allow_revive == 1) { 1 } else { 0 }
|
||||
u8::from(pokemon.value_func(&env).unwrap().heal(amount, allow_revive == 1))
|
||||
}
|
||||
|
||||
fn pokemon_clear_status(
|
||||
@@ -261,7 +256,7 @@ register! {
|
||||
) -> u8 {
|
||||
unsafe {
|
||||
let c_name = CStr::from_ptr(env.data().data().get_raw_pointer(name_ptr));
|
||||
if pokemon.value_func(&env).unwrap().has_volatile_script(&c_name.as_ref().into()) { 1 } else { 0 }
|
||||
u8::from(pokemon.value_func(&env).unwrap().has_volatile_script(&c_name.as_ref().into()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -149,13 +149,7 @@ fn effect_parameter_get_type(env: FunctionEnvMut<WebAssemblyEnv>, parameter: Ext
|
||||
fn effect_parameter_as_bool(env: FunctionEnvMut<WebAssemblyEnv>, parameter: ExternRef<EffectParameter>) -> u8 {
|
||||
let v = parameter.value_func(&env).unwrap();
|
||||
match v {
|
||||
EffectParameter::Bool(_, b) => {
|
||||
if *b {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
EffectParameter::Bool(_, b) => u8::from(*b),
|
||||
_ => panic!("Unexpected parameter type!"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ use crate::static_data::{
|
||||
ItemLibrary, LibrarySettings, MoveLibrary, SpeciesLibrary, StaticData, StatisticSet, TypeLibrary,
|
||||
};
|
||||
|
||||
/// Item registration.
|
||||
mod item;
|
||||
/// Moves data registration
|
||||
mod moves;
|
||||
|
||||
@@ -56,17 +56,9 @@ fn move_data_get_priority(env: FunctionEnvMut<WebAssemblyEnv>, move_data: Extern
|
||||
move_data.value_func(&env).unwrap().priority()
|
||||
}
|
||||
fn move_data_has_flag(env: FunctionEnvMut<WebAssemblyEnv>, move_data: ExternRef<MoveData>, flag: ExternRef<StringKey>) -> u8 {
|
||||
if move_data.value_func(&env).unwrap().has_flag(flag.value_func(&env).unwrap()) {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
u8::from(move_data.value_func(&env).unwrap().has_flag(flag.value_func(&env).unwrap()))
|
||||
}
|
||||
fn move_data_has_flag_by_hash(env: FunctionEnvMut<WebAssemblyEnv>, move_data: ExternRef<MoveData>, flag_hash: u32) -> u8 {
|
||||
if move_data.value_func(&env).unwrap().has_flag_by_hash(flag_hash) {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
u8::from(move_data.value_func(&env).unwrap().has_flag_by_hash(flag_hash))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ impl WebAssemblyScript {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get a pointer inside the WASM memory.
|
||||
pub(crate) fn get_wasm_pointer(&self) -> u32 {
|
||||
self.self_ptr
|
||||
}
|
||||
@@ -569,7 +570,7 @@ impl Script for WebAssemblyScript {
|
||||
let env = &self.environment;
|
||||
if let Some(func) = env.script_function_cache().prevent_stat_boost_change(env) {
|
||||
let ptr = env.allocate_temp(*prevent);
|
||||
let self_inflicted = if self_inflicted { 1_u8 } else { 0_u8 };
|
||||
let self_inflicted = u8::from(self_inflicted);
|
||||
call_func!(
|
||||
func,
|
||||
env,
|
||||
|
||||
@@ -173,6 +173,7 @@ script_function_cache! {
|
||||
}
|
||||
|
||||
impl ScriptFunctionCache {
|
||||
/// Get the name of a script.
|
||||
pub(crate) fn script_get_name(&self, env: &Arc<WebAssemblyEnvironmentData>) -> Option<TypedFunction<u32, u32>> {
|
||||
{
|
||||
let read_lock = self.script_get_name.read();
|
||||
@@ -191,6 +192,7 @@ impl ScriptFunctionCache {
|
||||
self.script_get_name.read().as_ref().cloned()
|
||||
}
|
||||
|
||||
/// Drop the memory of a CString inside the WASM memory.
|
||||
pub(crate) fn dealloc_cstring(&self, env: &Arc<WebAssemblyEnvironmentData>) -> Option<TypedFunction<u32, ()>> {
|
||||
{
|
||||
let read_lock = self.dealloc_cstring.read();
|
||||
|
||||
@@ -93,18 +93,15 @@ impl WebAssemblyScriptResolver {
|
||||
self.modules.push(module);
|
||||
}
|
||||
|
||||
/// Initialise all the data we need.
|
||||
/// Tells the script resolver we're done loading wasm modules, and to finalize the resolver.
|
||||
pub fn finalize(&mut self) {
|
||||
let mut imports = Imports::new();
|
||||
//let mut exports = Exports::new();
|
||||
|
||||
let env = FunctionEnv::new(
|
||||
&mut self.store_mut(),
|
||||
WebAssemblyEnv::new(Arc::downgrade(&self.environment_data)),
|
||||
);
|
||||
register_webassembly_funcs(&mut imports, &mut self.store_mut(), &env);
|
||||
//imports.register("env", exports);
|
||||
|
||||
for module in &self.modules {
|
||||
for import in module.imports() {
|
||||
if imports.get_export("env", import.name()).is_none() {
|
||||
|
||||
Reference in New Issue
Block a user