mindustry logic execution, map- and schematic- parsing and rendering
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use std::any::Any;

use crate::block::{BlockLogic, DataConvertError, DeserializeError, make_register, SerializeError};
use crate::block::simple::{SimpleBlock, state_impl};
use crate::data::GridPos;
use crate::data::dynamic::{DynData, DynType};

make_register!
(
	COPPER_WALL: "copper-wall" => SimpleBlock::new(1, true);
	COPPER_WALL_LARGE: "copper-wall-large" => SimpleBlock::new(2, true);
	TITANIUM_WALL: "titanium-wall" => SimpleBlock::new(1, true);
	TITANIUM_WALL_LARGE: "titanium-wall-large" => SimpleBlock::new(2, true);
	PLASTANIUM_WALL: "plastanium-wall" => SimpleBlock::new(1, true);
	PLASTANIUM_WALL_LARGE: "plastanium-wall-large" => SimpleBlock::new(2, true);
	THORIUM_WALL: "thorium-wall" => SimpleBlock::new(1, true);
	THORIUM_WALL_LARGE: "thorium-wall-large" => SimpleBlock::new(2, true);
	PHASE_WALL: "phase-wall" => SimpleBlock::new(1, true);
	PHASE_WALL_LARGE: "phase-wall-large" => SimpleBlock::new(2, true);
	SURGE_WALL: "surge-wall" => SimpleBlock::new(1, true);
	SURGE_WALL_LARGE: "surge-wall-large" => SimpleBlock::new(2, true);
	DOOR: "door" => DoorBlock::new(1, true);
	DOOR_LARGE: "door-large" => DoorBlock::new(2, true);
	// sandbox only
	SCRAP_WALL: "scrap-wall" => SimpleBlock::new(1, true);
	SCRAP_WALL_LARGE: "scrap-wall-large" => SimpleBlock::new(2, true);
	SCRAP_WALL_HUGE: "scrap-wall-huge" => SimpleBlock::new(3, true);
	SCRAP_WALL_GIGANTIC: "scrap-wall-gigantic" => SimpleBlock::new(4, true);
	THRUSTER: "thruster" => SimpleBlock::new(4, false);
);

pub struct DoorBlock
{
	size: u8,
	symmetric: bool,
}

impl DoorBlock
{
	pub const fn new(size: u8, symmetric: bool) -> Self
	{
		if size == 0
		{
			panic!("invalid size");
		}
		Self{size, symmetric}
	}
	
	state_impl!(pub bool);
}

impl BlockLogic for DoorBlock
{
	fn get_size(&self) -> u8
	{
		self.size
	}
	
	fn is_symmetric(&self) -> bool
	{
		self.symmetric
	}
	
	fn data_from_i32(&self, _: i32, _: GridPos) -> Result<DynData, DataConvertError>
	{
		Ok(DynData::Boolean(false))
	}
	
	fn deserialize_state(&self, data: DynData) -> Result<Option<Box<dyn Any>>, DeserializeError>
	{
		match data
		{
			DynData::Boolean(opened) => Ok(Some(Self::create_state(opened))),
			_ => Err(DeserializeError::InvalidType{have: data.get_type(), expect: DynType::Boolean}),
		}
	}
	
	fn clone_state(&self, state: &dyn Any) -> Box<dyn Any>
	{
		let state = Self::get_state(state);
		Box::new(Self::create_state(*state))
	}
	
	fn serialize_state(&self, state: &dyn Any) -> Result<DynData, SerializeError>
	{
		let state = Self::get_state(state);
		Ok(DynData::Boolean(*state))
	}
}