diff --git a/src/ship/drops/tool_table.rs b/src/ship/drops/tool_table.rs index b0147c4..585fd20 100644 --- a/src/ship/drops/tool_table.rs +++ b/src/ship/drops/tool_table.rs @@ -13,7 +13,7 @@ use crate::ship::drops::load_data_file; use crate::ship::drops::tech_table::TechniqueTable; -#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Copy, Clone)] +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Copy, Clone, enum_utils::FromStr)] enum ToolRateType { Monomate, Dimate, @@ -50,6 +50,19 @@ struct ToolRate { }*/ #[derive(Debug, Serialize, Deserialize)] +struct ToolRatesRaw { + area1: BTreeMap, + area2: BTreeMap, + area3: BTreeMap, + area4: BTreeMap, + area5: BTreeMap, + area6: BTreeMap, + area7: BTreeMap, + area8: BTreeMap, + area9: BTreeMap, + area10: BTreeMap, +} + struct ToolRates { area1: BTreeMap, area2: BTreeMap, @@ -63,6 +76,23 @@ struct ToolRates { area10: BTreeMap, } +impl ToolRates { + fn new(raw: ToolRatesRaw) -> ToolRates { + ToolRates { + area1: raw.area1.into_iter().map(|(name, rate)| (name.parse().unwrap(), rate)).collect(), + area2: raw.area2.into_iter().map(|(name, rate)| (name.parse().unwrap(), rate)).collect(), + area3: raw.area3.into_iter().map(|(name, rate)| (name.parse().unwrap(), rate)).collect(), + area4: raw.area4.into_iter().map(|(name, rate)| (name.parse().unwrap(), rate)).collect(), + area5: raw.area5.into_iter().map(|(name, rate)| (name.parse().unwrap(), rate)).collect(), + area6: raw.area6.into_iter().map(|(name, rate)| (name.parse().unwrap(), rate)).collect(), + area7: raw.area7.into_iter().map(|(name, rate)| (name.parse().unwrap(), rate)).collect(), + area8: raw.area8.into_iter().map(|(name, rate)| (name.parse().unwrap(), rate)).collect(), + area9: raw.area9.into_iter().map(|(name, rate)| (name.parse().unwrap(), rate)).collect(), + area10: raw.area10.into_iter().map(|(name, rate)| (name.parse().unwrap(), rate)).collect(), + } + } +} + impl ToolRates { fn get_by_area<'a>(&'a self, map_area: &MapVariantType) -> &'a BTreeMap { match map_area.area_value().unwrap() { @@ -87,8 +117,10 @@ pub struct ToolTable { impl ToolTable { pub fn new(episode: Episode, difficulty: Difficulty, section_id: SectionID) -> ToolTable { + let rates = load_data_file(episode, difficulty, section_id, "tool_rate.toml"); + ToolTable { - rates: load_data_file(episode, difficulty, section_id, "tool_rate.toml"), + rates: ToolRates::new(rates), tech_table: TechniqueTable::new(episode, difficulty, section_id), } }