mindustry logic execution, map- and schematic- parsing and rendering
Diffstat (limited to 'src/block/simple.rs')
| -rw-r--r-- | src/block/simple.rs | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/block/simple.rs b/src/block/simple.rs index 49f7151..dcbe0dc 100644 --- a/src/block/simple.rs +++ b/src/block/simple.rs @@ -3,6 +3,8 @@ use std::any::{Any, type_name}; use crate::block::{BlockLogic, DataConvertError, DeserializeError, SerializeError}; use crate::data::GridPos; use crate::data::dynamic::DynData; +use crate::item; +use crate::item::storage::Storage; macro_rules!state_impl { @@ -29,21 +31,24 @@ macro_rules!state_impl } pub(crate) use state_impl; +pub type BuildCost = &'static [(item::Type, u32)]; + pub struct SimpleBlock { size: u8, symmetric: bool, + build_cost: BuildCost, } impl SimpleBlock { - pub const fn new(size: u8, symmetric: bool) -> Self + pub const fn new(size: u8, symmetric: bool, build_cost: BuildCost) -> Self { if size == 0 { panic!("invalid size"); } - Self{size, symmetric} + Self{size, symmetric, build_cost} } } @@ -59,6 +64,20 @@ impl BlockLogic for SimpleBlock self.symmetric } + fn create_build_cost(&self) -> Option<Storage> + { + if !self.build_cost.is_empty() + { + let mut storage = Storage::new(); + for (ty, cnt) in self.build_cost + { + storage.add(*ty, *cnt, u32::MAX); + } + Some(storage) + } + else {None} + } + fn data_from_i32(&self, _: i32, _: GridPos) -> Result<DynData, DataConvertError> { Ok(DynData::Empty) @@ -79,3 +98,12 @@ impl BlockLogic for SimpleBlock Ok(DynData::Empty) } } + +macro_rules!cost +{ + ($($item:ident: $cnt:literal),+) => + { + &[$((crate::item::Type::$item, $cnt)),*] + }; +} +pub(crate) use cost; |