Style and Clippy fixes.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-10-14 16:53:30 +02:00
parent 9efe1b4e22
commit 691bf7c12e
56 changed files with 354 additions and 249 deletions

View File

@@ -1,4 +1,4 @@
use crate::ffi::{ffi_arc_getter, ffi_getter, BorrowedPtr, ExternPointer, IdentifiablePointer, OwnedPtr};
use crate::ffi::{ffi_arc_getter, BorrowedPtr, ExternPointer, IdentifiablePointer, OwnedPtr};
use crate::static_data::{EffectParameter, MoveCategory, MoveData, MoveTarget, SecondaryEffect, TypeIdentifier};
use crate::StringKey;
use hashbrown::HashSet;
@@ -6,6 +6,7 @@ use std::ffi::{c_char, CStr, CString};
use std::ptr::drop_in_place;
use std::sync::Arc;
/// Instantiates a new move.
#[no_mangle]
unsafe extern "C" fn move_data_new(
name: *const c_char,
@@ -46,11 +47,13 @@ unsafe extern "C" fn move_data_new(
.into()
}
/// Drops a reference counted move.
#[no_mangle]
unsafe extern "C" fn move_data_drop(ptr: OwnedPtr<Arc<MoveData>>) {
drop_in_place(ptr)
}
/// The name of the move.
#[no_mangle]
unsafe extern "C" fn move_data_name(ptr: ExternPointer<Arc<MoveData>>) -> OwnedPtr<c_char> {
let name = ptr.as_ref().name();
@@ -65,6 +68,7 @@ ffi_arc_getter!(MoveData, base_usages, u8);
ffi_arc_getter!(MoveData, target, MoveTarget);
ffi_arc_getter!(MoveData, priority, i8);
/// The optional secondary effect the move has.
#[no_mangle]
unsafe extern "C" fn move_data_secondary_effect(
ptr: ExternPointer<Arc<MoveData>>,
@@ -77,16 +81,14 @@ unsafe extern "C" fn move_data_secondary_effect(
}
}
/// Arbitrary flags that can be applied to the move.
#[no_mangle]
unsafe extern "C" fn move_data_has_flag(ptr: ExternPointer<Arc<MoveData>>, flag: *const c_char) -> u8 {
let flag = CStr::from_ptr(flag).into();
if ptr.as_ref().has_flag(&flag) {
1
} else {
0
}
u8::from(ptr.as_ref().has_flag(&flag))
}
/// Instantiates a new Secondary Effect.
#[no_mangle]
unsafe extern "C" fn secondary_effect_new(
chance: f32,
@@ -108,23 +110,31 @@ unsafe extern "C" fn secondary_effect_new(
.into()
}
/// Drop a secondary effect.
#[no_mangle]
unsafe extern "C" fn secondary_effect_drop(ptr: OwnedPtr<SecondaryEffect>) {
drop_in_place(ptr)
}
ffi_getter!(SecondaryEffect, chance, f32);
/// The chance the effect triggers.
#[no_mangle]
unsafe extern "C" fn secondary_effect_chance(ptr: ExternPointer<SecondaryEffect>) -> f32 {
ptr.as_ref().chance()
}
/// The name of the effect.
#[no_mangle]
unsafe extern "C" fn secondary_effect_effect_name(ptr: ExternPointer<SecondaryEffect>) -> OwnedPtr<c_char> {
CString::new(ptr.as_ref().effect_name().str()).unwrap().into_raw()
}
/// The length of parameters of the effect.
#[no_mangle]
unsafe extern "C" fn secondary_effect_parameter_length(ptr: ExternPointer<SecondaryEffect>) -> usize {
ptr.as_ref().parameters().len()
}
/// Get a parameter of the effect.
#[no_mangle]
unsafe extern "C" fn secondary_effect_parameter_get(
ptr: ExternPointer<SecondaryEffect>,