fish_lib/game/services/
species_service.rs1use crate::config::ConfigInterface;
2use crate::data::species_data::SpeciesData;
3use std::collections::HashMap;
4use std::sync::Arc;
5
6pub trait SpeciesServiceInterface: Send + Sync {
7 fn get_species_names(&self) -> Arc<HashMap<i32, String>>;
8 fn get_species_data(&self, species_id: i32) -> Option<Arc<SpeciesData>>;
9}
10
11pub struct SpeciesService {
12 config: Arc<dyn ConfigInterface>,
13}
14
15impl SpeciesService {
16 pub fn new(config: Arc<dyn ConfigInterface>) -> SpeciesService {
17 SpeciesService { config }
18 }
19}
20
21impl SpeciesServiceInterface for SpeciesService {
22 fn get_species_names(&self) -> Arc<HashMap<i32, String>> {
23 self.config.species_names().clone()
24 }
25
26 fn get_species_data(&self, species_id: i32) -> Option<Arc<SpeciesData>> {
27 self.config.get_species_data(species_id)
28 }
29}