90 lines
1.8 KiB
Rust
90 lines
1.8 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
use crate::models::player::Player;
|
|
use crate::models::shop::ShopData;
|
|
|
|
pub mod player;
|
|
pub mod shop;
|
|
pub mod item;
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub enum LocationData {
|
|
Base,
|
|
Shop(ShopData),
|
|
Town,
|
|
Market,
|
|
Attraction,
|
|
PublicFarm,
|
|
}
|
|
|
|
#[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: u64,
|
|
name: String,
|
|
position: Position,
|
|
owners: Vec<Player>,
|
|
tunnel: Option<Tunnel>,
|
|
loc_data: LocationData,
|
|
}
|
|
|
|
|
|
|
|
impl Location {
|
|
fn new (id: u64, name: &str, position: Position, owners: Vec<Player>, tunnel: Option<Tunnel>, loc_data: LocationData) -> Self {
|
|
Location {
|
|
id,
|
|
name: name.to_string(),
|
|
position,
|
|
owners,
|
|
tunnel,
|
|
loc_data,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[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 {name: "CoolZero123".to_string(), user_ids: vec![UserID::DiscordUUID(0)]};
|
|
Location::new(0, "test", Position {x: 0, y: 0, dimension: Dimension::Overworld}, vec![player], None, LocationData::Base);
|
|
}
|
|
}
|
|
|