diff --git a/src/ffi/dynamic_data/models/learned_move.rs b/src/ffi/dynamic_data/models/learned_move.rs new file mode 100644 index 0000000..ef0c7ce --- /dev/null +++ b/src/ffi/dynamic_data/models/learned_move.rs @@ -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>, + learn_method: MoveLearnMethod, +) -> IdentifiablePointer> { + 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>, +) -> IdentifiablePointer> { + 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>) -> 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>) -> 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>) -> 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>, 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>) { + 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>, amount: u8) { + learned_move.as_ref().restore_uses(amount); +} diff --git a/src/ffi/dynamic_data/models/mod.rs b/src/ffi/dynamic_data/models/mod.rs index c984a1c..b5a3c88 100644 --- a/src/ffi/dynamic_data/models/mod.rs +++ b/src/ffi/dynamic_data/models/mod.rs @@ -1,2 +1,4 @@ +/// The foreign function interface for a Learned Move. +mod learned_move; /// The foreign function interface for a Pokemon. mod pokemon;