mindustry logic execution, map- and schematic- parsing and rendering
Add simple Block helpers
| -rw-r--r-- | src/block/mod.rs | 19 | ||||
| -rw-r--r-- | src/block/simple.rs | 28 |
2 files changed, 47 insertions, 0 deletions
diff --git a/src/block/mod.rs b/src/block/mod.rs index 1a32b6b..1967ba8 100644 --- a/src/block/mod.rs +++ b/src/block/mod.rs @@ -5,6 +5,8 @@ use std::collections::hash_map::Entry; use crate::access::BoxAccess; use crate::data::dynamic::DynData; +pub mod simple; + pub trait BlockLogic { fn get_size(&self) -> u8; @@ -173,3 +175,20 @@ impl<'l> AsRef<HashMap<&'l str, &'l Block>> for BlockRegistry<'l> &self.blocks } } + +macro_rules!make_register +{ + ($($field:ident: $name:literal => $logic:expr;)+) => + { + $( + pub static $field: $crate::block::Block = $crate::block::Block::new( + std::borrow::Cow::Borrowed($name), $crate::access::Access::Borrowed(&$logic)); + )+ + + pub fn register<'l>(reg: &mut $crate::block::BlockRegistry<'l>) + { + $(assert!(reg.register(&$field).is_ok(), "duplicate block {:?}", $name);)+ + } + }; +} +pub(crate) use make_register; diff --git a/src/block/simple.rs b/src/block/simple.rs new file mode 100644 index 0000000..ebbcc92 --- /dev/null +++ b/src/block/simple.rs @@ -0,0 +1,28 @@ +use crate::block::BlockLogic; + +pub struct SimpleBlock +{ + size: u8, + symmetric: bool, +} + +impl SimpleBlock +{ + pub const fn new(size: u8, symmetric: bool) -> Self + { + Self{size, symmetric} + } +} + +impl BlockLogic for SimpleBlock +{ + fn get_size(&self) -> u8 + { + self.size + } + + fn is_symmetric(&self) -> bool + { + self.symmetric + } +} |