mindustry logic execution, map- and schematic- parsing and rendering
| -rw-r--r-- | src/data/schematic.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/data/schematic.rs b/src/data/schematic.rs index f55c65d..cd257ca 100644 --- a/src/data/schematic.rs +++ b/src/data/schematic.rs @@ -39,10 +39,20 @@ impl Placement &self.state } + pub fn set_state(&mut self, state: DynData) -> DynData + { + std::mem::replace(&mut self.state, state) + } + pub fn get_rotation(&self) -> Rotation { self.rot } + + pub fn set_rotation(&mut self, rot: Rotation) -> Rotation + { + std::mem::replace(&mut self.rot, rot) + } } #[derive(Clone)] @@ -152,6 +162,21 @@ impl Schematic } } + pub fn get_mut(&mut self, x: u16, y: u16) -> Result<Option<&mut Placement>, PosError> + { + if x >= self.width || y >= self.height + { + return Err(PosError{x, y, w: self.width, h: self.height}); + } + if self.blocks.len() == 0 {return Ok(None);} + let pos = (x as usize) + (y as usize) * (self.width as usize); + match self.lookup[pos] + { + None => Ok(None), + Some(idx) => Ok(Some(&mut self.blocks[idx])), + } + } + fn swap_remove(&mut self, idx: usize) -> Placement { // swap_remove not only avoids moves in self.blocks but also reduces the lookup changes we have to do |