firecore_battle/
data.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Default, Debug, Clone, Copy, Serialize, Deserialize)]
4pub struct BattleData {
5    pub type_: BattleType,
6    #[serde(default)]
7    pub settings: BattleSettings,
8}
9
10#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
11pub enum BattleType {
12    Wild,
13    Trainer,
14    GymLeader,
15}
16
17impl BattleType {
18    pub fn is_wild(&self) -> bool {
19        matches!(self, BattleType::Wild)
20    }
21
22    pub fn is_trainer(&self) -> bool {
23        !self.is_wild()
24    }
25}
26
27impl Default for BattleType {
28    fn default() -> Self {
29        Self::Wild
30    }
31}
32
33#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
34pub struct BattleSettings {
35    #[serde(default = "const_true")]
36    pub allow_forfeit: bool,
37}
38
39impl Default for BattleSettings {
40    fn default() -> Self {
41        Self {
42            allow_forfeit: true,
43        }
44    }
45}
46
47const fn const_true() -> bool {
48    true
49}