pub struct Schematic {
pub width: usize,
pub height: usize,
pub tags: HashMap<String, String>,
pub blocks: Array2D<Option<Placement>>,
}Expand description
a schematic.
Fields§
§width: usize§height: usize§blocks: Array2D<Option<Placement>>schems can have holes, so Option is used.
Implementations§
source§impl Schematic
impl Schematic
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>, PosError>
pub fn get(&self, x: usize, y: usize) -> Result<Option<&Placement>, PosError>
gets a block
let mut s = Schematic::new(5, 5);
assert!(s.get(0, 0).unwrap().is_none());
s.put(0, 0, &DUO);
assert!(s.get(0, 0).unwrap().is_some());sourcepub fn get_mut(
&mut self,
x: usize,
y: usize
) -> Result<Option<&mut Placement>, PosError>
pub fn get_mut( &mut self, x: usize, y: usize ) -> Result<Option<&mut Placement>, PosError>
gets a block, mutably
sourcepub fn put(&mut self, x: usize, y: usize, block: &'static Block) -> &mut Self
pub fn put(&mut self, x: usize, y: usize, block: &'static 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, &ROUTER);
assert!(s.get(0, 0).unwrap().is_some() == true);sourcepub fn set(
&mut self,
x: usize,
y: usize,
block: &'static Block,
data: DynData,
rot: Rotation
) -> Result<(), PlaceError>
pub fn set( &mut self, x: usize, y: usize, block: &'static Block, data: DynData, rot: Rotation ) -> Result<(), PlaceError>
set a block
let mut s = Schematic::new(5, 5);
s.set(0, 0, &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>, PosError>
pub fn take( &mut self, x: usize, y: usize ) -> Result<Option<Placement>, PosError>
take out a block
let mut s = Schematic::new(5, 5);
s.put(0, 0, &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, &CYCLONE);
assert_eq!(s.compute_total_cost().0.get_total(), 405);source§impl Schematic
impl Schematic
sourcepub fn deserialize_base64(data: &str) -> Result<Schematic, R64Error>
pub fn deserialize_base64(data: &str) -> Result<Schematic, R64Error>
deserializes a schematic from base64
let string = "bXNjaAF4nGNgZmBmZmDJS8xNZeBOyslPzlYAkwzcKanFyUWZBSWZ+XkMDAxsOYlJqTnFDEzRsYwMfAWJlTn5iSm6RfmlJalFQGlGEGJkZWSYxQAAcBkUPA==";
let s = Schematic::deserialize_base64(string).unwrap();
assert!(s.get(1, 1).unwrap().unwrap().block.name() == "payload-router");sourcepub fn serialize_base64(&self) -> Result<String, W64Error>
pub fn serialize_base64(&self) -> Result<String, W64Error>
serialize a schematic to base64
Trait Implementations§
source§impl PartialEq<Schematic> for Schematic
impl PartialEq<Schematic> for Schematic
source§impl Renderable for Schematic
impl Renderable for Schematic
source§impl Serializable for Schematic
impl Serializable for Schematic
type ReadError = ReadError
type WriteError = WriteError
Auto Trait Implementations§
impl RefUnwindSafe for Schematic
impl Send for Schematic
impl Sync for Schematic
impl Unpin for Schematic
impl UnwindSafe for Schematic
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