Major rework of extern ref system for WASM, fixes most possible panics in WASM handling
All checks were successful
continuous-integration/drone Build is passing
All checks were successful
continuous-integration/drone Build is passing
This commit is contained in:
@@ -12,7 +12,7 @@ extern "C" fn turn_choice_drop(choice: OwnedPtr<TurnChoice>) {
|
||||
|
||||
/// Get the user of the given choice.
|
||||
#[no_mangle]
|
||||
extern "C" fn turn_choice_user(choice: ExternPointer<TurnChoice>) -> IdentifiablePointer<Arc<Pokemon>> {
|
||||
extern "C" fn turn_choice_user(choice: ExternPointer<TurnChoice>) -> IdentifiablePointer<Pokemon> {
|
||||
choice.as_ref().user().clone().into()
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ extern "C" fn turn_choice_fail(choice: ExternPointer<TurnChoice>) {
|
||||
/// Creates a new Turn Choice with a move to use.
|
||||
#[no_mangle]
|
||||
extern "C" fn turn_choice_move_new(
|
||||
user: ExternPointer<Arc<Pokemon>>,
|
||||
user: ExternPointer<Pokemon>,
|
||||
learned_move: ExternPointer<Arc<LearnedMove>>,
|
||||
target_side: u8,
|
||||
target_index: u8,
|
||||
@@ -94,12 +94,12 @@ extern "C" fn turn_choice_move_priority(choice: ExternPointer<TurnChoice>) -> Na
|
||||
|
||||
/// Creates a new Turn Choice for the user to flee.
|
||||
#[no_mangle]
|
||||
extern "C" fn turn_choice_flee_new(user: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<TurnChoice> {
|
||||
extern "C" fn turn_choice_flee_new(user: ExternPointer<Pokemon>) -> IdentifiablePointer<TurnChoice> {
|
||||
Box::new(TurnChoice::Flee(FleeChoice::new(user.as_ref().clone()))).into()
|
||||
}
|
||||
|
||||
/// Creates a new Turn Choice for the user to pass the turn.
|
||||
#[no_mangle]
|
||||
extern "C" fn turn_choice_pass_new(user: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<TurnChoice> {
|
||||
extern "C" fn turn_choice_pass_new(user: ExternPointer<Pokemon>) -> IdentifiablePointer<TurnChoice> {
|
||||
Box::new(TurnChoice::Pass(PassChoice::new(user.as_ref().clone()))).into()
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ use crate::dynamic_data::{BattleStatCalculator, Gen7BattleStatCalculator, Pokemo
|
||||
use crate::ffi::{ExternPointer, IdentifiablePointer, NativeResult, OwnedPtr};
|
||||
use crate::static_data::{Statistic, StatisticSet};
|
||||
use std::ptr::drop_in_place;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Creates a new Gen 7 battle stat calculator
|
||||
#[no_mangle]
|
||||
@@ -23,7 +22,7 @@ extern "C" fn battle_stat_calculator_drop(ptr: OwnedPtr<Box<dyn BattleStatCalcul
|
||||
#[no_mangle]
|
||||
extern "C" fn battle_stat_calculator_calculate_flat_stats(
|
||||
ptr: ExternPointer<Box<dyn BattleStatCalculator>>,
|
||||
pokemon: ExternPointer<Arc<Pokemon>>,
|
||||
pokemon: ExternPointer<Pokemon>,
|
||||
mut stats: ExternPointer<Box<StatisticSet<u32>>>,
|
||||
) -> NativeResult<()> {
|
||||
ptr.as_ref()
|
||||
@@ -35,7 +34,7 @@ extern "C" fn battle_stat_calculator_calculate_flat_stats(
|
||||
#[no_mangle]
|
||||
extern "C" fn battle_stat_calculator_calculate_flat_stat(
|
||||
ptr: ExternPointer<Box<dyn BattleStatCalculator>>,
|
||||
pokemon: ExternPointer<Arc<Pokemon>>,
|
||||
pokemon: ExternPointer<Pokemon>,
|
||||
stat: Statistic,
|
||||
) -> NativeResult<u32> {
|
||||
ptr.as_ref().calculate_flat_stat(pokemon.as_ref(), stat).into()
|
||||
@@ -45,7 +44,7 @@ extern "C" fn battle_stat_calculator_calculate_flat_stat(
|
||||
#[no_mangle]
|
||||
extern "C" fn battle_stat_calculator_calculate_boosted_stats(
|
||||
ptr: ExternPointer<Box<dyn BattleStatCalculator>>,
|
||||
pokemon: ExternPointer<Arc<Pokemon>>,
|
||||
pokemon: ExternPointer<Pokemon>,
|
||||
mut stats: ExternPointer<Box<StatisticSet<u32>>>,
|
||||
) -> NativeResult<()> {
|
||||
ptr.as_ref()
|
||||
@@ -57,7 +56,7 @@ extern "C" fn battle_stat_calculator_calculate_boosted_stats(
|
||||
#[no_mangle]
|
||||
extern "C" fn battle_stat_calculator_calculate_boosted_stat(
|
||||
ptr: ExternPointer<Box<dyn BattleStatCalculator>>,
|
||||
pokemon: ExternPointer<Arc<Pokemon>>,
|
||||
pokemon: ExternPointer<Pokemon>,
|
||||
stat: Statistic,
|
||||
) -> NativeResult<u32> {
|
||||
ptr.as_ref().calculate_boosted_stat(pokemon.as_ref(), stat).into()
|
||||
|
||||
@@ -9,18 +9,18 @@ use std::sync::Arc;
|
||||
/// Instantiates a new DynamicLibrary with given parameters.
|
||||
#[no_mangle]
|
||||
extern "C" fn dynamic_library_new(
|
||||
static_data: OwnedPtr<Box<dyn StaticData>>,
|
||||
stat_calculator: OwnedPtr<Box<dyn BattleStatCalculator>>,
|
||||
damage_library: OwnedPtr<Box<dyn DamageLibrary>>,
|
||||
misc_library: OwnedPtr<Box<dyn MiscLibrary>>,
|
||||
static_data: OwnedPtr<Arc<dyn StaticData>>,
|
||||
stat_calculator: OwnedPtr<Arc<dyn BattleStatCalculator>>,
|
||||
damage_library: OwnedPtr<Arc<dyn DamageLibrary>>,
|
||||
misc_library: OwnedPtr<Arc<dyn MiscLibrary>>,
|
||||
script_resolver: OwnedPtr<Box<dyn ScriptResolver>>,
|
||||
) -> IdentifiablePointer<Arc<dyn DynamicLibrary>> {
|
||||
unsafe {
|
||||
let a: Arc<dyn DynamicLibrary> = Arc::new(DynamicLibraryImpl::new(
|
||||
*Box::from_raw(static_data),
|
||||
*Box::from_raw(stat_calculator),
|
||||
*Box::from_raw(damage_library),
|
||||
*Box::from_raw(misc_library),
|
||||
static_data.read(),
|
||||
stat_calculator.read(),
|
||||
damage_library.read(),
|
||||
misc_library.read(),
|
||||
*Box::from_raw(script_resolver),
|
||||
));
|
||||
a.into()
|
||||
@@ -37,8 +37,8 @@ extern "C" fn dynamic_library_drop(ptr: OwnedPtr<Arc<dyn DynamicLibrary>>) {
|
||||
#[no_mangle]
|
||||
extern "C" fn dynamic_library_get_static_data(
|
||||
ptr: ExternPointer<Arc<dyn DynamicLibrary>>,
|
||||
) -> IdentifiablePointer<Box<dyn StaticData>> {
|
||||
ptr.as_ref().static_data().into()
|
||||
) -> IdentifiablePointer<Arc<dyn StaticData>> {
|
||||
ptr.as_ref().static_data().clone().into()
|
||||
}
|
||||
|
||||
/// The stat calculator deals with the calculation of flat and boosted stats, based on the
|
||||
@@ -46,16 +46,16 @@ extern "C" fn dynamic_library_get_static_data(
|
||||
#[no_mangle]
|
||||
extern "C" fn dynamic_library_get_stat_calculator(
|
||||
ptr: ExternPointer<Arc<dyn DynamicLibrary>>,
|
||||
) -> IdentifiablePointer<Box<dyn BattleStatCalculator>> {
|
||||
ptr.as_ref().stat_calculator().into()
|
||||
) -> IdentifiablePointer<Arc<dyn BattleStatCalculator>> {
|
||||
ptr.as_ref().stat_calculator().clone().into()
|
||||
}
|
||||
|
||||
/// The damage calculator deals with the calculation of things relating to damage.
|
||||
#[no_mangle]
|
||||
extern "C" fn dynamic_library_get_damage_calculator(
|
||||
ptr: ExternPointer<Arc<dyn DynamicLibrary>>,
|
||||
) -> IdentifiablePointer<Box<dyn DamageLibrary>> {
|
||||
ptr.as_ref().damage_calculator().into()
|
||||
) -> IdentifiablePointer<Arc<dyn DamageLibrary>> {
|
||||
ptr.as_ref().damage_calculator().clone().into()
|
||||
}
|
||||
|
||||
/// The Misc Library holds minor functions that do not fall in any of the other libraries and
|
||||
@@ -63,6 +63,6 @@ extern "C" fn dynamic_library_get_damage_calculator(
|
||||
#[no_mangle]
|
||||
extern "C" fn dynamic_library_get_misc_library(
|
||||
ptr: ExternPointer<Arc<dyn DynamicLibrary>>,
|
||||
) -> IdentifiablePointer<Box<dyn MiscLibrary>> {
|
||||
ptr.as_ref().misc_library().into()
|
||||
) -> IdentifiablePointer<Arc<dyn MiscLibrary>> {
|
||||
ptr.as_ref().misc_library().clone().into()
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ use std::sync::Arc;
|
||||
#[no_mangle]
|
||||
extern "C" fn battle_new(
|
||||
library: ExternPointer<Arc<dyn DynamicLibrary>>,
|
||||
parties: *const OwnedPtr<BattleParty>,
|
||||
parties: *const OwnedPtr<Arc<BattleParty>>,
|
||||
parties_length: usize,
|
||||
can_flee: u8,
|
||||
number_of_sides: u8,
|
||||
@@ -19,7 +19,7 @@ extern "C" fn battle_new(
|
||||
// NOTE: Split into two due to u128 not being ABI safe: https://github.com/rust-lang/rust/issues/54341
|
||||
random_seed_1: u64,
|
||||
random_seed_2: u64,
|
||||
) -> IdentifiablePointer<Arc<Battle>> {
|
||||
) -> IdentifiablePointer<Battle> {
|
||||
let parties = unsafe {
|
||||
std::slice::from_raw_parts(parties, parties_length)
|
||||
.iter()
|
||||
@@ -59,9 +59,12 @@ extern "C" fn battle_parties_length(ptr: ExternPointer<Arc<Battle>>) -> usize {
|
||||
|
||||
/// Get a party in the battle.
|
||||
#[no_mangle]
|
||||
extern "C" fn battle_parties_get(ptr: ExternPointer<Arc<Battle>>, index: usize) -> IdentifiablePointer<BattleParty> {
|
||||
extern "C" fn battle_parties_get(
|
||||
ptr: ExternPointer<Arc<Battle>>,
|
||||
index: usize,
|
||||
) -> IdentifiablePointer<Arc<BattleParty>> {
|
||||
if let Some(v) = ptr.as_ref().parties().get(index) {
|
||||
(v as *const BattleParty).into()
|
||||
v.clone().into()
|
||||
} else {
|
||||
IdentifiablePointer::none()
|
||||
}
|
||||
@@ -103,8 +106,8 @@ extern "C" fn battle_sides_get(ptr: ExternPointer<Arc<Battle>>, index: usize) ->
|
||||
|
||||
/// The RNG used for the battle.
|
||||
#[no_mangle]
|
||||
extern "C" fn battle_random(ptr: ExternPointer<Arc<Battle>>) -> IdentifiablePointer<BattleRandom> {
|
||||
(ptr.as_ref().random() as *const BattleRandom).into()
|
||||
extern "C" fn battle_random(ptr: ExternPointer<Arc<Battle>>) -> IdentifiablePointer<Arc<BattleRandom>> {
|
||||
ptr.as_ref().random().clone().into()
|
||||
}
|
||||
|
||||
/// Whether or not the battle has ended.
|
||||
@@ -150,11 +153,7 @@ extern "C" fn battle_last_turn_time(ptr: ExternPointer<Arc<Battle>>) -> u64 {
|
||||
|
||||
/// Get a Pokemon on the battlefield, on a specific side and an index on that side.
|
||||
#[no_mangle]
|
||||
extern "C" fn battle_get_pokemon(
|
||||
ptr: ExternPointer<Arc<Battle>>,
|
||||
side: u8,
|
||||
index: u8,
|
||||
) -> IdentifiablePointer<Arc<Pokemon>> {
|
||||
extern "C" fn battle_get_pokemon(ptr: ExternPointer<Arc<Battle>>, side: u8, index: u8) -> IdentifiablePointer<Pokemon> {
|
||||
if let Some(v) = ptr.as_ref().get_pokemon(side, index) {
|
||||
v.into()
|
||||
} else {
|
||||
|
||||
@@ -58,7 +58,7 @@ extern "C" fn battle_party_has_pokemon_not_in_field(ptr: ExternPointer<Arc<Battl
|
||||
extern "C" fn battle_party_get_pokemon(
|
||||
ptr: ExternPointer<Arc<BattleParty>>,
|
||||
index: usize,
|
||||
) -> IdentifiablePointer<Arc<Pokemon>> {
|
||||
) -> IdentifiablePointer<Pokemon> {
|
||||
if let Some(v) = ptr.as_ref().get_pokemon(index) {
|
||||
v.into()
|
||||
} else {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use crate::dynamic_data::{Event, Pokemon};
|
||||
use crate::ffi::{ExternPointer, IdentifiablePointer};
|
||||
use std::sync::Arc;
|
||||
|
||||
/// The kind of the event.
|
||||
#[no_mangle]
|
||||
@@ -67,7 +66,7 @@ event_ffi!(
|
||||
/// The index of the Pokemon that got switched in/out on its side
|
||||
index: u8,
|
||||
/// The new Pokemon that will be on the spot. If none, the spot will be null.
|
||||
pokemon: IdentifiablePointer<Arc<Pokemon>>,
|
||||
pokemon: IdentifiablePointer<Pokemon>,
|
||||
},
|
||||
{
|
||||
return SwitchData{
|
||||
|
||||
@@ -61,5 +61,6 @@ extern "C" fn learned_move_restore_all_uses(learned_move: ExternPointer<Arc<Lear
|
||||
/// Restore the remaining PP by a certain amount. Will prevent it from going above max PP.
|
||||
#[no_mangle]
|
||||
extern "C" fn learned_move_restore_uses(learned_move: ExternPointer<Arc<LearnedMove>>, amount: u8) -> NativeResult<()> {
|
||||
learned_move.as_ref().restore_uses(amount).into()
|
||||
learned_move.as_ref().restore_uses(amount);
|
||||
NativeResult::ok(())
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ extern "C" fn pokemon_new(
|
||||
gender: Gender,
|
||||
coloring: u8,
|
||||
nature: *const c_char,
|
||||
) -> NativeResult<IdentifiablePointer<Arc<Pokemon>>> {
|
||||
) -> NativeResult<IdentifiablePointer<Pokemon>> {
|
||||
let nature = unsafe { CStr::from_ptr(nature) }.into();
|
||||
let pokemon = Pokemon::new(
|
||||
library.as_ref().clone(),
|
||||
@@ -39,44 +39,44 @@ extern "C" fn pokemon_new(
|
||||
&nature,
|
||||
);
|
||||
match pokemon {
|
||||
Ok(pokemon) => NativeResult::ok(Arc::new(pokemon).into()),
|
||||
Ok(pokemon) => NativeResult::ok(pokemon.into()),
|
||||
Err(err) => NativeResult::err(err),
|
||||
}
|
||||
}
|
||||
|
||||
/// Drops an Arc reference held by the FFI.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn pokemon_drop(ptr: OwnedPtr<Arc<Pokemon>>) {
|
||||
unsafe extern "C" fn pokemon_drop(ptr: OwnedPtr<Pokemon>) {
|
||||
drop_in_place(ptr);
|
||||
}
|
||||
|
||||
/// The library data of the Pokemon.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_library(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<Arc<dyn DynamicLibrary>> {
|
||||
extern "C" fn pokemon_library(ptr: ExternPointer<Pokemon>) -> IdentifiablePointer<Arc<dyn DynamicLibrary>> {
|
||||
ptr.as_ref().library().clone().into()
|
||||
}
|
||||
|
||||
/// The species of the Pokemon.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_species(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<Arc<dyn Species>> {
|
||||
extern "C" fn pokemon_species(ptr: ExternPointer<Pokemon>) -> IdentifiablePointer<Arc<dyn Species>> {
|
||||
ptr.as_ref().species().into()
|
||||
}
|
||||
|
||||
/// The form of the Pokemon.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_form(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<Arc<dyn Form>> {
|
||||
extern "C" fn pokemon_form(ptr: ExternPointer<Pokemon>) -> IdentifiablePointer<Arc<dyn Form>> {
|
||||
ptr.as_ref().form().into()
|
||||
}
|
||||
|
||||
/// The species that should be displayed to the user. This handles stuff like the Illusion ability.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_display_species(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<Arc<dyn Species>> {
|
||||
extern "C" fn pokemon_display_species(ptr: ExternPointer<Pokemon>) -> IdentifiablePointer<Arc<dyn Species>> {
|
||||
ptr.as_ref().display_species().into()
|
||||
}
|
||||
|
||||
/// The form that should be displayed to the user. This handles stuff like the Illusion ability.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_display_form(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<Arc<dyn Form>> {
|
||||
extern "C" fn pokemon_display_form(ptr: ExternPointer<Pokemon>) -> IdentifiablePointer<Arc<dyn Form>> {
|
||||
ptr.as_ref().display_form().into()
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ ffi_arc_getter!(Pokemon, coloring, u8);
|
||||
|
||||
/// Gets the held item of a Pokemon
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_held_item(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<Arc<dyn Item>> {
|
||||
extern "C" fn pokemon_held_item(ptr: ExternPointer<Pokemon>) -> IdentifiablePointer<Arc<dyn Item>> {
|
||||
if let Some(v) = ptr.as_ref().held_item().read().as_ref() {
|
||||
v.clone().into()
|
||||
} else {
|
||||
@@ -98,7 +98,7 @@ extern "C" fn pokemon_held_item(ptr: ExternPointer<Arc<Pokemon>>) -> Identifiabl
|
||||
|
||||
/// Checks whether the Pokemon is holding a specific item.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_has_held_item(ptr: ExternPointer<Arc<Pokemon>>, name: *const c_char) -> u8 {
|
||||
extern "C" fn pokemon_has_held_item(ptr: ExternPointer<Pokemon>, name: *const c_char) -> u8 {
|
||||
let name = unsafe { CStr::from_ptr(name) }.into();
|
||||
u8::from(ptr.as_ref().has_held_item(&name))
|
||||
}
|
||||
@@ -106,7 +106,7 @@ extern "C" fn pokemon_has_held_item(ptr: ExternPointer<Arc<Pokemon>>, name: *con
|
||||
/// Changes the held item of the Pokemon. Returns the previously held item.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_set_held_item(
|
||||
ptr: ExternPointer<Arc<Pokemon>>,
|
||||
ptr: ExternPointer<Pokemon>,
|
||||
item: ExternPointer<Arc<dyn Item>>,
|
||||
) -> IdentifiablePointer<Arc<dyn Item>> {
|
||||
if let Some(v) = ptr.as_ref().set_held_item(item.as_ref()) {
|
||||
@@ -118,7 +118,7 @@ extern "C" fn pokemon_set_held_item(
|
||||
|
||||
/// Removes the held item from the Pokemon. Returns the previously held item.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_remove_held_item(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<Arc<dyn Item>> {
|
||||
extern "C" fn pokemon_remove_held_item(ptr: ExternPointer<Pokemon>) -> IdentifiablePointer<Arc<dyn Item>> {
|
||||
if let Some(v) = ptr.as_ref().remove_held_item() {
|
||||
v.into()
|
||||
} else {
|
||||
@@ -128,7 +128,7 @@ extern "C" fn pokemon_remove_held_item(ptr: ExternPointer<Arc<Pokemon>>) -> Iden
|
||||
|
||||
/// Makes the Pokemon uses its held item.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_consume_held_item(ptr: ExternPointer<Arc<Pokemon>>) -> NativeResult<u8> {
|
||||
extern "C" fn pokemon_consume_held_item(ptr: ExternPointer<Pokemon>) -> NativeResult<u8> {
|
||||
match ptr.as_ref().consume_held_item() {
|
||||
Ok(v) => NativeResult::ok(u8::from(v)),
|
||||
Err(err) => NativeResult::err(err),
|
||||
@@ -142,7 +142,7 @@ ffi_arc_getter!(Pokemon, height, f32);
|
||||
|
||||
/// An optional nickname of the Pokemon.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_nickname(ptr: ExternPointer<Arc<Pokemon>>) -> NativeResult<*mut c_char> {
|
||||
extern "C" fn pokemon_nickname(ptr: ExternPointer<Pokemon>) -> NativeResult<*mut c_char> {
|
||||
let name = ptr.as_ref().nickname();
|
||||
if let Some(v) = name {
|
||||
match CString::new(v.as_str()) {
|
||||
@@ -156,13 +156,13 @@ extern "C" fn pokemon_nickname(ptr: ExternPointer<Arc<Pokemon>>) -> NativeResult
|
||||
|
||||
/// Whether the actual ability on the form is a hidden ability.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_real_ability_is_hidden(ptr: ExternPointer<Arc<Pokemon>>) -> u8 {
|
||||
extern "C" fn pokemon_real_ability_is_hidden(ptr: ExternPointer<Pokemon>) -> u8 {
|
||||
u8::from(ptr.as_ref().real_ability().hidden)
|
||||
}
|
||||
|
||||
/// The index of the actual ability on the form.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_real_ability_index(ptr: ExternPointer<Arc<Pokemon>>) -> u8 {
|
||||
extern "C" fn pokemon_real_ability_index(ptr: ExternPointer<Pokemon>) -> u8 {
|
||||
ptr.as_ref().real_ability().index
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ ffi_vec_value_getters!(Pokemon, Pokemon, types, TypeIdentifier);
|
||||
/// a null pointer otherwise.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_learned_move_get(
|
||||
ptr: ExternPointer<Arc<Pokemon>>,
|
||||
ptr: ExternPointer<Pokemon>,
|
||||
index: usize,
|
||||
) -> IdentifiablePointer<Arc<LearnedMove>> {
|
||||
if let Some(Some(v)) = ptr.as_ref().learned_moves().read().get(index) {
|
||||
@@ -184,26 +184,26 @@ extern "C" fn pokemon_learned_move_get(
|
||||
|
||||
/// The stats of the Pokemon when disregarding any stat boosts.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_flat_stats(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<StatisticSet<u32>> {
|
||||
(ptr.as_ref().flat_stats() as *const StatisticSet<u32>).into()
|
||||
extern "C" fn pokemon_flat_stats(ptr: ExternPointer<Pokemon>) -> IdentifiablePointer<Arc<StatisticSet<u32>>> {
|
||||
ptr.as_ref().flat_stats().clone().into()
|
||||
}
|
||||
|
||||
/// The stats of the Pokemon including the stat boosts.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_boosted_stats(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<StatisticSet<u32>> {
|
||||
(ptr.as_ref().boosted_stats() as *const StatisticSet<u32>).into()
|
||||
extern "C" fn pokemon_boosted_stats(ptr: ExternPointer<Pokemon>) -> IdentifiablePointer<Arc<StatisticSet<u32>>> {
|
||||
ptr.as_ref().boosted_stats().clone().into()
|
||||
}
|
||||
|
||||
/// Get the stat boosts for a specific stat.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_get_stat_boost(ptr: ExternPointer<Arc<Pokemon>>, statistic: Statistic) -> i8 {
|
||||
extern "C" fn pokemon_get_stat_boost(ptr: ExternPointer<Pokemon>, statistic: Statistic) -> i8 {
|
||||
ptr.as_ref().stat_boost(statistic)
|
||||
}
|
||||
|
||||
/// Change a boosted stat by a certain amount.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_change_stat_boost(
|
||||
ptr: ExternPointer<Arc<Pokemon>>,
|
||||
ptr: ExternPointer<Pokemon>,
|
||||
stat: Statistic,
|
||||
diff_amount: i8,
|
||||
self_inflicted: u8,
|
||||
@@ -216,14 +216,14 @@ extern "C" fn pokemon_change_stat_boost(
|
||||
|
||||
/// Gets a [individual value](https://bulbapedia.bulbagarden.net/wiki/Individual_values) of the Pokemon.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_get_individual_value(ptr: ExternPointer<Arc<Pokemon>>, stat: Statistic) -> u8 {
|
||||
extern "C" fn pokemon_get_individual_value(ptr: ExternPointer<Pokemon>, stat: Statistic) -> u8 {
|
||||
ptr.as_ref().individual_values().get_stat(stat)
|
||||
}
|
||||
|
||||
/// Modifies a [individual value](https://bulbapedia.bulbagarden.net/wiki/Individual_values) of the Pokemon.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_set_individual_value(
|
||||
ptr: ExternPointer<Arc<Pokemon>>,
|
||||
ptr: ExternPointer<Pokemon>,
|
||||
stat: Statistic,
|
||||
value: u8,
|
||||
) -> NativeResult<()> {
|
||||
@@ -233,17 +233,13 @@ extern "C" fn pokemon_set_individual_value(
|
||||
|
||||
/// Gets a [effort value](https://bulbapedia.bulbagarden.net/wiki/Effort_values) of the Pokemon.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_get_effort_value(ptr: ExternPointer<Arc<Pokemon>>, stat: Statistic) -> u8 {
|
||||
extern "C" fn pokemon_get_effort_value(ptr: ExternPointer<Pokemon>, stat: Statistic) -> u8 {
|
||||
ptr.as_ref().effort_values().get_stat(stat)
|
||||
}
|
||||
|
||||
/// Modifies a [effort value](https://bulbapedia.bulbagarden.net/wiki/Effort_values) of the Pokemon.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_set_effort_value(
|
||||
ptr: ExternPointer<Arc<Pokemon>>,
|
||||
stat: Statistic,
|
||||
value: u8,
|
||||
) -> NativeResult<()> {
|
||||
extern "C" fn pokemon_set_effort_value(ptr: ExternPointer<Pokemon>, stat: Statistic, value: u8) -> NativeResult<()> {
|
||||
ptr.as_ref().effort_values().set_stat(stat, value);
|
||||
ptr.as_ref().recalculate_flat_stats().into()
|
||||
}
|
||||
@@ -251,7 +247,7 @@ extern "C" fn pokemon_set_effort_value(
|
||||
/// Gets the data for the battle the Pokemon is currently in. If the Pokemon is not in a battle, this
|
||||
/// returns null.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_get_battle(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<Arc<Battle>> {
|
||||
extern "C" fn pokemon_get_battle(ptr: ExternPointer<Pokemon>) -> IdentifiablePointer<Battle> {
|
||||
if let Some(v) = ptr.as_ref().get_battle() {
|
||||
v.into()
|
||||
} else {
|
||||
@@ -262,27 +258,27 @@ extern "C" fn pokemon_get_battle(ptr: ExternPointer<Arc<Pokemon>>) -> Identifiab
|
||||
/// Get the index of the side of the battle the Pokemon is in. If the Pokemon
|
||||
/// is not on the battlefield, this always returns 0.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_get_battle_side_index(ptr: ExternPointer<Arc<Pokemon>>) -> u8 {
|
||||
extern "C" fn pokemon_get_battle_side_index(ptr: ExternPointer<Pokemon>) -> u8 {
|
||||
ptr.as_ref().get_battle_side_index().unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Get the index of the slot on the side of the battle the Pokemon is in. If the Pokemon
|
||||
/// is not on the battlefield, this always returns 0.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_get_battle_index(ptr: ExternPointer<Arc<Pokemon>>) -> u8 {
|
||||
extern "C" fn pokemon_get_battle_index(ptr: ExternPointer<Pokemon>) -> u8 {
|
||||
ptr.as_ref().get_battle_index().unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Returns whether something overrides the ability.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_is_ability_overriden(ptr: ExternPointer<Arc<Pokemon>>) -> u8 {
|
||||
extern "C" fn pokemon_is_ability_overriden(ptr: ExternPointer<Pokemon>) -> u8 {
|
||||
u8::from(ptr.as_ref().is_ability_overriden())
|
||||
}
|
||||
|
||||
/// Returns the currently active ability.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_active_ability(
|
||||
ptr: ExternPointer<Arc<Pokemon>>,
|
||||
ptr: ExternPointer<Pokemon>,
|
||||
) -> NativeResult<IdentifiablePointer<Arc<dyn Ability>>> {
|
||||
match ptr.as_ref().active_ability() {
|
||||
Ok(v) => NativeResult::ok(v.clone().into()),
|
||||
@@ -292,13 +288,13 @@ extern "C" fn pokemon_active_ability(
|
||||
|
||||
/// Whether or not the Pokemon is allowed to gain experience.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_allowed_experience_gain(ptr: ExternPointer<Arc<Pokemon>>) -> u8 {
|
||||
extern "C" fn pokemon_allowed_experience_gain(ptr: ExternPointer<Pokemon>) -> u8 {
|
||||
u8::from(ptr.as_ref().allowed_experience_gain())
|
||||
}
|
||||
|
||||
/// The [nature](https://bulbapedia.bulbagarden.net/wiki/Nature) of the Pokemon.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_nature(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<Arc<dyn Nature>> {
|
||||
extern "C" fn pokemon_nature(ptr: ExternPointer<Pokemon>) -> IdentifiablePointer<Arc<dyn Nature>> {
|
||||
ptr.as_ref().nature().clone().into()
|
||||
}
|
||||
|
||||
@@ -306,20 +302,20 @@ extern "C" fn pokemon_nature(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePo
|
||||
/// stats, level, nature, IV, or EV changes. This has a side effect of recalculating the boosted
|
||||
/// stats, as those depend on the flat stats.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_recalculate_flat_stats(ptr: ExternPointer<Arc<Pokemon>>) -> NativeResult<()> {
|
||||
extern "C" fn pokemon_recalculate_flat_stats(ptr: ExternPointer<Pokemon>) -> NativeResult<()> {
|
||||
ptr.as_ref().recalculate_flat_stats().into()
|
||||
}
|
||||
|
||||
/// Calculates the boosted stats on the Pokemon. This should be called when a stat boost changes.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_recalculate_boosted_stats(ptr: ExternPointer<Arc<Pokemon>>) -> NativeResult<()> {
|
||||
extern "C" fn pokemon_recalculate_boosted_stats(ptr: ExternPointer<Pokemon>) -> NativeResult<()> {
|
||||
ptr.as_ref().recalculate_boosted_stats().into()
|
||||
}
|
||||
|
||||
/// Change the species of the Pokemon.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_change_species(
|
||||
ptr: ExternPointer<Arc<Pokemon>>,
|
||||
ptr: ExternPointer<Pokemon>,
|
||||
species: ExternPointer<Arc<dyn Species>>,
|
||||
form: ExternPointer<Arc<dyn Form>>,
|
||||
) -> NativeResult<()> {
|
||||
@@ -330,48 +326,45 @@ extern "C" fn pokemon_change_species(
|
||||
|
||||
/// Change the form of the Pokemon.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_change_form(
|
||||
ptr: ExternPointer<Arc<Pokemon>>,
|
||||
form: ExternPointer<Arc<dyn Form>>,
|
||||
) -> NativeResult<()> {
|
||||
extern "C" fn pokemon_change_form(ptr: ExternPointer<Pokemon>, form: ExternPointer<Arc<dyn Form>>) -> NativeResult<()> {
|
||||
ptr.as_ref().change_form(form.as_ref()).into()
|
||||
}
|
||||
|
||||
/// Whether or not the Pokemon is useable in a battle.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_is_usable(ptr: ExternPointer<Arc<Pokemon>>) -> u8 {
|
||||
extern "C" fn pokemon_is_usable(ptr: ExternPointer<Pokemon>) -> u8 {
|
||||
u8::from(ptr.as_ref().is_usable())
|
||||
}
|
||||
|
||||
/// Returns whether the Pokemon is fainted.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_is_fainted(ptr: ExternPointer<Arc<Pokemon>>) -> u8 {
|
||||
extern "C" fn pokemon_is_fainted(ptr: ExternPointer<Pokemon>) -> u8 {
|
||||
u8::from(ptr.as_ref().is_fainted())
|
||||
}
|
||||
|
||||
/// Whether or not the Pokemon is on the battlefield.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_is_on_battlefield(ptr: ExternPointer<Arc<Pokemon>>) -> u8 {
|
||||
extern "C" fn pokemon_is_on_battlefield(ptr: ExternPointer<Pokemon>) -> u8 {
|
||||
u8::from(ptr.as_ref().is_on_battlefield())
|
||||
}
|
||||
|
||||
/// Damages the Pokemon by a certain amount of damage, from a damage source.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_damage(ptr: ExternPointer<Arc<Pokemon>>, damage: u32, source: DamageSource) -> NativeResult<()> {
|
||||
extern "C" fn pokemon_damage(ptr: ExternPointer<Pokemon>, damage: u32, source: DamageSource) -> NativeResult<()> {
|
||||
ptr.as_ref().damage(damage, source).into()
|
||||
}
|
||||
|
||||
/// Heals the Pokemon by a specific amount. Unless allow_revive is set to true, this will not
|
||||
/// heal if the Pokemon has 0 health. If the amount healed is 0, this will return false.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_heal(ptr: ExternPointer<Arc<Pokemon>>, amount: u32, allow_revive: u8) -> bool {
|
||||
extern "C" fn pokemon_heal(ptr: ExternPointer<Pokemon>, amount: u32, allow_revive: u8) -> bool {
|
||||
ptr.as_ref().heal(amount, allow_revive == 1)
|
||||
}
|
||||
|
||||
/// Learn a move.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_learn_move(
|
||||
ptr: ExternPointer<Arc<Pokemon>>,
|
||||
ptr: ExternPointer<Pokemon>,
|
||||
move_name: *const c_char,
|
||||
learn_method: MoveLearnMethod,
|
||||
) -> NativeResult<()> {
|
||||
@@ -384,6 +377,6 @@ extern "C" fn pokemon_learn_move(
|
||||
|
||||
/// Removes the current non-volatile status from the Pokemon.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_clear_status(ptr: ExternPointer<Arc<Pokemon>>) {
|
||||
extern "C" fn pokemon_clear_status(ptr: ExternPointer<Pokemon>) {
|
||||
ptr.as_ref().clear_status()
|
||||
}
|
||||
|
||||
@@ -10,10 +10,7 @@ extern "C" fn pokemon_party_new(capacity: usize) -> IdentifiablePointer<Arc<Poke
|
||||
|
||||
/// Gets a Pokemon at an index in the party.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_party_at(
|
||||
ptr: ExternPointer<Arc<PokemonParty>>,
|
||||
index: usize,
|
||||
) -> IdentifiablePointer<Arc<Pokemon>> {
|
||||
extern "C" fn pokemon_party_at(ptr: ExternPointer<Arc<PokemonParty>>, index: usize) -> IdentifiablePointer<Pokemon> {
|
||||
if let Some(v) = ptr.as_ref().at(index) {
|
||||
v.into()
|
||||
} else {
|
||||
@@ -32,8 +29,8 @@ extern "C" fn pokemon_party_switch(ptr: ExternPointer<Arc<PokemonParty>>, a: usi
|
||||
extern "C" fn pokemon_party_swap_into(
|
||||
ptr: ExternPointer<Arc<PokemonParty>>,
|
||||
index: usize,
|
||||
pokemon: ExternPointer<Arc<Pokemon>>,
|
||||
) -> NativeResult<IdentifiablePointer<Arc<Pokemon>>> {
|
||||
pokemon: ExternPointer<Pokemon>,
|
||||
) -> NativeResult<IdentifiablePointer<Pokemon>> {
|
||||
let pokemon = if pokemon.ptr.is_null() {
|
||||
None
|
||||
} else {
|
||||
@@ -66,9 +63,6 @@ extern "C" fn pokemon_party_pack_party(ptr: ExternPointer<Arc<PokemonParty>>) ->
|
||||
|
||||
/// Checks if the party contains a given pokemon.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_party_has_pokemon(
|
||||
ptr: ExternPointer<Arc<PokemonParty>>,
|
||||
pokemon: ExternPointer<Arc<Pokemon>>,
|
||||
) -> u8 {
|
||||
extern "C" fn pokemon_party_has_pokemon(ptr: ExternPointer<Arc<PokemonParty>>, pokemon: ExternPointer<Pokemon>) -> u8 {
|
||||
u8::from(ptr.as_ref().has_pokemon(pokemon.as_ref()))
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ macro_rules! ffi_vec_stringkey_getters {
|
||||
};
|
||||
}
|
||||
|
||||
use crate::dynamic_data::{Battle, Pokemon};
|
||||
use crate::{ValueIdentifiable, ValueIdentifier};
|
||||
pub(self) use ffi_arc_dyn_getter;
|
||||
pub(self) use ffi_arc_getter;
|
||||
@@ -250,6 +251,40 @@ impl<T: ValueIdentifiable> From<*const T> for IdentifiablePointer<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Pokemon> for IdentifiablePointer<Pokemon> {
|
||||
fn from(v: Pokemon) -> Self {
|
||||
let id = v.value_identifier().value();
|
||||
Self {
|
||||
ptr: Box::into_raw(Box::new(v)),
|
||||
id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Option<Pokemon>> for IdentifiablePointer<Pokemon> {
|
||||
fn from(v: Option<Pokemon>) -> Self {
|
||||
if let Some(v) = v {
|
||||
let id = unsafe { transmute(v.value_identifier()) };
|
||||
Self {
|
||||
ptr: Box::into_raw(Box::new(v)),
|
||||
id,
|
||||
}
|
||||
} else {
|
||||
IdentifiablePointer::none()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Battle> for IdentifiablePointer<Battle> {
|
||||
fn from(v: Battle) -> Self {
|
||||
let id = v.value_identifier().value();
|
||||
Self {
|
||||
ptr: Box::into_raw(Box::new(v)),
|
||||
id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> IdentifiablePointer<T> {
|
||||
/// Returns an identifiable pointer with null as pointer, and 0 as identifier.
|
||||
pub fn none() -> Self {
|
||||
|
||||
@@ -11,13 +11,13 @@ use std::sync::Arc;
|
||||
unsafe extern "C" fn ability_new(
|
||||
name: *const c_char,
|
||||
effect: *const c_char,
|
||||
parameters: *const OwnedPtr<EffectParameter>,
|
||||
parameters: *const OwnedPtr<Arc<EffectParameter>>,
|
||||
parameters_length: usize,
|
||||
) -> NativeResult<IdentifiablePointer<Arc<dyn Ability>>> {
|
||||
let parameters = std::slice::from_raw_parts(parameters, parameters_length);
|
||||
let mut parameters_vec: Vec<EffectParameter> = Vec::with_capacity(parameters_length);
|
||||
let mut parameters_vec: Vec<Arc<EffectParameter>> = Vec::with_capacity(parameters_length);
|
||||
for parameter in parameters {
|
||||
parameters_vec.push(*Box::from_raw(*parameter));
|
||||
parameters_vec.push(parameter.read());
|
||||
}
|
||||
|
||||
let name: StringKey = match CStr::from_ptr(name).to_str() {
|
||||
@@ -68,9 +68,9 @@ unsafe extern "C" fn ability_parameter_length(ptr: ExternPointer<Arc<dyn Ability
|
||||
unsafe extern "C" fn ability_parameter_get(
|
||||
ptr: ExternPointer<Arc<dyn Ability>>,
|
||||
index: usize,
|
||||
) -> IdentifiablePointer<EffectParameter> {
|
||||
) -> IdentifiablePointer<Arc<EffectParameter>> {
|
||||
if let Some(p) = ptr.as_ref().parameters().get(index) {
|
||||
(p as *const EffectParameter).into()
|
||||
p.clone().into()
|
||||
} else {
|
||||
IdentifiablePointer::none()
|
||||
}
|
||||
|
||||
@@ -95,8 +95,8 @@ ffi_vec_value_getters!(Form, dyn Form, types, TypeIdentifier);
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn form_base_stats(
|
||||
ptr: ExternPointer<Arc<dyn Form>>,
|
||||
) -> IdentifiablePointer<StaticStatisticSet<u16>> {
|
||||
(ptr.as_ref().base_stats() as *const StaticStatisticSet<u16>).into()
|
||||
) -> IdentifiablePointer<Arc<StaticStatisticSet<u16>>> {
|
||||
ptr.as_ref().base_stats().clone().into()
|
||||
}
|
||||
|
||||
ffi_vec_stringkey_getters!(Form, abilities);
|
||||
|
||||
@@ -4,28 +4,29 @@ use crate::static_data::{
|
||||
StaticData, StaticDataImpl, TypeLibrary,
|
||||
};
|
||||
use std::ptr::drop_in_place;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Instantiates a new data collection.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn static_data_new(
|
||||
settings: OwnedPtr<Box<dyn LibrarySettings>>,
|
||||
species: OwnedPtr<Box<dyn SpeciesLibrary>>,
|
||||
moves: OwnedPtr<Box<dyn MoveLibrary>>,
|
||||
items: OwnedPtr<Box<dyn ItemLibrary>>,
|
||||
growth_rates: OwnedPtr<Box<dyn GrowthRateLibrary>>,
|
||||
types: OwnedPtr<Box<dyn TypeLibrary>>,
|
||||
natures: OwnedPtr<Box<dyn NatureLibrary>>,
|
||||
abilities: OwnedPtr<Box<dyn AbilityLibrary>>,
|
||||
) -> IdentifiablePointer<Box<dyn StaticData>> {
|
||||
let b: Box<dyn StaticData> = Box::new(StaticDataImpl::new(
|
||||
*Box::from_raw(settings),
|
||||
*Box::from_raw(species),
|
||||
*Box::from_raw(moves),
|
||||
*Box::from_raw(items),
|
||||
*Box::from_raw(growth_rates),
|
||||
*Box::from_raw(types),
|
||||
*Box::from_raw(natures),
|
||||
*Box::from_raw(abilities),
|
||||
settings: OwnedPtr<Arc<dyn LibrarySettings>>,
|
||||
species: OwnedPtr<Arc<dyn SpeciesLibrary>>,
|
||||
moves: OwnedPtr<Arc<dyn MoveLibrary>>,
|
||||
items: OwnedPtr<Arc<dyn ItemLibrary>>,
|
||||
growth_rates: OwnedPtr<Arc<dyn GrowthRateLibrary>>,
|
||||
types: OwnedPtr<Arc<dyn TypeLibrary>>,
|
||||
natures: OwnedPtr<Arc<dyn NatureLibrary>>,
|
||||
abilities: OwnedPtr<Arc<dyn AbilityLibrary>>,
|
||||
) -> IdentifiablePointer<Arc<dyn StaticData>> {
|
||||
let b: Arc<dyn StaticData> = Arc::new(StaticDataImpl::new(
|
||||
settings.read(),
|
||||
species.read(),
|
||||
moves.read(),
|
||||
items.read(),
|
||||
growth_rates.read(),
|
||||
types.read(),
|
||||
natures.read(),
|
||||
abilities.read(),
|
||||
));
|
||||
b.into()
|
||||
}
|
||||
@@ -39,63 +40,63 @@ unsafe extern "C" fn static_data_drop(ptr: OwnedPtr<Box<dyn StaticData>>) {
|
||||
/// Several misc settings for the library.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn static_data_settings(
|
||||
mut data: ExternPointer<Box<dyn StaticData>>,
|
||||
) -> IdentifiablePointer<Box<dyn LibrarySettings>> {
|
||||
data.as_mut().settings().into()
|
||||
mut data: ExternPointer<Arc<dyn StaticData>>,
|
||||
) -> IdentifiablePointer<Arc<dyn LibrarySettings>> {
|
||||
data.as_mut().settings().clone().into()
|
||||
}
|
||||
|
||||
/// All data for Pokemon species.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn static_data_species(
|
||||
mut data: ExternPointer<Box<dyn StaticData>>,
|
||||
) -> IdentifiablePointer<Box<dyn SpeciesLibrary>> {
|
||||
data.as_mut().species().into()
|
||||
mut data: ExternPointer<Arc<dyn StaticData>>,
|
||||
) -> IdentifiablePointer<Arc<dyn SpeciesLibrary>> {
|
||||
data.as_mut().species().clone().into()
|
||||
}
|
||||
|
||||
/// All data for the moves.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn static_data_moves(
|
||||
mut data: ExternPointer<Box<dyn StaticData>>,
|
||||
) -> IdentifiablePointer<Box<dyn MoveLibrary>> {
|
||||
data.as_mut().moves().into()
|
||||
mut data: ExternPointer<Arc<dyn StaticData>>,
|
||||
) -> IdentifiablePointer<Arc<dyn MoveLibrary>> {
|
||||
data.as_mut().moves().clone().into()
|
||||
}
|
||||
|
||||
/// All data for the items.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn static_data_items(
|
||||
mut data: ExternPointer<Box<dyn StaticData>>,
|
||||
) -> IdentifiablePointer<Box<dyn ItemLibrary>> {
|
||||
(data.as_mut().items()).into()
|
||||
mut data: ExternPointer<Arc<dyn StaticData>>,
|
||||
) -> IdentifiablePointer<Arc<dyn ItemLibrary>> {
|
||||
(data.as_mut().items()).clone().into()
|
||||
}
|
||||
|
||||
/// All data for growth rates.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn static_data_growth_rates(
|
||||
mut data: ExternPointer<Box<dyn StaticData>>,
|
||||
) -> IdentifiablePointer<Box<dyn GrowthRateLibrary>> {
|
||||
data.as_mut().growth_rates().into()
|
||||
mut data: ExternPointer<Arc<dyn StaticData>>,
|
||||
) -> IdentifiablePointer<Arc<dyn GrowthRateLibrary>> {
|
||||
data.as_mut().growth_rates().clone().into()
|
||||
}
|
||||
|
||||
/// All data related to types and type effectiveness.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn static_data_types(
|
||||
mut data: ExternPointer<Box<dyn StaticData>>,
|
||||
) -> IdentifiablePointer<Box<dyn TypeLibrary>> {
|
||||
data.as_mut().types().into()
|
||||
mut data: ExternPointer<Arc<dyn StaticData>>,
|
||||
) -> IdentifiablePointer<Arc<dyn TypeLibrary>> {
|
||||
data.as_mut().types().clone().into()
|
||||
}
|
||||
|
||||
/// All data related to natures.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn static_data_natures(
|
||||
data: ExternPointer<Box<dyn StaticData>>,
|
||||
) -> IdentifiablePointer<Box<dyn NatureLibrary>> {
|
||||
data.as_ref().natures().into()
|
||||
data: ExternPointer<Arc<dyn StaticData>>,
|
||||
) -> IdentifiablePointer<Arc<dyn NatureLibrary>> {
|
||||
data.as_ref().natures().clone().into()
|
||||
}
|
||||
|
||||
/// All data related to abilities.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn static_data_abilities(
|
||||
mut data: ExternPointer<Box<dyn StaticData>>,
|
||||
) -> IdentifiablePointer<Box<dyn AbilityLibrary>> {
|
||||
(data.as_mut().abilities()).into()
|
||||
mut data: ExternPointer<Arc<dyn StaticData>>,
|
||||
) -> IdentifiablePointer<Arc<dyn AbilityLibrary>> {
|
||||
(data.as_mut().abilities()).clone().into()
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ unsafe extern "C" fn move_data_has_flag(ptr: ExternPointer<Arc<dyn MoveData>>, f
|
||||
unsafe extern "C" fn secondary_effect_new(
|
||||
chance: f32,
|
||||
effect_name: BorrowedPtr<c_char>,
|
||||
parameters: *mut OwnedPtr<EffectParameter>,
|
||||
parameters: *mut OwnedPtr<Arc<EffectParameter>>,
|
||||
parameters_length: usize,
|
||||
) -> IdentifiablePointer<Box<dyn SecondaryEffect>> {
|
||||
let parameter_slice = std::slice::from_raw_parts(parameters, parameters_length);
|
||||
@@ -156,9 +156,9 @@ unsafe extern "C" fn secondary_effect_parameter_length(ptr: ExternPointer<Box<dy
|
||||
unsafe extern "C" fn secondary_effect_parameter_get(
|
||||
ptr: ExternPointer<Box<dyn SecondaryEffect>>,
|
||||
index: usize,
|
||||
) -> IdentifiablePointer<EffectParameter> {
|
||||
) -> IdentifiablePointer<Arc<EffectParameter>> {
|
||||
if let Some(v) = ptr.as_ref().parameters().get(index) {
|
||||
(v as *const EffectParameter).into()
|
||||
v.clone().into()
|
||||
} else {
|
||||
IdentifiablePointer::none()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user