poke_data/models/pokemon_move/
changelog.rs1use crate::data::link_context::LinkContext;
2use crate::data::linkable::Linkable;
3use crate::models::pokemon_move_effect::{PokemonMoveEffect, PokemonMoveEffectId};
4use crate::models::pokemon_move_target::{PokemonMoveTarget, PokemonMoveTargetId};
5use crate::types::pokemon_type::Type;
6use serde::{Deserialize, Serialize};
7use std::sync::Arc;
8
9#[derive(Debug)]
10pub struct PokemonMoveChangelog {
11 pub pokemon_type: Option<Type>,
12 pub power: Option<u8>,
13 pub pp: Option<u8>,
14 pub accuracy: Option<u8>,
15 pub priority: Option<i8>,
16 pub target: Option<Arc<PokemonMoveTarget>>,
17 pub effect: Option<Arc<PokemonMoveEffect>>,
18 pub effect_chance: Option<u8>,
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct UnlinkedPokemonMoveChangelog {
23 pub pokemon_type: Option<Type>,
24 pub power: Option<u8>,
25 pub pp: Option<u8>,
26 pub accuracy: Option<u8>,
27 pub priority: Option<i8>,
28 pub target_id: Option<PokemonMoveTargetId>,
29 pub effect_id: Option<PokemonMoveEffectId>,
30 pub effect_chance: Option<u8>,
31}
32
33impl Linkable for UnlinkedPokemonMoveChangelog {
34 type Linked = PokemonMoveChangelog;
35
36 fn link(&self, context: &LinkContext) -> Self::Linked {
37 let target = self.target_id.map(|target_id| {
38 context
39 .move_targets
40 .get(&target_id)
41 .unwrap_or_else(|| {
42 panic!(
43 "No move target '{}' found for move changelog entry",
44 target_id
45 )
46 })
47 .clone()
48 });
49
50 let effect = self.effect_id.map(|effect_id| {
51 context
52 .move_effects
53 .get(&effect_id)
54 .unwrap_or_else(|| {
55 panic!(
56 "No move effect '{}' found for move changelog entry",
57 effect_id
58 )
59 })
60 .clone()
61 });
62
63 PokemonMoveChangelog {
64 pokemon_type: self.pokemon_type,
65 power: self.power,
66 pp: self.pp,
67 accuracy: self.accuracy,
68 priority: self.priority,
69 target,
70 effect,
71 effect_chance: self.effect_chance,
72 }
73 }
74}