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

104 lines
2.3 KiB
Rust

use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter};
use std::str::FromStr;
pub mod item;
pub mod locations;
pub mod meta;
pub mod parameters;
pub mod player;
pub mod response;
pub mod token;
#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
pub enum Dimension {
Overworld,
Nether,
TheEnd,
}
impl Default for Dimension {
fn default() -> Self {
Self::Overworld
}
}
impl Display for Dimension {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let display_name = match self {
Dimension::Overworld => "Overworld",
Dimension::Nether => "Nether",
Dimension::TheEnd => "The End",
};
write!(f, "{}", display_name)
}
}
impl FromStr for Dimension {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let s = s.to_lowercase();
Ok(match s.as_str() {
"o" | "overworld" => Dimension::Overworld,
"n" | "nether" => Dimension::Nether,
"e" | "end" | "the end" => Dimension::TheEnd,
_ => return Err(format!("Unable to parse {} as dimension", s)),
})
}
}
#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
pub enum Direction {
North,
East,
South,
West,
}
impl Display for Direction {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let display_name = match self {
Direction::North => "North",
Direction::East => "East",
Direction::South => "South",
Direction::West => "West",
};
write!(f, "{}", display_name)
}
}
#[derive(Default, Serialize, Deserialize, Debug, Copy, Clone)]
pub struct Position {
pub x: i32,
pub y: i32,
pub dimension: Dimension,
}
impl Position {
pub fn new(x: i32, y: i32, dimension: Dimension) -> Self {
Self { x, y, dimension }
}
}
impl Display for Position {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{} @ (x={}, z={}) ", self.dimension, self.x, self.y)
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Tunnel {
direction: Direction,
number: i32,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Ord, PartialOrd, Eq, Hash)]
pub enum CommandLevel {
ALL = 0,
REGISTERED = 1,
MOD = 2,
ADMIN = 3,
}