mindustry logic execution, map- and schematic- parsing and rendering
Diffstat (limited to 'src/block/power.rs')
| -rw-r--r-- | src/block/power.rs | 37 |
1 files changed, 11 insertions, 26 deletions
diff --git a/src/block/power.rs b/src/block/power.rs index 3e152ef..e21d342 100644 --- a/src/block/power.rs +++ b/src/block/power.rs @@ -3,7 +3,9 @@ use std::error::Error; use std::fmt; use crate::block::simple::{cost, state_impl, BuildCost, SimpleBlock}; -use crate::block::{make_register, BlockLogic, DataConvertError, DeserializeError, SerializeError}; +use crate::block::{ + impl_block, make_register, BlockLogic, DataConvertError, DeserializeError, SerializeError, +}; use crate::data::dynamic::{DynData, DynType}; use crate::data::GridPos; use crate::item::storage::Storage; @@ -39,13 +41,13 @@ pub struct ConnectorBlock { } impl ConnectorBlock { + #[must_use] pub const fn new(size: u8, symmetric: bool, build_cost: BuildCost, max: u8) -> Self { - if size == 0 { - panic!("invalid size"); - } - if max == 0 || max > i8::MAX as u8 { - panic!("invalid maximum link count"); - } + assert!(size != 0, "invalid size"); + assert!( + !(max == 0 || max > i8::MAX as u8), + "invalid maximum link count" + ); Self { size, symmetric, @@ -54,6 +56,7 @@ impl ConnectorBlock { } } + #[must_use] pub fn get_max_links(&self) -> u8 { self.max } @@ -62,25 +65,7 @@ impl ConnectorBlock { } impl BlockLogic for ConnectorBlock { - fn get_size(&self) -> u8 { - self.size - } - - fn is_symmetric(&self) -> bool { - 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 - } - } + impl_block!(); fn data_from_i32(&self, _: i32, _: GridPos) -> Result<DynData, DataConvertError> { Ok(DynData::Empty) |