use anyhow::Result;
use battler_data::SerializedRuleSet;
use serde::{
Deserialize,
Serialize,
};
use crate::{
battle::BattleType,
config::RuleSet,
dex::Dex,
};
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct FormatData {
pub battle_type: BattleType,
pub rules: SerializedRuleSet,
}
#[derive(Clone)]
pub struct Format {
pub battle_type: BattleType,
pub rules: RuleSet,
}
impl Format {
pub fn new(data: FormatData, dex: &Dex) -> Result<Self> {
let rules = RuleSet::new(data.rules, &data.battle_type, dex)?;
Ok(Self {
battle_type: data.battle_type,
rules,
})
}
pub fn data(&self) -> FormatData {
FormatData {
battle_type: self.battle_type.clone(),
rules: self.rules.serialized(),
}
}
}