poke_data/models/
pokemon_form.rs1use crate::data::link_context::LinkContext;
2use crate::data::linkable::Linkable;
3use crate::models::localized_names::LocalizedStrings;
4use crate::models::pokeathlon_stats::PokeathlonStats;
5use crate::models::pokemon::PokemonId;
6use crate::models::version_group::{VersionGroup, VersionGroupId};
7use crate::types::pokemon_type::Type;
8use serde::{Deserialize, Serialize};
9use std::sync::Arc;
10
11pub type PokemonFormId = u16;
12
13#[derive(Debug)]
14pub struct PokemonForm {
15 pub id: PokemonFormId,
16 pub identifier: String,
17 pub form_identifier: Option<String>,
18 pub form_names: Option<LocalizedStrings>,
19 pub type_overrides: Option<Vec<Type>>,
20 pub pokeathlon_stats: Option<PokeathlonStats>,
21 pub pokemon_id: PokemonId,
22 pub introduced_in_version_group: Arc<VersionGroup>,
23 pub is_default: bool,
24 pub is_battle_only: bool,
25 pub is_mega: bool,
26 pub form_order: u8,
27 pub order: u16,
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
31pub struct UnlinkedPokemonForm {
32 pub id: PokemonFormId,
33 pub identifier: String,
34 pub form_identifier: Option<String>,
35 pub form_names: Option<LocalizedStrings>,
36 pub type_overrides: Option<Vec<Type>>,
37 pub pokeathlon_stats: Option<PokeathlonStats>,
38 pub pokemon_id: PokemonId,
39 pub introduced_in_version_group_id: VersionGroupId,
40 pub is_default: bool,
41 pub is_battle_only: bool,
42 pub is_mega: bool,
43 pub form_order: u8,
44 pub order: u16,
45}
46
47impl Linkable for UnlinkedPokemonForm {
48 type Linked = Arc<PokemonForm>;
49
50 fn link(&self, context: &LinkContext) -> Self::Linked {
51 let introduced_in_version_group = context
52 .version_groups
53 .get(&self.introduced_in_version_group_id)
54 .unwrap_or_else(|| {
55 panic!(
56 "No version group '{}' found for pokemon form '{}'",
57 self.introduced_in_version_group_id, self.id
58 )
59 })
60 .clone();
61
62 let form = PokemonForm {
63 id: self.id,
64 identifier: self.identifier.clone(),
65 form_identifier: self.form_identifier.clone(),
66 form_names: self.form_names.clone(),
67 type_overrides: self.type_overrides.clone(),
68 pokeathlon_stats: self.pokeathlon_stats.clone(),
69 pokemon_id: self.pokemon_id.clone(),
70 introduced_in_version_group,
71 is_default: self.is_default,
72 is_battle_only: self.is_battle_only,
73 is_mega: self.is_mega,
74 form_order: self.form_order,
75 order: self.order,
76 };
77
78 Arc::new(form)
79 }
80}