pub struct Schematic<'l> {
pub width: usize,
pub height: usize,
pub tags: HashMap<String, String>,
pub blocks: Array2D<Option<Placement<'l>>>,
}Expand description
a schematic.
Fields§
§width: usize§height: usize§blocks: Array2D<Option<Placement<'l>>>schems can have holes, so Option is used.
Implementations§
source§impl<'l> Schematic<'l>
impl<'l> Schematic<'l>
sourcepub fn new(width: usize, height: usize) -> Self
pub fn new(width: usize, height: usize) -> Self
create a new schematic, panicking if too big
let s = Schematic::new(5, 5);sourcepub fn try_new(width: usize, height: usize) -> Result<Self, NewError>
pub fn try_new(width: usize, height: usize) -> Result<Self, NewError>
create a new schematic, erroring if too big
assert!(Schematic::try_new(500, 500).is_err() == true);sourcepub fn get(
&self,
x: usize,
y: usize
) -> Result<Option<&Placement<'l>>, PosError>
pub fn get( &self, x: usize, y: usize ) -> Result<Option<&Placement<'l>>, PosError>
gets a block
let mut s = Schematic::new(5, 5);
assert!(s.get(0, 0).unwrap().is_none());
s.put(0, 0, &mindus::block::turrets::DUO);
assert!(s.get(0, 0).unwrap().is_some());sourcepub fn get_mut(
&mut self,
x: usize,
y: usize
) -> Result<Option<&mut Placement<'l>>, PosError>
pub fn get_mut( &mut self, x: usize, y: usize ) -> Result<Option<&mut Placement<'l>>, PosError>
gets a block, mutably
sourcepub fn put(&mut self, x: usize, y: usize, block: &'l Block) -> &mut Self
pub fn put(&mut self, x: usize, y: usize, block: &'l Block) -> &mut Self
put a block in (same as Schematic::set, but less arguments and builder-ness). panics!!!
let mut s = Schematic::new(5, 5);
s.put(0, 0, &mindus::block::distribution::ROUTER);
assert!(s.get(0, 0).unwrap().is_some() == true);sourcepub fn set(
&mut self,
x: usize,
y: usize,
block: &'l Block,
data: DynData,
rot: Rotation
) -> Result<(), PlaceError>
pub fn set( &mut self, x: usize, y: usize, block: &'l Block, data: DynData, rot: Rotation ) -> Result<(), PlaceError>
set a block
let mut s = Schematic::new(5, 5);
s.set(0, 0, &mindus::block::distribution::ROUTER, DynData::Empty, Rotation::Right);
assert!(s.get(0, 0).unwrap().is_some() == true);sourcepub fn take(
&mut self,
x: usize,
y: usize
) -> Result<Option<Placement<'l>>, PosError>
pub fn take( &mut self, x: usize, y: usize ) -> Result<Option<Placement<'l>>, PosError>
take out a block
let mut s = Schematic::new(5, 5);
s.put(0, 0, &mindus::block::turrets::DUO);
assert!(s.get(0, 0).unwrap().is_some() == true);
assert!(s.take(0, 0).unwrap().is_some() == true);
assert!(s.get(0, 0).unwrap().is_none() == true);sourcepub fn block_iter(&self) -> impl Iterator<Item = (GridPos, &Placement<'_>)>
pub fn block_iter(&self) -> impl Iterator<Item = (GridPos, &Placement<'_>)>
iterate over all the blocks
sourcepub fn compute_total_cost(&self) -> (ItemStorage, bool)
pub fn compute_total_cost(&self) -> (ItemStorage, bool)
see how much this schematic costs.
returns (cost, is_sandbox)
let mut s = Schematic::new(5, 5);
s.put(1, 1, &mindus::block::turrets::CYCLONE);
assert_eq!(s.compute_total_cost().0.get_total(), 405);Trait Implementations§
source§impl<'l> PartialEq<Schematic<'l>> for Schematic<'l>
impl<'l> PartialEq<Schematic<'l>> for Schematic<'l>
source§impl Renderable for Schematic<'_>
impl Renderable for Schematic<'_>
source§unsafe fn render(&self) -> RgbImage
unsafe fn render(&self) -> RgbImage
creates a picture of a schematic. Bridges and node connections are not drawn.
use mindus::*;
let mut s = Schematic::new(2, 3);
s.put(0, 0, &block::distribution::DISTRIBUTOR);
s.put(0, 2, &block::distribution::ROUTER);
s.put(1, 2, &block::walls::COPPER_WALL);
// warm up the images for the first time
unsafe { warmup(); }
// this is now safe, because we have warmed up
let output /*: RgbImage */ = unsafe { s.render() };Safety
UB if called before warmup
source§impl<'l> Serializer<Schematic<'l>> for SchematicSerializer<'l>
impl<'l> Serializer<Schematic<'l>> for SchematicSerializer<'l>
Auto Trait Implementations§
impl<'l> !RefUnwindSafe for Schematic<'l>
impl<'l> Send for Schematic<'l>
impl<'l> Sync for Schematic<'l>
impl<'l> Unpin for Schematic<'l>
impl<'l> !UnwindSafe for Schematic<'l>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more