use polariton::operation::Typed; pub trait ConfigProvider { fn cube_list(&self) -> Typed; fn movement_list(&self) -> Typed; fn weapon_list(&self) -> Typed; fn weapon_upgrade_list(&self) -> Typed; fn weapon_keys(&self) -> Typed; fn tech_tree_nodes(&self, unlocked_cubes: &std::collections::HashSet) -> Typed; fn ids(&self) -> Vec; fn regen_config(&self) -> Typed; fn after_battle_vote_config(&self) -> Typed; fn game_mode_config(&self) -> Typed; fn campaigns_parameters(&self) -> Typed; fn campaign_waves(&self) -> Typed; fn campaign_version(&self) -> Typed; fn campaign_details(&self) -> CompleteCampaignProvider; } pub struct CompleteCampaignProvider { map: std::collections::HashMap>, } impl CompleteCampaignProvider { pub fn new(map: std::collections::HashMap>) -> Self { Self { map } } pub fn get(&self, id: &str, difficulty: &i32) -> Result, i16> { if let Some(campaign) = self.map.get(id) { if let Some(details) = campaign.get(difficulty) { Ok(details.as_transmissible()) } else { log::warn!("Couldn't find difficulty {} in campaign `{}`", difficulty, id); Err(crate::data::error_codes::WebServicesError::DatabaseError as i16) } } else { log::warn!("Couldn't find campaign {} (ignoring difficulty {})", id, difficulty); Err(crate::data::error_codes::WebServicesError::DatabaseError as i16) } } }