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

This commit is contained in:
2022-11-27 22:29:11 +01:00
parent 27164616e9
commit ad9f17ccf1
12 changed files with 118 additions and 81 deletions

View File

@@ -11,7 +11,7 @@ pub struct LearnedMove {
/// A unique identifier so we know what value this is.
identifier: ValueIdentifier,
/// The immutable move information of the move.
move_data: Arc<MoveData>,
move_data: Arc<dyn MoveData>,
/// The maximal power points for this move.
max_pp: u8,
/// The amount of remaining power points. If this is 0, we can not use the move anymore.
@@ -33,7 +33,7 @@ pub enum MoveLearnMethod {
impl LearnedMove {
/// Instantiate a new learned move.
pub fn new(move_data: &Arc<MoveData>, learn_method: MoveLearnMethod) -> Self {
pub fn new(move_data: &Arc<dyn MoveData>, learn_method: MoveLearnMethod) -> Self {
Self {
identifier: Default::default(),
move_data: move_data.clone(),
@@ -44,7 +44,7 @@ impl LearnedMove {
}
/// The immutable move information of the move.
pub fn move_data(&self) -> &Arc<MoveData> {
pub fn move_data(&self) -> &Arc<dyn MoveData> {
&self.move_data
}
/// The maximal power points for this move.
@@ -100,11 +100,11 @@ impl ValueIdentifiable for LearnedMove {
#[cfg(test)]
mod tests {
use super::*;
use crate::static_data::{MoveCategory, MoveTarget};
use crate::static_data::{MoveCategory, MoveDataImpl, MoveTarget};
#[test]
fn create_learned_move_restore_uses() {
let data = Arc::new(MoveData::new(
let data: Arc<dyn MoveData> = Arc::new(MoveDataImpl::new(
&"foo".into(),
0u8.into(),
MoveCategory::Special,