Geoffrey-rs/geoffrey_models/src/models/locations/mod.rs

74 lines
1.4 KiB
Rust
Raw Normal View History

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<u64>,
pub name: String,
pub position: Position,
owners: HashSet<u64>,
pub tunnel: Option<Tunnel>,
loc_type: LocationType
}
impl Location {
pub fn new (name: &str, position: Position, owner: u64, tunnel: Option<Tunnel>, 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<u64> {
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<u64> {
self.id
}
fn set_id(&mut self, id: u64) {
self.id = Some(id)
}
fn tree() -> String {
"location".to_string()
}
}