FFI for Learned Move

This commit is contained in:
Deukhoofd 2022-10-15 10:25:40 +02:00
parent 691bf7c12e
commit c7b5bb7d12
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,58 @@
use crate::dynamic_data::{LearnedMove, MoveLearnMethod};
use crate::ffi::{ExternPointer, IdentifiablePointer};
use crate::static_data::MoveData;
use std::sync::Arc;
/// Instantiate a new learned move.
#[no_mangle]
extern "C" fn learned_move_new(
move_data: ExternPointer<Arc<MoveData>>,
learn_method: MoveLearnMethod,
) -> IdentifiablePointer<Arc<LearnedMove>> {
Arc::new(LearnedMove::new(move_data.as_ref(), learn_method)).into()
}
/// The immutable move information of the move.
#[no_mangle]
extern "C" fn learned_move_move_data(
learned_move: ExternPointer<Arc<LearnedMove>>,
) -> IdentifiablePointer<Arc<MoveData>> {
learned_move.as_ref().move_data().clone().into()
}
/// The maximal power points for this move.
#[no_mangle]
extern "C" fn learned_move_max_pp(learned_move: ExternPointer<Arc<LearnedMove>>) -> u8 {
learned_move.as_ref().max_pp()
}
/// The amount of remaining power points. If this is 0, we can not use the move anymore.
#[no_mangle]
extern "C" fn learned_move_remaining_pp(learned_move: ExternPointer<Arc<LearnedMove>>) -> u8 {
learned_move.as_ref().remaining_pp()
}
/// The way the move was learned.
#[no_mangle]
extern "C" fn learned_move_learn_method(learned_move: ExternPointer<Arc<LearnedMove>>) -> MoveLearnMethod {
learned_move.as_ref().learn_method()
}
/// Try and reduce the PP by a certain amount. If the amount is higher than the current uses,
/// return false. Otherwise, reduce the PP, and return true.
#[no_mangle]
extern "C" fn learned_move_try_use(learned_move: ExternPointer<Arc<LearnedMove>>, amount: u8) -> u8 {
u8::from(learned_move.as_ref().try_use(amount))
}
/// Set the remaining PP to the max amount of PP.
#[no_mangle]
extern "C" fn learned_move_restore_all_uses(learned_move: ExternPointer<Arc<LearnedMove>>) {
learned_move.as_ref().restore_all_uses();
}
/// 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) {
learned_move.as_ref().restore_uses(amount);
}

View File

@ -1,2 +1,4 @@
/// The foreign function interface for a Learned Move.
mod learned_move;
/// The foreign function interface for a Pokemon.
mod pokemon;