codename-routes/routes-native/src/stateserver/world/tiles.rs

122 lines
3.2 KiB
Rust
Raw Normal View History

2022-05-06 22:17:56 +00:00
use derive_builder::Builder;
2022-05-08 22:52:47 +00:00
use strum::{AsRefStr, EnumCount, EnumDiscriminants, EnumIter, FromRepr, IntoEnumIterator};
2022-05-04 14:46:58 +00:00
#[derive(AsRefStr, EnumIter, FromRepr, EnumDiscriminants, Clone, Copy, PartialEq, EnumCount)]
2022-05-08 12:06:42 +00:00
#[repr(u8)]
2022-05-03 22:06:50 +00:00
pub enum Tiletypes {
Air,
Water,
Grass,
Dirt,
Sand,
2022-05-08 22:52:47 +00:00
Rock,
2022-05-09 21:04:54 +00:00
WaterSlab,
GrassSlab,
2022-05-19 17:01:57 +00:00
SandPathTlBr,
SandPathTrBl,
SandPathCross,
SandPathCurveDD,
SandPathCurveUU,
SandPathCurveLL,
SandPathCurveRR,
SandPathTTlBr,
SandPathTrBlBr,
SandPathTrTlBl,
SandPathTlTrBr,
2022-05-03 22:06:50 +00:00
}
2022-05-06 22:17:56 +00:00
#[allow(dead_code)]
#[derive(Builder)]
2022-05-03 22:06:50 +00:00
pub struct Tile {
kind: Tiletypes,
2022-05-06 22:17:56 +00:00
#[builder(default = "true")]
2022-05-08 22:52:47 +00:00
pub is_support: bool,
2022-05-08 16:53:27 +00:00
#[builder(default = "true")]
pub hide_top_left: bool,
2022-05-08 16:53:27 +00:00
#[builder(default = "true")]
pub hide_top_right: bool,
2022-05-08 16:53:27 +00:00
#[builder(default = "true")]
pub hide_below: bool,
2022-05-08 22:52:47 +00:00
#[builder(default = "false")]
pub must_be_on_top: bool,
#[builder(default = "true")]
pub can_be_bedrock: bool,
2022-05-19 17:01:57 +00:00
#[builder(default = "false")]
pub is_grass: bool,
2022-05-03 22:06:50 +00:00
}
impl Tile {
2022-05-06 18:50:54 +00:00
pub fn new(kind: Tiletypes) -> Tile {
let tile: Tile;
match kind {
Tiletypes::Air => {
tile = TileBuilder::default()
.kind(kind)
.is_support(false)
.hide_below(false)
.hide_top_right(false)
.hide_top_left(false)
2022-05-08 22:52:47 +00:00
.can_be_bedrock(false)
.build()
.unwrap()
}
Tiletypes::Water => {
tile = TileBuilder::default()
.kind(kind)
.is_support(false)
.build()
.unwrap()
}
Tiletypes::Grass => {
tile = TileBuilder::default()
.kind(kind)
.must_be_on_top(true)
2022-05-19 17:01:57 +00:00
.is_grass(true)
.build()
.unwrap()
}
2022-05-09 21:04:54 +00:00
Tiletypes::GrassSlab => {
tile = TileBuilder::default()
.kind(kind)
.must_be_on_top(true)
.is_support(false)
2022-05-19 17:01:57 +00:00
.is_grass(true)
2022-05-09 21:04:54 +00:00
.build()
.unwrap()
}
Tiletypes::WaterSlab => {
tile = TileBuilder::default()
.kind(kind)
.is_support(false)
.build()
.unwrap()
}
_ => tile = TileBuilder::default().kind(kind).build().unwrap(),
};
tile
2022-05-03 22:06:50 +00:00
}
pub fn kind_to_string(&self) -> String {
self.kind.as_ref().to_string()
2022-05-04 14:46:58 +00:00
}
2022-05-03 22:06:50 +00:00
}
2022-05-08 22:52:47 +00:00
pub struct Attributelists {
pub bedrock: Vec<Tiletypes>,
2022-05-19 17:01:57 +00:00
pub grass: Vec<Tiletypes>,
2022-05-08 22:52:47 +00:00
}
impl Attributelists {
pub fn new() -> Attributelists{
let mut bedrock: Vec<Tiletypes> = vec![];
2022-05-19 17:01:57 +00:00
let mut grass: Vec<Tiletypes> = vec![];
2022-05-08 22:52:47 +00:00
for tiletype in Tiletypes::iter(){
let tile = Tile::new(tiletype);
2022-05-19 17:01:57 +00:00
if tile.can_be_bedrock { bedrock.push(tiletype);
if tile.is_grass {grass.push(tiletype);}
}
2022-05-08 22:52:47 +00:00
}
2022-05-19 17:01:57 +00:00
Attributelists { bedrock, grass }
2022-05-08 22:52:47 +00:00
}
}