voxel-zone/common/src/space/level_tile.rs

78 lines
2.1 KiB
Rust

#[cfg(not(feature = "std"))]
use core::default::Default;
#[cfg(feature = "serde")]
use serde::{Serialize, Deserialize};
#[derive(Copy, Clone, Debug, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum LevelTile {
#[default]
None,
Solid(Climbable),
SemisolidPlatform,
Door(DoorInfo),
EntitySpawn(EntityInfo),
}
#[derive(Copy, Clone, Default, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Climbable {
pub front: bool,
pub left: bool,
pub right: bool,
} // TODO: modular_bitfield?
#[derive(Copy, Clone, Default, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct DoorInfo {
id: u8,
}
#[derive(Copy, Clone, Default, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct EntityInfo {
id: u8,
}
#[cfg(feature = "block-mesh")]
pub mod block_mesh_impl {
use block_mesh::{Voxel, VoxelVisibility};
use super::LevelTile;
impl Voxel for LevelTile {
fn get_visibility(&self) -> VoxelVisibility {
get_visibility(self)
}
}
fn get_visibility(v: &LevelTile) -> VoxelVisibility {
match v {
LevelTile::None => VoxelVisibility::Empty,
LevelTile::Solid(_) => VoxelVisibility::Opaque,
LevelTile::SemisolidPlatform => VoxelVisibility::Translucent,
LevelTile::Door(_) => VoxelVisibility::Translucent,
LevelTile::EntitySpawn(_) => VoxelVisibility::Translucent,
}
}
}
pub const NULL_TILE: LevelTile = LevelTile::None;
const DEFAULT_NONE: LevelTile = LevelTile::None;
const DEFAULT_SOLID: LevelTile = LevelTile::Solid(Climbable {
front: false,
left: false,
right: false,
});
#[cfg(feature = "three_dimensional")]
impl super::three_dimensional::traits::DefaultVoxel for LevelTile {
fn get_default(kind: super::three_dimensional::traits::DefaultVoxelKinds) -> Self {
match kind {
super::three_dimensional::traits::DefaultVoxelKinds::None => DEFAULT_NONE,
super::three_dimensional::traits::DefaultVoxelKinds::Solid => DEFAULT_SOLID,
}
}
}