Struct mindus::Schematic

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

schems can have holes, so Option is used.

Implementations§

source§

impl Schematic

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 ratios(&self) -> Io

Ratios of this schematic.

assert_eq!(Schematic::deserialize_base64("bXNjaAF4nEWMSw7CMAxEh9REVSqx5hKcCLFISxaR0o9Sg8rtSTpFePPkmWfDwTWQyY8B5z75VdE9wzrkuGicJwA2+T6kFeb+aNDtym2MW8i4LJ/sNWo4dje8ksa31zmXuyv+Y4BTgRD2iIi9M+xM7WrUgnoNhYpQESpCxfKLrUo9FsISLX6vKgwhhCVK+wX5/BtM").unwrap().ratios(),
    ratios![[Coal: 5.25, Lead: 10.5, Sand: 10.5, Water: 180] => [BlastCompound: 5.25, SporePod: 0.75]]);
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>, 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>, PosError>

gets a block, mutably

source

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

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

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

source

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

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

serialize a schematic to base64

Trait Implementations§

source§

impl Clone for Schematic

source§

fn clone(&self) -> Schematic

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 Debug for Schematic

source§

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

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

impl PartialEq for Schematic

source§

fn eq(&self, rhs: &Schematic) -> 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 Serializable for Schematic

§

type ReadError = ReadError

§

type WriteError = WriteError

source§

fn deserialize(buff: &mut DataRead<'_>) -> Result<Schematic, 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§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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> Join<T, 1, 1, T> for T

source§

fn join(self, with: T) -> [T; 2]

Join a array and an scalar together. For joining two arrays together, see Couple. Read more
source§

impl<T, const O: usize> Join<T, 1, O, [T; O]> for T

source§

fn join(self, with: [T; O]) -> [T; { _ }]

Join a array and an scalar together. For joining two arrays together, see Couple. Read more
source§

impl<T> ToOwned for T
where 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 T
where 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 T
where 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.