Skip to main content

CyberGrindPattern

Struct CyberGrindPattern 

Source
pub struct CyberGrindPattern { /* private fields */ }

Implementations§

Source§

impl CyberGrindPattern

Source

pub fn write_to_path<P: AsRef<Path>>(&self, path: P) -> Result<(), Error>

Creates a new file at path path. If one already exists, it is truncated. Outputs a Cybergrind Pattern File to that path.

Source

pub fn write(&self, file: &mut File) -> Result<(), Error>

Takes in a file and writes a Cybergrind Pattern to it.

Source

pub fn parse(bytes: &[u8]) -> Result<CyberGrindPattern, ParseError>

Takes in a series of bytes and tries to turn them into a Cybergrind Pattern.

Source

pub fn parse_str(string: &str) -> Result<CyberGrindPattern, ParseError>

Takes in a string and tries to turn it into a Cybergrind pattern.

Source

pub fn parse_file(file: &mut File) -> Result<CyberGrindPattern, IoError>

Takes in a string and tries to read it as a Cybergrind pattern.

Source

pub fn parse_path<P: AsRef<Path>>(path: P) -> Result<CyberGrindPattern, IoError>

Tries to open a file at path path and reads it as a Cybergrind Patter.

Source§

impl CyberGrindPattern

An interface for building cybergrind patterns. This a 512-byte wide struct with a padding of 16 bits, so small enough to store on the stack if necessary.

A Cybergrind pattern is a 16x16 array of tiles. Each tile has a height and optional prefab.

use tinycbg::{CyberGrindPattern, Tile, Prefab};

let mut pat = CyberGrindPattern::new();
let wall_tile = Tile::new(20, Prefab::None);

pat.copy_tile_to_column(wall_tile, 0);
pat.copy_tile_to_column(wall_tile, 15);
// Patterns can be indexed with
// coordinates or numbers 0-255
pat[(7, 7)].set_prefab(Prefab::Melee);

pat.write_to_path("test.cgp"); // Cybergrind patterns are stored in '.cgp' files
Source

pub fn new() -> Self

Creates a new Cybergrind pattern with all tiles initialized to have a height of zero and no prefab. Same as CyberGrindPattern::default()

use tinycbg::{CyberGrindPattern, Prefab};

let pat = CyberGrindPattern::new();
assert_eq!(pat[0].height(), 0);
assert_eq!(pat[0].prefab(), Prefab::None);
Source

pub fn copy_tile_to_row(&mut self, tile: Tile, row: usize)

Copies the data from tile Tile to row number row.

use tinycbg::{CyberGrindPattern, Tile};

let mut pat = CyberGrindPattern::new();

let wall_tile = Tile::with_height(20);

let row = 10;
pat.copy_tile_to_row(wall_tile, row);
for i in 0..16 {
    assert_eq!(pat[(i, row)], wall_tile);
}
Source

pub fn copy_tile_to_column(&mut self, tile: Tile, column: usize)

Copies the data from tile Tile to column number column.

use tinycbg::{CyberGrindPattern, Tile};

let mut pat = CyberGrindPattern::new();

let wall_tile = Tile::with_height(20);

let column = 7;
pat.copy_tile_to_column(wall_tile, column);
for i in 0..16 {
    assert_eq!(pat[(column, i)], wall_tile);

}

Trait Implementations§

Source§

impl Clone for CyberGrindPattern

Source§

fn clone(&self) -> CyberGrindPattern

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Default for CyberGrindPattern

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<Vec<Tile>> for CyberGrindPattern

Source§

fn from(values: Vec<Tile>) -> Self

Converts to this type from the input type.
Source§

impl From<[Tile; 256]> for CyberGrindPattern

Source§

fn from(tiles: [Tile; 256]) -> Self

Converts to this type from the input type.
Source§

impl Index<(usize, usize)> for CyberGrindPattern

Source§

type Output = Tile

The returned type after indexing.
Source§

fn index(&self, coordinate: (usize, usize)) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<Range<usize>> for CyberGrindPattern

Source§

type Output = [Tile]

The returned type after indexing.
Source§

fn index(&self, range: Range<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeFull> for CyberGrindPattern

Source§

type Output = [Tile]

The returned type after indexing.
Source§

fn index(&self, range: RangeFull) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<usize> for CyberGrindPattern

Source§

type Output = Tile

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<(usize, usize)> for CyberGrindPattern

Source§

fn index_mut(&mut self, coordinate: (usize, usize)) -> &mut Tile

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<Range<usize>> for CyberGrindPattern

Source§

fn index_mut(&mut self, range: Range<usize>) -> &mut [Tile]

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<RangeFull> for CyberGrindPattern

Source§

fn index_mut(&mut self, range: RangeFull) -> &mut [Tile]

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<usize> for CyberGrindPattern

Source§

fn index_mut(&mut self, index: usize) -> &mut Tile

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a> IntoIterator for &'a CyberGrindPattern

Source§

type Item = Tile

The type of the elements being iterated over.
Source§

type IntoIter = CyberGrindPatternIter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

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>,

Source§

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>,

Source§

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.