Make LearnableMoves a trait
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-11-28 20:20:46 +01:00
parent d4b1cadad0
commit c1e09c654b
6 changed files with 48 additions and 29 deletions

View File

@@ -23,7 +23,7 @@ unsafe extern "C" fn form_new(
abilities_length: usize,
hidden_abilities: *const BorrowedPtr<c_char>,
hidden_abilities_length: usize,
moves: OwnedPtr<LearnableMoves>,
moves: OwnedPtr<Box<dyn LearnableMoves>>,
flags: *const *const c_char,
flags_length: usize,
) -> IdentifiablePointer<Arc<Form>> {
@@ -89,7 +89,11 @@ unsafe extern "C" fn form_base_stats(ptr: ExternPointer<Arc<Form>>) -> Identifia
ffi_vec_stringkey_getters!(Form, abilities);
ffi_vec_stringkey_getters!(Form, hidden_abilities);
ffi_arc_getter!(Form, moves, BorrowedPtr<LearnableMoves>);
/// The moves a Pokemon with this form can learn.
#[no_mangle]
extern "C" fn form_moves(ptr: ExternPointer<Arc<Form>>) -> BorrowedPtr<Box<dyn LearnableMoves>> {
ptr.as_ref().moves() as *const Box<dyn LearnableMoves>
}
/// Check if the form has a specific flag set.
#[no_mangle]

View File

@@ -1,25 +1,25 @@
use crate::defines::LevelInt;
use crate::ffi::{BorrowedPtr, ExternPointer, OwnedPtr};
use crate::static_data::LearnableMoves;
use crate::static_data::{LearnableMoves, LearnableMovesImpl};
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()))
extern "C" fn learnable_moves_new() -> OwnedPtr<Box<dyn LearnableMoves>> {
Box::into_raw(Box::new(Box::new(LearnableMovesImpl::new())))
}
/// drops a learnablemoves struct.
#[no_mangle]
unsafe extern "C" fn learnable_moves_drop(ptr: OwnedPtr<LearnableMoves>) {
unsafe extern "C" fn learnable_moves_drop(ptr: OwnedPtr<Box<dyn 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(
mut ptr: ExternPointer<LearnableMoves>,
mut ptr: ExternPointer<Box<dyn LearnableMoves>>,
level: LevelInt,
move_name: BorrowedPtr<c_char>,
) {