This commit is contained in:
@@ -260,8 +260,8 @@ extern "C" fn pokemon_is_ability_overriden(ptr: ExternPointer<Arc<Pokemon>>) ->
|
||||
|
||||
/// Returns the currently active ability.
|
||||
#[no_mangle]
|
||||
extern "C" fn pokemon_active_ability(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<Ability> {
|
||||
(ptr.as_ref().active_ability() as *const Ability).into()
|
||||
extern "C" fn pokemon_active_ability(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<Arc<dyn Ability>> {
|
||||
ptr.as_ref().active_ability().clone().into()
|
||||
}
|
||||
|
||||
/// Whether or not the Pokemon is allowed to gain experience.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::ffi::{ExternPointer, IdentifiablePointer, OwnedPtr};
|
||||
use crate::static_data::{Ability, EffectParameter};
|
||||
use crate::static_data::{Ability, AbilityImpl, EffectParameter};
|
||||
use crate::StringKey;
|
||||
use std::ffi::{c_char, CStr, CString};
|
||||
use std::ptr::drop_in_place;
|
||||
@@ -12,7 +12,7 @@ unsafe extern "C" fn ability_new(
|
||||
effect: *const c_char,
|
||||
parameters: *const OwnedPtr<EffectParameter>,
|
||||
parameters_length: usize,
|
||||
) -> IdentifiablePointer<Arc<Ability>> {
|
||||
) -> 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);
|
||||
for parameter in parameters {
|
||||
@@ -22,37 +22,38 @@ unsafe extern "C" fn ability_new(
|
||||
let name: StringKey = CStr::from_ptr(name).to_str().unwrap().into();
|
||||
let effect: StringKey = CStr::from_ptr(effect).to_str().unwrap().into();
|
||||
|
||||
Arc::new(Ability::new(&name, &effect, parameters_vec)).into()
|
||||
let arc: Arc<dyn Ability> = Arc::new(AbilityImpl::new(&name, &effect, parameters_vec));
|
||||
arc.into()
|
||||
}
|
||||
|
||||
/// Drops a reference counted ability.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn ability_drop(ptr: OwnedPtr<Arc<Ability>>) {
|
||||
unsafe extern "C" fn ability_drop(ptr: OwnedPtr<Arc<dyn 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> {
|
||||
unsafe extern "C" fn ability_name(ptr: ExternPointer<Arc<dyn 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> {
|
||||
unsafe extern "C" fn ability_effect(ptr: ExternPointer<Arc<dyn 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 {
|
||||
unsafe extern "C" fn ability_parameter_length(ptr: ExternPointer<Arc<dyn 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>>,
|
||||
ptr: ExternPointer<Arc<dyn Ability>>,
|
||||
index: usize,
|
||||
) -> IdentifiablePointer<EffectParameter> {
|
||||
if let Some(p) = ptr.as_ref().parameters().get(index) {
|
||||
|
||||
@@ -74,5 +74,5 @@ macro_rules! library_interface {
|
||||
|
||||
library_interface!(SpeciesLibrary, Species);
|
||||
library_interface!(MoveLibrary, MoveData);
|
||||
library_interface!(AbilityLibrary, Ability);
|
||||
library_interface!(AbilityLibrary, dyn Ability);
|
||||
library_interface!(ItemLibrary, dyn Item);
|
||||
|
||||
@@ -10,13 +10,14 @@ extern "C" fn nature_new(
|
||||
decrease_stat: Statistic,
|
||||
increase_modifier: f32,
|
||||
decrease_modifier: f32,
|
||||
) -> IdentifiablePointer<Arc<NatureImpl>> {
|
||||
NatureImpl::new(increase_stat, decrease_stat, increase_modifier, decrease_modifier).into()
|
||||
) -> IdentifiablePointer<Arc<dyn Nature>> {
|
||||
let arc: Arc<dyn Nature> = NatureImpl::new(increase_stat, decrease_stat, increase_modifier, decrease_modifier);
|
||||
arc.into()
|
||||
}
|
||||
|
||||
/// Reduce the reference count for a nature.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn nature_drop(ptr: OwnedPtr<Arc<NatureImpl>>) {
|
||||
unsafe extern "C" fn nature_drop(ptr: OwnedPtr<Arc<dyn Nature>>) {
|
||||
drop_in_place(ptr)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user