mindustry logic execution, map- and schematic- parsing and rendering
Diffstat (limited to 'src/block/simple.rs')
| -rw-r--r-- | src/block/simple.rs | 68 |
1 files changed, 45 insertions, 23 deletions
diff --git a/src/block/simple.rs b/src/block/simple.rs index c78eb0e..2dca7fd 100644 --- a/src/block/simple.rs +++ b/src/block/simple.rs @@ -23,15 +23,19 @@ macro_rules! state_impl { pub(crate) use state_impl; macro_rules! make_simple { - ($name: ident, $draw: expr) => { + ($name: ident, $draw: expr, $read: expr) => { pub struct $name { size: u8, symmetric: bool, - build_cost: BuildCost, + build_cost: crate::block::simple::BuildCost, } impl $name { #[must_use] - pub const fn new(size: u8, symmetric: bool, build_cost: BuildCost) -> Self { + pub const fn new( + size: u8, + symmetric: bool, + build_cost: crate::block::simple::BuildCost, + ) -> Self { assert!(size != 0, "invalid size"); Self { size, @@ -41,51 +45,69 @@ macro_rules! make_simple { } } - use crate::block::{ - impl_block, simple::BuildCost, BlockLogic, DataConvertError, DeserializeError, - SerializeError, State, - }; - use crate::data::dynamic::DynData; - use crate::data::GridPos; - impl BlockLogic for $name { - impl_block!(); - - fn data_from_i32(&self, _: i32, _: GridPos) -> Result<DynData, DataConvertError> { - Ok(DynData::Empty) + impl crate::block::BlockLogic for $name { + crate::block::impl_block!(); + + fn data_from_i32( + &self, + _: i32, + _: crate::data::GridPos, + ) -> Result<crate::DynData, crate::block::DataConvertError> { + Ok(crate::DynData::Empty) } - fn deserialize_state(&self, _: DynData) -> Result<Option<State>, DeserializeError> { + fn deserialize_state( + &self, + _: crate::DynData, + ) -> Result<Option<crate::block::State>, crate::block::DeserializeError> { Ok(None) } - fn clone_state(&self, _: &State) -> State { + fn clone_state(&self, _: &crate::block::State) -> crate::block::State { panic!("{} has no custom state", stringify!($name)) } - fn mirror_state(&self, _: &mut State, _: bool, _: bool) { + fn mirror_state(&self, _: &mut crate::block::State, _: bool, _: bool) { panic!("{} has no custom state", stringify!($name)); } - fn rotate_state(&self, _: &mut State, _: bool) { + fn rotate_state(&self, _: &mut crate::block::State, _: bool) { panic!("{} has no custom state", stringify!($name)); } - fn serialize_state(&self, _: &State) -> Result<DynData, SerializeError> { - Ok(DynData::Empty) + fn serialize_state( + &self, + _: &crate::block::State, + ) -> Result<crate::DynData, crate::block::SerializeError> { + Ok(crate::DynData::Empty) } fn draw( &self, category: &str, name: &str, - state: Option<&State>, - ) -> Option<image::RgbaImage> { + state: Option<&crate::block::State>, + ) -> Option<crate::data::renderer::ImageHolder> { $draw(self, category, name, state) } + + fn read( + &self, + category: &str, + name: &str, + reg: &crate::block::BlockRegistry, + entity_mapping: &crate::data::map::EntityMapping, + buff: &mut crate::data::DataRead, + ) -> Result<(), crate::data::ReadError> { + $read(self, category, name, reg, entity_mapping, buff) + } } }; + ($name: ident, $draw: expr) => { + crate::block::simple::make_simple!($name, $draw, |_, _, _, _, _, _| Ok(())); + }; ($name: ident) => { - crate::block::simple::make_simple!($name, |_, _, _, _| { None }); + crate::block::simple::make_simple!($name, |_, _, _, _| None, |_, _, _, _, _, _| { Ok(()) }); }; } pub(crate) use make_simple; |