fish_lib/game/services/
location_service.rs1use crate::config::ConfigInterface;
2use crate::data::location_data::LocationData;
3use std::collections::HashMap;
4use std::sync::Arc;
5
6pub trait LocationServiceInterface: Send + Sync {
7 fn get_location_names(&self) -> Arc<HashMap<i32, String>>;
8 fn get_location_data(&self, location_id: i32) -> Option<Arc<LocationData>>;
9}
10
11pub struct LocationService {
12 config: Arc<dyn ConfigInterface>,
13}
14
15impl LocationService {
16 pub fn new(config: Arc<dyn ConfigInterface>) -> LocationService {
17 LocationService { config }
18 }
19}
20
21impl LocationServiceInterface for LocationService {
22 fn get_location_names(&self) -> Arc<HashMap<i32, String>> {
23 self.config.location_names().clone()
24 }
25
26 fn get_location_data(&self, location_id: i32) -> Option<Arc<LocationData>> {
27 self.config.get_location_data(location_id)
28 }
29}