use serde::{Serialize, Deserialize}; use std::collections::HashSet; use crate::GeoffreyDatabaseModel; use crate::models::{Position, Tunnel}; pub mod farm; pub mod market; pub mod shop; pub mod town; #[derive(Serialize, Deserialize, Debug, Clone)] pub enum LocationType { Base, Shop(u64), Attraction, Town(u64), Farm(u64), Market(u64), } #[derive(Serialize, Deserialize, Debug, Clone)] pub struct Location { id: Option, pub name: String, pub position: Position, owners: HashSet, pub tunnel: Option, loc_type: LocationType } impl Location { pub fn new (name: &str, position: Position, owner: u64, tunnel: Option, loc_type: LocationType) -> Self { let mut owners = HashSet::new(); owners.insert(owner); Self { id: None, name: name.to_string(), position, owners, tunnel, loc_type } } fn owners(&self) -> Vec { self.owners.iter().cloned().collect() } fn add_owner(&mut self, owner: u64) { self.owners.insert(owner); } fn remove_owner(&mut self, owner: u64) { self.owners.remove(&owner); } } impl GeoffreyDatabaseModel for Location { fn id(&self) -> Option { self.id } fn set_id(&mut self, id: u64) { self.id = Some(id) } fn tree() -> String { "location".to_string() } }