This commit is contained in:
@@ -7,7 +7,7 @@ use std::sync::Arc;
|
||||
/// Instantiate a new learned move.
|
||||
#[no_mangle]
|
||||
extern "C" fn learned_move_new(
|
||||
move_data: ExternPointer<Arc<MoveData>>,
|
||||
move_data: ExternPointer<Arc<dyn MoveData>>,
|
||||
learn_method: MoveLearnMethod,
|
||||
) -> IdentifiablePointer<Arc<LearnedMove>> {
|
||||
Arc::new(LearnedMove::new(move_data.as_ref(), learn_method)).into()
|
||||
@@ -23,7 +23,7 @@ extern "C" fn learned_move_drop(learned_move: OwnedPtr<Arc<LearnedMove>>) {
|
||||
#[no_mangle]
|
||||
extern "C" fn learned_move_move_data(
|
||||
learned_move: ExternPointer<Arc<LearnedMove>>,
|
||||
) -> IdentifiablePointer<Arc<MoveData>> {
|
||||
) -> IdentifiablePointer<Arc<dyn MoveData>> {
|
||||
learned_move.as_ref().move_data().clone().into()
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,6 @@ macro_rules! library_interface {
|
||||
}
|
||||
|
||||
library_interface!(SpeciesLibrary, Species);
|
||||
library_interface!(MoveLibrary, MoveData);
|
||||
library_interface!(MoveLibrary, dyn MoveData);
|
||||
library_interface!(AbilityLibrary, dyn Ability);
|
||||
library_interface!(ItemLibrary, dyn Item);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::ffi::{ffi_arc_getter, BorrowedPtr, ExternPointer, IdentifiablePointer, OwnedPtr};
|
||||
use crate::static_data::{
|
||||
EffectParameter, MoveCategory, MoveData, MoveTarget, SecondaryEffect, SecondaryEffectImpl, TypeIdentifier,
|
||||
EffectParameter, MoveCategory, MoveData, MoveDataImpl, MoveTarget, SecondaryEffect, SecondaryEffectImpl,
|
||||
TypeIdentifier,
|
||||
};
|
||||
use crate::StringKey;
|
||||
use hashbrown::HashSet;
|
||||
@@ -22,7 +23,7 @@ unsafe extern "C" fn move_data_new(
|
||||
secondary_effect: *mut Box<dyn SecondaryEffect>,
|
||||
flags: *const *const c_char,
|
||||
flags_length: usize,
|
||||
) -> IdentifiablePointer<Arc<MoveData>> {
|
||||
) -> IdentifiablePointer<Arc<dyn MoveData>> {
|
||||
let flags = std::slice::from_raw_parts(flags, flags_length);
|
||||
let name: StringKey = CStr::from_ptr(name).to_str().unwrap().into();
|
||||
let mut flags_set: HashSet<StringKey> = HashSet::with_capacity(flags_length);
|
||||
@@ -34,7 +35,7 @@ unsafe extern "C" fn move_data_new(
|
||||
} else {
|
||||
Some(*Box::from_raw(secondary_effect))
|
||||
};
|
||||
Arc::new(MoveData::new(
|
||||
let a: Arc<dyn MoveData> = Arc::new(MoveDataImpl::new(
|
||||
&name,
|
||||
move_type,
|
||||
category,
|
||||
@@ -45,42 +46,42 @@ unsafe extern "C" fn move_data_new(
|
||||
priority,
|
||||
secondary_effect,
|
||||
flags_set,
|
||||
))
|
||||
.into()
|
||||
));
|
||||
a.into()
|
||||
}
|
||||
|
||||
/// Drops a reference counted move.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn move_data_drop(ptr: OwnedPtr<Arc<MoveData>>) {
|
||||
unsafe extern "C" fn move_data_drop(ptr: OwnedPtr<Arc<dyn 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> {
|
||||
unsafe extern "C" fn move_data_name(ptr: ExternPointer<Arc<dyn MoveData>>) -> OwnedPtr<c_char> {
|
||||
let name = ptr.as_ref().name();
|
||||
CString::new(name.str()).unwrap().into_raw()
|
||||
}
|
||||
|
||||
ffi_arc_getter!(MoveData, move_type, TypeIdentifier);
|
||||
ffi_arc_getter!(MoveData, category, MoveCategory);
|
||||
ffi_arc_getter!(MoveData, base_power, u8);
|
||||
ffi_arc_getter!(MoveData, accuracy, u8);
|
||||
ffi_arc_getter!(MoveData, base_usages, u8);
|
||||
ffi_arc_getter!(MoveData, target, MoveTarget);
|
||||
ffi_arc_getter!(MoveData, priority, i8);
|
||||
ffi_arc_getter!(dyn MoveData, move_type, TypeIdentifier);
|
||||
ffi_arc_getter!(dyn MoveData, category, MoveCategory);
|
||||
ffi_arc_getter!(dyn MoveData, base_power, u8);
|
||||
ffi_arc_getter!(dyn MoveData, accuracy, u8);
|
||||
ffi_arc_getter!(dyn MoveData, base_usages, u8);
|
||||
ffi_arc_getter!(dyn MoveData, target, MoveTarget);
|
||||
ffi_arc_getter!(dyn MoveData, priority, i8);
|
||||
|
||||
/// The optional secondary effect the move has.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn move_data_secondary_effect(
|
||||
ptr: ExternPointer<Arc<MoveData>>,
|
||||
ptr: ExternPointer<Arc<dyn MoveData>>,
|
||||
) -> IdentifiablePointer<Box<dyn SecondaryEffect>> {
|
||||
ptr.as_ref().secondary_effect().into()
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
unsafe extern "C" fn move_data_has_flag(ptr: ExternPointer<Arc<dyn MoveData>>, flag: *const c_char) -> u8 {
|
||||
let flag = CStr::from_ptr(flag).into();
|
||||
u8::from(ptr.as_ref().has_flag(&flag))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user