pub struct CyberGrindPattern { /* private fields */ }Implementations§
Source§impl CyberGrindPattern
impl CyberGrindPattern
Sourcepub fn write_to_path<P: AsRef<Path>>(&self, path: P) -> Result<(), Error>
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.
Sourcepub fn write(&self, file: &mut File) -> Result<(), Error>
pub fn write(&self, file: &mut File) -> Result<(), Error>
Takes in a file and writes a Cybergrind Pattern to it.
Sourcepub fn parse(bytes: &[u8]) -> Result<CyberGrindPattern, ParseError>
pub fn parse(bytes: &[u8]) -> Result<CyberGrindPattern, ParseError>
Takes in a series of bytes and tries to turn them into a Cybergrind Pattern.
Sourcepub fn parse_str(string: &str) -> Result<CyberGrindPattern, ParseError>
pub fn parse_str(string: &str) -> Result<CyberGrindPattern, ParseError>
Takes in a string and tries to turn it into a Cybergrind pattern.
Sourcepub fn parse_file(file: &mut File) -> Result<CyberGrindPattern, IoError>
pub fn parse_file(file: &mut File) -> Result<CyberGrindPattern, IoError>
Takes in a string and tries to read it as a Cybergrind pattern.
Sourcepub fn parse_path<P: AsRef<Path>>(path: P) -> Result<CyberGrindPattern, IoError>
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.
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' filesSourcepub fn new() -> Self
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);Sourcepub fn copy_tile_to_row(&mut self, tile: Tile, row: usize)
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);
}Sourcepub fn copy_tile_to_column(&mut self, tile: Tile, column: usize)
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
impl Clone for CyberGrindPattern
Source§fn clone(&self) -> CyberGrindPattern
fn clone(&self) -> CyberGrindPattern
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more