Struct mindus::Schematic

source ·
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§tags: HashMap<String, String>§blocks: Array2D<Option<Placement<'l>>>

schems can have holes, so Option is used.

Implementations§

source§

impl<'l> Schematic<'l>

source

pub fn new(width: usize, height: usize) -> Self

create a new schematic, panicking if too big

let s = Schematic::new(5, 5);
source

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);
source

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, &DUO);
assert!(s.get(0, 0).unwrap().is_some());
source

pub fn get_mut( &mut self, x: usize, y: usize ) -> Result<Option<&mut Placement<'l>>, PosError>

gets a block, mutably

source

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, &ROUTER);
assert!(s.get(0, 0).unwrap().is_some() == true);
source

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, &ROUTER, DynData::Empty, Rotation::Right);
assert!(s.get(0, 0).unwrap().is_some() == true);
source

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, &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);
source

pub fn block_iter(&self) -> impl Iterator<Item = (GridPos, &Placement<'_>)>

iterate over all the blocks

source

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<'l> Schematic<'l>

source

pub fn deserialize_base64(data: &str) -> Result<Schematic<'l>, 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");
source

pub fn serialize_base64(&self) -> Result<String, W64Error>

serialize a schematic to base64

Trait Implementations§

source§

impl<'l> Clone for Schematic<'l>

source§

fn clone(&self) -> Schematic<'l>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'l> Debug for Schematic<'l>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'l> PartialEq<Schematic<'l>> for Schematic<'l>

source§

fn eq(&self, rhs: &Schematic<'l>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Renderable for Schematic<'_>

source§

fn render(&self) -> Image<Vec<u8>, 3>

creates a picture of a schematic. Bridges and node connections are not drawn.

let mut s = Schematic::new(2, 3);
s.put(0, 0, &DISTRIBUTOR);
s.put(0, 2, &ROUTER);
s.put(1, 2, &COPPER_WALL);
let output /*: Image */ = s.render();
source§

impl<'l> Serializable for Schematic<'l>

§

type ReadError = ReadError

§

type WriteError = WriteError

source§

fn deserialize( buff: &mut DataRead<'_> ) -> Result<Schematic<'l>, Self::ReadError>

deserialize self from a binary buffer
source§

fn serialize(&self, buff: &mut DataWrite<'_>) -> Result<(), Self::WriteError>

transform self into a binary buffer

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.