112 lines
2.3 KiB
Rust
112 lines
2.3 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
use crate::models::player::Player;
|
|
use crate::models::shop::ShopData;
|
|
use crate::models::town::TownData;
|
|
use crate::models::market::MarketData;
|
|
use crate::models::farm::FarmData;
|
|
use crate::GeoffreyDatabaseModel;
|
|
|
|
pub mod player;
|
|
pub mod shop;
|
|
pub mod item;
|
|
pub mod town;
|
|
pub mod farm;
|
|
pub mod market;
|
|
pub mod token;
|
|
mod meta;
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub enum LocationData {
|
|
Base,
|
|
Shop(ShopData),
|
|
Town(TownData),
|
|
Market(MarketData),
|
|
Attraction,
|
|
PublicFarm(FarmData),
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
|
|
pub enum Dimension {
|
|
Overworld,
|
|
Nether,
|
|
TheEnd
|
|
}
|
|
|
|
impl Default for Dimension {
|
|
fn default() -> Self {
|
|
Self::Overworld
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
|
|
pub enum Direction {
|
|
North,
|
|
East,
|
|
South,
|
|
West,
|
|
}
|
|
|
|
#[derive(Default, Serialize, Deserialize, Debug, Copy, Clone)]
|
|
pub struct Position {
|
|
pub x: i64,
|
|
pub y: i64,
|
|
dimension: Dimension,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct Tunnel {
|
|
direction: Direction,
|
|
number: i64
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct Location {
|
|
id: Option<u64>,
|
|
name: String,
|
|
position: Position,
|
|
owners: Vec<Player>,
|
|
tunnel: Option<Tunnel>,
|
|
loc_data: LocationData,
|
|
}
|
|
|
|
|
|
impl Location {
|
|
pub fn new (name: &str, position: Position, owners: Vec<Player>, tunnel: Option<Tunnel>, loc_data: LocationData) -> Self {
|
|
Location {
|
|
id: None,
|
|
name: name.to_string(),
|
|
position,
|
|
owners,
|
|
tunnel,
|
|
loc_data,
|
|
}
|
|
}
|
|
}
|
|
|
|
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()
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use crate::models::{Location, Position, Dimension, LocationData};
|
|
use crate::models::player::{Player, UserID};
|
|
|
|
#[test]
|
|
fn test_new_base() {
|
|
let player = Player::new("CoolZero123", UserID::DiscordUUID(0));
|
|
Location::new("test", Position {x: 0, y: 0, dimension: Dimension::Overworld}, vec![player], None, LocationData::Base);
|
|
}
|
|
}
|
|
|