terra-wld 0.3.0

Terraria world parser
Documentation
use std::num::NonZeroU8;

use terra_types::{InPixels, Vec2};

pub use crate::tile::{tile_type::TileType, wall_type::WallType};
pub use terra_types::{Paint, TileShape};

mod tile_type;
mod wall_type;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct Tile {
	pub tile: Option<TileForeground>,
	pub wall: Option<Wall>,
	pub liquid: Option<Liquid>,
	pub is_red_wire: bool,
	pub is_blue_wire: bool,
	pub is_yellow_wire: bool,
	pub is_green_wire: bool,
	pub is_actuator: bool,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct TileForeground {
	pub tile: TileType,
	pub shape: TileShape,
	pub paint: Option<Paint>,
	pub is_invisible: bool,
	pub is_full_bright: bool,
	pub is_actuated: bool,
	pub texture_coords: Option<Vec2<InPixels, i16>>,
}

impl TileForeground {
	pub fn new(tile: TileType) -> Self {
		Self {
			tile,
			shape: TileShape::Full,
			paint: None,
			is_invisible: false,
			is_full_bright: false,
			is_actuated: false,
			texture_coords: None,
		}
	}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Wall {
	pub wall: WallType,
	pub paint: Option<Paint>,
	pub is_invisible: bool,
	pub is_full_bright: bool,
}

impl Wall {
	pub fn new(wall: WallType) -> Self {
		Self {
			wall,
			paint: None,
			is_invisible: false,
			is_full_bright: false,
		}
	}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Liquid {
	pub liquid: LiquidType,
	pub level: NonZeroU8,
}

impl Liquid {
	pub fn new(liquid: LiquidType) -> Self {
		Self {
			liquid,
			level: NonZeroU8::new(255).expect("Valid number"),
		}
	}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum LiquidType {
	Water,
	Lava,
	Honey,
	Shimmer,
}