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:
@@ -5,6 +5,7 @@ use std::ffi::{c_char, CStr, CString};
|
||||
use std::ptr::drop_in_place;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Instantiates a new ability.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn ability_new(
|
||||
name: *const c_char,
|
||||
@@ -24,26 +25,31 @@ unsafe extern "C" fn ability_new(
|
||||
Arc::new(Ability::new(&name, &effect, parameters_vec)).into()
|
||||
}
|
||||
|
||||
/// Drops a reference counted ability.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn ability_drop(ptr: OwnedPtr<Arc<Ability>>) {
|
||||
drop_in_place(ptr)
|
||||
}
|
||||
|
||||
/// The name of the ability.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn ability_name(ptr: ExternPointer<Arc<Ability>>) -> OwnedPtr<c_char> {
|
||||
CString::new(ptr.as_ref().name().str()).unwrap().into_raw()
|
||||
}
|
||||
|
||||
/// The name of the script effect of the ability.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn ability_effect(ptr: ExternPointer<Arc<Ability>>) -> OwnedPtr<c_char> {
|
||||
CString::new(ptr.as_ref().effect().str()).unwrap().into_raw()
|
||||
}
|
||||
|
||||
/// The length of the parameters for the script effect of the ability.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn ability_parameter_length(ptr: ExternPointer<Arc<Ability>>) -> usize {
|
||||
ptr.as_ref().parameters().len()
|
||||
}
|
||||
|
||||
/// Gets a parameter for the script effect of the ability.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn ability_parameter_get(
|
||||
ptr: ExternPointer<Arc<Ability>>,
|
||||
|
||||
@@ -9,6 +9,7 @@ use std::ffi::{c_char, CStr, CString};
|
||||
use std::ptr::drop_in_place;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Instantiates a new form.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn form_new(
|
||||
name: *const c_char,
|
||||
@@ -60,11 +61,13 @@ unsafe extern "C" fn form_new(
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Drops a reference count for a form.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn form_drop(ptr: OwnedPtr<Arc<Form>>) {
|
||||
drop_in_place(ptr)
|
||||
}
|
||||
|
||||
/// The name of the form.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn form_name(ptr: ExternPointer<Arc<Form>>) -> OwnedPtr<c_char> {
|
||||
let name = ptr.as_ref().name();
|
||||
@@ -77,6 +80,7 @@ ffi_arc_getter!(Form, base_experience, u32);
|
||||
|
||||
ffi_vec_value_getters!(Form, types, TypeIdentifier);
|
||||
|
||||
/// The inherent values of a form of species that are used for the stats of a Pokemon.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn form_base_stats(ptr: ExternPointer<Arc<Form>>) -> IdentifiablePointer<StaticStatisticSet<u16>> {
|
||||
(ptr.as_ref().base_stats() as *const StaticStatisticSet<u16>).into()
|
||||
@@ -87,12 +91,9 @@ ffi_vec_stringkey_getters!(Form, hidden_abilities);
|
||||
|
||||
ffi_arc_getter!(Form, moves, BorrowedPtr<LearnableMoves>);
|
||||
|
||||
/// Check if the form has a specific flag set.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn form_has_flag(ptr: ExternPointer<Arc<Form>>, 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))
|
||||
}
|
||||
|
||||
@@ -3,22 +3,27 @@ use crate::ffi::{ExternPointer, OwnedPtr};
|
||||
use crate::static_data::{GrowthRate, LookupGrowthRate};
|
||||
use std::ptr::drop_in_place;
|
||||
|
||||
/// Instantiates a new lookup growth rate. The experience array should be the amount of experience
|
||||
/// required per level, with the first element being the experience required for level 1 (generally 0).
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn growth_rate_lookup_new(array: *const u32, length: usize) -> OwnedPtr<Box<dyn GrowthRate>> {
|
||||
let array = std::slice::from_raw_parts(array, length);
|
||||
Box::into_raw(Box::new(Box::new(LookupGrowthRate::new(array.to_vec()))))
|
||||
}
|
||||
|
||||
/// Drops the growth rate.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn growth_rate_lookup_drop(ptr: OwnedPtr<Box<dyn GrowthRate>>) {
|
||||
drop_in_place(ptr)
|
||||
}
|
||||
|
||||
/// Calculate the level something with this growth rate would have at a certain experience.
|
||||
#[no_mangle]
|
||||
extern "C" fn growth_rate_calculate_level(ptr: ExternPointer<Box<dyn GrowthRate>>, experience: u32) -> LevelInt {
|
||||
ptr.as_ref().calculate_level(experience)
|
||||
}
|
||||
|
||||
/// Calculate the experience something with this growth rate would have at a certain level.
|
||||
#[no_mangle]
|
||||
extern "C" fn growth_rate_calculate_experience(ptr: ExternPointer<Box<dyn GrowthRate>>, level: LevelInt) -> u32 {
|
||||
ptr.as_ref().calculate_experience(level)
|
||||
|
||||
@@ -6,6 +6,7 @@ use std::ffi::{c_char, CStr, CString};
|
||||
use std::ptr::drop_in_place;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Instantiates an item.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn item_new(
|
||||
name: *const c_char,
|
||||
@@ -24,11 +25,13 @@ unsafe extern "C" fn item_new(
|
||||
Arc::new(Item::new(&name, category, battle_category, price, flags_set)).into()
|
||||
}
|
||||
|
||||
/// Drops a reference counted item.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn item_drop(ptr: OwnedPtr<Arc<Item>>) {
|
||||
drop_in_place(ptr)
|
||||
}
|
||||
|
||||
/// The name of the item.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn item_name(ptr: ExternPointer<Arc<Item>>) -> OwnedPtr<c_char> {
|
||||
let name = ptr.as_ref().name();
|
||||
@@ -39,12 +42,9 @@ ffi_arc_getter!(Item, category, ItemCategory);
|
||||
ffi_arc_getter!(Item, battle_category, BattleItemCategory);
|
||||
ffi_arc_getter!(Item, price, i32);
|
||||
|
||||
/// Checks whether the item has a specific flag.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn item_has_flag(ptr: ExternPointer<Arc<Item>>, 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))
|
||||
}
|
||||
|
||||
@@ -4,19 +4,22 @@ use crate::static_data::LearnableMoves;
|
||||
use std::ffi::{c_char, CStr};
|
||||
use std::ptr::drop_in_place;
|
||||
|
||||
/// Instantiates a new Learnable Moves.
|
||||
#[no_mangle]
|
||||
extern "C" fn learnable_moves_new() -> OwnedPtr<LearnableMoves> {
|
||||
Box::into_raw(Box::new(LearnableMoves::new()))
|
||||
}
|
||||
|
||||
/// drops a learnablemoves struct.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn learnable_moves_drop(ptr: OwnedPtr<LearnableMoves>) {
|
||||
drop_in_place(ptr)
|
||||
}
|
||||
|
||||
/// Adds a new level move the Pokemon can learn.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn learnable_moves_add_level_move(
|
||||
ptr: ExternPointer<LearnableMoves>,
|
||||
mut ptr: ExternPointer<LearnableMoves>,
|
||||
level: LevelInt,
|
||||
move_name: BorrowedPtr<c_char>,
|
||||
) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -4,43 +4,59 @@ use crate::StringKey;
|
||||
use std::ffi::{c_char, CStr, CString};
|
||||
use std::ptr::drop_in_place;
|
||||
|
||||
/// The Foreign Function Interface for abilities
|
||||
mod ability;
|
||||
/// The Foreign Function Interface for forms
|
||||
mod form;
|
||||
/// The Foreign Function Interface for growth rates
|
||||
mod growth_rate;
|
||||
/// The Foreign Function Interface for items
|
||||
mod item;
|
||||
/// The Foreign Function Interface for learnable moves
|
||||
mod learnable_moves;
|
||||
/// The Foreign Function Interface for libraries
|
||||
mod libraries;
|
||||
/// The Foreign Function Interface for moves
|
||||
mod move_data;
|
||||
/// The Foreign Function Interface for natures
|
||||
mod nature;
|
||||
/// The Foreign Function Interface for species
|
||||
mod species;
|
||||
/// The Foreign Function Interface for sets of statistics
|
||||
mod statistic_set;
|
||||
|
||||
/// Instantiates an effect parameter with a boolean.
|
||||
#[no_mangle]
|
||||
extern "C" fn effect_parameter_new_bool(value: u8) -> OwnedPtr<EffectParameter> {
|
||||
Box::into_raw(Box::new((value == 1).into()))
|
||||
}
|
||||
|
||||
/// Instantiates an effect parameter with an integer.
|
||||
#[no_mangle]
|
||||
extern "C" fn effect_parameter_new_int(value: i64) -> OwnedPtr<EffectParameter> {
|
||||
Box::into_raw(Box::new(value.into()))
|
||||
}
|
||||
|
||||
/// Instantiates an effect parameter with a float.
|
||||
#[no_mangle]
|
||||
extern "C" fn effect_parameter_new_float(value: f32) -> OwnedPtr<EffectParameter> {
|
||||
Box::into_raw(Box::new(value.into()))
|
||||
}
|
||||
|
||||
/// Instantiates an effect parameter with a string.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn effect_parameter_new_string(value: *const c_char) -> OwnedPtr<EffectParameter> {
|
||||
let sk: StringKey = CStr::from_ptr(value).to_str().unwrap().into();
|
||||
Box::into_raw(Box::new(sk.into()))
|
||||
}
|
||||
|
||||
/// Drop an effect parameter.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn effect_parameter_drop(ptr: OwnedPtr<EffectParameter>) {
|
||||
drop_in_place(ptr)
|
||||
}
|
||||
|
||||
/// Get the type of an effect parameter.
|
||||
#[no_mangle]
|
||||
extern "C" fn effect_parameter_get_type(ptr: ExternPointer<EffectParameter>) -> u8 {
|
||||
match ptr.as_ref() {
|
||||
@@ -51,15 +67,17 @@ extern "C" fn effect_parameter_get_type(ptr: ExternPointer<EffectParameter>) ->
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the boolean contained in the effect parameter, panics if the effect parameter is not a bool.
|
||||
#[no_mangle]
|
||||
extern "C" fn effect_parameter_get_as_bool(ptr: ExternPointer<EffectParameter>) -> u8 {
|
||||
let p = ptr.as_ref();
|
||||
if let EffectParameter::Bool(_, b) = p {
|
||||
return if *b { 1 } else { 0 };
|
||||
return u8::from(*b);
|
||||
}
|
||||
panic!("Unexpected effect parameter. Expected bool, was: {}", p);
|
||||
}
|
||||
|
||||
/// Get the int contained in the effect parameter, panics if the effect parameter is not a int.
|
||||
#[no_mangle]
|
||||
extern "C" fn effect_parameter_get_as_int(ptr: ExternPointer<EffectParameter>) -> i64 {
|
||||
let p = ptr.as_ref();
|
||||
@@ -69,6 +87,7 @@ extern "C" fn effect_parameter_get_as_int(ptr: ExternPointer<EffectParameter>) -
|
||||
panic!("Unexpected effect parameter. Expected int, was: {}", p);
|
||||
}
|
||||
|
||||
/// Get the float contained in the effect parameter, panics if the effect parameter is not a float.
|
||||
#[no_mangle]
|
||||
extern "C" fn effect_parameter_get_as_float(ptr: ExternPointer<EffectParameter>) -> f32 {
|
||||
let p = ptr.as_ref();
|
||||
@@ -78,6 +97,7 @@ extern "C" fn effect_parameter_get_as_float(ptr: ExternPointer<EffectParameter>)
|
||||
panic!("Unexpected effect parameter. Expected float, was: {}", p);
|
||||
}
|
||||
|
||||
/// Get the string contained in the effect parameter, panics if the effect parameter is not a string.
|
||||
#[no_mangle]
|
||||
extern "C" fn effect_parameter_get_as_string(ptr: ExternPointer<EffectParameter>) -> OwnedPtr<c_char> {
|
||||
let p = ptr.as_ref();
|
||||
|
||||
@@ -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>,
|
||||
|
||||
@@ -3,6 +3,7 @@ use crate::static_data::{Nature, Statistic};
|
||||
use std::ptr::drop_in_place;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Instantiates a new statistic.
|
||||
#[no_mangle]
|
||||
extern "C" fn nature_new(
|
||||
increase_stat: Statistic,
|
||||
@@ -13,21 +14,26 @@ extern "C" fn nature_new(
|
||||
Nature::new(increase_stat, decrease_stat, increase_modifier, decrease_modifier).into()
|
||||
}
|
||||
|
||||
/// Reduce the reference count for a nature.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn nature_drop(ptr: OwnedPtr<Arc<Nature>>) {
|
||||
drop_in_place(ptr)
|
||||
}
|
||||
|
||||
/// The stat that should receive the increased modifier.
|
||||
#[no_mangle]
|
||||
extern "C" fn nature_increased_stat(ptr: ExternPointer<Arc<Nature>>) -> Statistic {
|
||||
ptr.as_ref().increased_stat()
|
||||
}
|
||||
|
||||
/// The stat that should receive the decreased modifier.
|
||||
#[no_mangle]
|
||||
extern "C" fn nature_decreased_stat(ptr: ExternPointer<Arc<Nature>>) -> Statistic {
|
||||
ptr.as_ref().decreased_stat()
|
||||
}
|
||||
|
||||
/// Calculates the modifier for a given stat. If it's the increased stat, returns the increased
|
||||
/// modifier, if it's the decreased stat, returns the decreased modifier. Otherwise returns 1.0
|
||||
#[no_mangle]
|
||||
extern "C" fn nature_get_stat_modifier(ptr: ExternPointer<Arc<Nature>>, stat: Statistic) -> f32 {
|
||||
ptr.as_ref().get_stat_modifier(stat)
|
||||
|
||||
@@ -6,6 +6,7 @@ use std::ffi::{c_char, CStr};
|
||||
use std::ptr::drop_in_place;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Creates a new species.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn species_new(
|
||||
id: u16,
|
||||
@@ -37,6 +38,7 @@ unsafe extern "C" fn species_new(
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Drop a reference to the species.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn species_drop(ptr: OwnedPtr<Arc<Species>>) {
|
||||
drop_in_place(ptr);
|
||||
@@ -48,9 +50,10 @@ ffi_arc_getter!(Species, gender_rate, f32);
|
||||
ffi_arc_stringkey_getter!(Species, growth_rate);
|
||||
ffi_arc_getter!(Species, capture_rate, u8);
|
||||
|
||||
/// Adds a new form to the species.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn species_add_form(
|
||||
species: ExternPointer<Arc<Species>>,
|
||||
mut species: ExternPointer<Arc<Species>>,
|
||||
name: BorrowedPtr<c_char>,
|
||||
form: OwnedPtr<Arc<Form>>,
|
||||
) {
|
||||
@@ -58,6 +61,7 @@ unsafe extern "C" fn species_add_form(
|
||||
species.as_mut().add_form(CStr::from_ptr(name).into(), form)
|
||||
}
|
||||
|
||||
/// Gets a form by name.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn species_get_form(
|
||||
species: ExternPointer<Arc<Species>>,
|
||||
|
||||
@@ -2,6 +2,7 @@ use crate::ffi::{ExternPointer, IdentifiablePointer, OwnedPtr};
|
||||
use crate::static_data::{StaticStatisticSet, Statistic, StatisticSet};
|
||||
use std::ptr::drop_in_place;
|
||||
|
||||
/// Basic foreign function interface for a statistic set.
|
||||
macro_rules! statistic_set {
|
||||
($num_type:ident) => {
|
||||
paste::paste!{
|
||||
@@ -61,6 +62,7 @@ statistic_set!(i8);
|
||||
statistic_set!(i16);
|
||||
statistic_set!(i32);
|
||||
|
||||
/// Basic foreign function interface for a static statistic set.
|
||||
macro_rules! static_statistic_set {
|
||||
($num_type:ident) => {
|
||||
paste::paste!{
|
||||
|
||||
Reference in New Issue
Block a user