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:
@@ -4,16 +4,19 @@ use crate::static_data::{GrowthRate, GrowthRateLibrary};
|
||||
use std::ffi::{c_char, CStr};
|
||||
use std::ptr::drop_in_place;
|
||||
|
||||
/// Instantiates a new growth rate library with a capacity
|
||||
#[no_mangle]
|
||||
extern "C" fn growth_rate_library_new(capacity: usize) -> IdentifiablePointer<GrowthRateLibrary> {
|
||||
Box::new(GrowthRateLibrary::new(capacity)).into()
|
||||
}
|
||||
|
||||
/// Drops the growthrate library.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn growth_rate_library_drop(ptr: OwnedPtr<GrowthRateLibrary>) {
|
||||
drop_in_place(ptr)
|
||||
}
|
||||
|
||||
/// Calculates the level for a given growth key name and a certain experience.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn growth_rate_library_calculate_level(
|
||||
ptr: ExternPointer<GrowthRateLibrary>,
|
||||
@@ -24,6 +27,7 @@ unsafe extern "C" fn growth_rate_library_calculate_level(
|
||||
.calculate_level(&CStr::from_ptr(growth_rate).into(), experience)
|
||||
}
|
||||
|
||||
/// Calculates the experience for a given growth key name and a certain level.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn growth_rate_library_calculate_experience(
|
||||
ptr: ExternPointer<GrowthRateLibrary>,
|
||||
@@ -34,9 +38,10 @@ unsafe extern "C" fn growth_rate_library_calculate_experience(
|
||||
.calculate_experience(&CStr::from_ptr(growth_rate).into(), level)
|
||||
}
|
||||
|
||||
/// Adds a new growth rate with a name and value.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn growth_rate_library_add_growth_rate(
|
||||
ptr: ExternPointer<GrowthRateLibrary>,
|
||||
mut ptr: ExternPointer<GrowthRateLibrary>,
|
||||
name: BorrowedPtr<c_char>,
|
||||
growth_rate: OwnedPtr<Box<dyn GrowthRate>>,
|
||||
) {
|
||||
|
||||
@@ -3,16 +3,19 @@ use crate::ffi::{ExternPointer, IdentifiablePointer, OwnedPtr};
|
||||
use crate::static_data::LibrarySettings;
|
||||
use std::ptr::drop_in_place;
|
||||
|
||||
/// Creates a new settings library.
|
||||
#[no_mangle]
|
||||
extern "C" fn library_settings_new(max_level: LevelInt) -> IdentifiablePointer<LibrarySettings> {
|
||||
Box::new(LibrarySettings::new(max_level)).into()
|
||||
}
|
||||
|
||||
/// Drop a library settings object.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn library_settings_drop(ptr: OwnedPtr<LibrarySettings>) {
|
||||
drop_in_place(ptr)
|
||||
}
|
||||
|
||||
/// The highest level a Pokemon can be.
|
||||
#[no_mangle]
|
||||
extern "C" fn library_settings_maximum_level(ptr: ExternPointer<LibrarySettings>) -> LevelInt {
|
||||
ptr.as_ref().maximum_level()
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
/// The foreign function interface for the growth rate library.
|
||||
mod growth_rate_library;
|
||||
/// The foreign function interface for the library settings.
|
||||
mod library_settings;
|
||||
/// The foreign function interface for the nature library.
|
||||
mod nature_library;
|
||||
/// The foreign function interface for the static data.
|
||||
mod static_data;
|
||||
/// The foreign function interface for the type library.
|
||||
mod type_library;
|
||||
|
||||
use crate::ffi::{BorrowedPtr, IdentifiablePointer, OwnedPtr};
|
||||
@@ -10,6 +15,7 @@ use std::ffi::{c_char, CStr};
|
||||
use std::ptr::drop_in_place;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Generates foreign function interfaces for a DataLibrary trait implementation.
|
||||
macro_rules! library_interface {
|
||||
($library_type:ty, $return_type:ty) => {
|
||||
paste::paste! {
|
||||
|
||||
@@ -4,19 +4,22 @@ use std::ffi::{c_char, CStr, CString};
|
||||
use std::ptr::drop_in_place;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Creates a new nature library with a given capacity.
|
||||
#[no_mangle]
|
||||
extern "C" fn nature_library_new(capacity: usize) -> IdentifiablePointer<NatureLibrary> {
|
||||
Box::new(NatureLibrary::new(capacity)).into()
|
||||
}
|
||||
|
||||
/// Drop a nature library.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn nature_library_drop(ptr: OwnedPtr<NatureLibrary>) {
|
||||
drop_in_place(ptr);
|
||||
}
|
||||
|
||||
/// Adds a new nature with name to the library.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn nature_library_load_nature(
|
||||
ptr: ExternPointer<NatureLibrary>,
|
||||
mut ptr: ExternPointer<NatureLibrary>,
|
||||
name: BorrowedPtr<c_char>,
|
||||
nature: OwnedPtr<Arc<Nature>>,
|
||||
) {
|
||||
@@ -24,6 +27,7 @@ unsafe extern "C" fn nature_library_load_nature(
|
||||
.load_nature(CStr::from_ptr(name).into(), nature.as_ref().unwrap().clone())
|
||||
}
|
||||
|
||||
/// Gets a nature by name.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn nature_library_get_nature(
|
||||
ptr: ExternPointer<NatureLibrary>,
|
||||
@@ -36,6 +40,7 @@ unsafe extern "C" fn nature_library_get_nature(
|
||||
}
|
||||
}
|
||||
|
||||
/// Finds a nature name by nature.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn nature_library_get_nature_name(
|
||||
ptr: ExternPointer<NatureLibrary>,
|
||||
|
||||
@@ -5,54 +5,64 @@ use crate::static_data::{
|
||||
};
|
||||
use std::ptr::drop_in_place;
|
||||
|
||||
/// Instantiates a new data collection.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn static_data_new(settings: OwnedPtr<LibrarySettings>) -> IdentifiablePointer<StaticData> {
|
||||
Box::new(StaticData::new(*Box::from_raw(settings))).into()
|
||||
}
|
||||
|
||||
/// Drop a static data.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn static_data_drop(ptr: OwnedPtr<StaticData>) {
|
||||
drop_in_place(ptr)
|
||||
}
|
||||
|
||||
/// Several misc settings for the library.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn static_data_settings(data: ExternPointer<StaticData>) -> IdentifiablePointer<LibrarySettings> {
|
||||
unsafe extern "C" fn static_data_settings(mut data: ExternPointer<StaticData>) -> IdentifiablePointer<LibrarySettings> {
|
||||
(data.as_mut().settings() as *const LibrarySettings).into()
|
||||
}
|
||||
|
||||
/// All data for Pokemon species.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn static_data_species(data: ExternPointer<StaticData>) -> IdentifiablePointer<SpeciesLibrary> {
|
||||
unsafe extern "C" fn static_data_species(mut data: ExternPointer<StaticData>) -> IdentifiablePointer<SpeciesLibrary> {
|
||||
(data.as_mut().species_mut() as *const SpeciesLibrary).into()
|
||||
}
|
||||
|
||||
/// All data for the moves.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn static_data_moves(data: ExternPointer<StaticData>) -> IdentifiablePointer<MoveLibrary> {
|
||||
unsafe extern "C" fn static_data_moves(mut data: ExternPointer<StaticData>) -> IdentifiablePointer<MoveLibrary> {
|
||||
(data.as_mut().moves_mut() as *const MoveLibrary).into()
|
||||
}
|
||||
|
||||
/// All data for the items.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn static_data_items(data: ExternPointer<StaticData>) -> IdentifiablePointer<ItemLibrary> {
|
||||
unsafe extern "C" fn static_data_items(mut data: ExternPointer<StaticData>) -> IdentifiablePointer<ItemLibrary> {
|
||||
(data.as_mut().items_mut() as *const ItemLibrary).into()
|
||||
}
|
||||
|
||||
/// All data for growth rates.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn static_data_growth_rates(
|
||||
data: ExternPointer<StaticData>,
|
||||
mut data: ExternPointer<StaticData>,
|
||||
) -> IdentifiablePointer<GrowthRateLibrary> {
|
||||
(data.as_mut().growth_rates_mut() as *const GrowthRateLibrary).into()
|
||||
}
|
||||
|
||||
/// All data related to types and type effectiveness.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn static_data_types(data: ExternPointer<StaticData>) -> IdentifiablePointer<TypeLibrary> {
|
||||
unsafe extern "C" fn static_data_types(mut data: ExternPointer<StaticData>) -> IdentifiablePointer<TypeLibrary> {
|
||||
(data.as_mut().types_mut() as *const TypeLibrary).into()
|
||||
}
|
||||
|
||||
/// All data related to natures.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn static_data_natures(data: ExternPointer<StaticData>) -> IdentifiablePointer<NatureLibrary> {
|
||||
unsafe extern "C" fn static_data_natures(mut data: ExternPointer<StaticData>) -> IdentifiablePointer<NatureLibrary> {
|
||||
(data.as_mut().natures_mut() as *const NatureLibrary).into()
|
||||
}
|
||||
|
||||
/// All data related to abilities.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn static_data_abilities(data: ExternPointer<StaticData>) -> IdentifiablePointer<AbilityLibrary> {
|
||||
unsafe extern "C" fn static_data_abilities(mut data: ExternPointer<StaticData>) -> IdentifiablePointer<AbilityLibrary> {
|
||||
(data.as_mut().abilities_mut() as *const AbilityLibrary).into()
|
||||
}
|
||||
|
||||
@@ -3,16 +3,19 @@ use crate::static_data::{TypeIdentifier, TypeLibrary};
|
||||
use std::ffi::{c_char, CStr, CString};
|
||||
use std::ptr::drop_in_place;
|
||||
|
||||
/// Instantiates a new type library with a specific capacity.
|
||||
#[no_mangle]
|
||||
extern "C" fn type_library_new(capacity: usize) -> IdentifiablePointer<TypeLibrary> {
|
||||
Box::new(TypeLibrary::new(capacity)).into()
|
||||
}
|
||||
|
||||
/// Drops a type library.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn type_library_drop(ptr: OwnedPtr<TypeLibrary>) {
|
||||
drop_in_place(ptr);
|
||||
}
|
||||
|
||||
/// Gets the type identifier for a type with a name.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn type_library_get_type_id(
|
||||
ptr: ExternPointer<TypeLibrary>,
|
||||
@@ -28,6 +31,7 @@ unsafe extern "C" fn type_library_get_type_id(
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the type name from the type identifier.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn type_library_get_type_name(
|
||||
ptr: ExternPointer<TypeLibrary>,
|
||||
@@ -43,6 +47,7 @@ unsafe extern "C" fn type_library_get_type_name(
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the effectiveness for a single attacking type against a single defending type.
|
||||
#[no_mangle]
|
||||
extern "C" fn type_library_get_single_effectiveness(
|
||||
ptr: ExternPointer<TypeLibrary>,
|
||||
@@ -52,6 +57,9 @@ extern "C" fn type_library_get_single_effectiveness(
|
||||
ptr.as_ref().get_single_effectiveness(attacking, defending)
|
||||
}
|
||||
|
||||
/// Gets the effectiveness for a single attacking type against an amount of defending types.
|
||||
/// This is equivalent to running [`type_library_get_single_effectiveness`] on each defending type,
|
||||
/// and multiplying the results with each other.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn type_library_get_effectiveness(
|
||||
ptr: ExternPointer<TypeLibrary>,
|
||||
@@ -63,17 +71,19 @@ unsafe extern "C" fn type_library_get_effectiveness(
|
||||
ptr.as_ref().get_effectiveness(attacking, v)
|
||||
}
|
||||
|
||||
/// Registers a new type in the library.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn type_library_register_type(
|
||||
ptr: ExternPointer<TypeLibrary>,
|
||||
mut ptr: ExternPointer<TypeLibrary>,
|
||||
name: BorrowedPtr<c_char>,
|
||||
) -> TypeIdentifier {
|
||||
ptr.as_mut().register_type(&CStr::from_ptr(name).into())
|
||||
}
|
||||
|
||||
/// Sets the effectiveness for an attacking type against a defending type.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn type_library_set_effectiveness(
|
||||
ptr: ExternPointer<TypeLibrary>,
|
||||
mut ptr: ExternPointer<TypeLibrary>,
|
||||
attacking: TypeIdentifier,
|
||||
defending: TypeIdentifier,
|
||||
effectiveness: f32,
|
||||
|
||||
Reference in New Issue
Block a user