brs

Crates.iobrs
lib.rsbrs
version0.2.0
sourcesrc
created_at2019-04-14 17:08:38.00328
updated_at2020-05-08 18:02:02.876021
descriptionRead and write Brickadia save files.
homepage
repository
max_upload_size
id127937
size49,159
(qoh)

documentation

README

brs on crates.io brs on docs.rs

Interfaces for reading and writing Brickadia save files.

Aims to be able to read all previous versions just like the game, but only write the newest version of the format.

Usage

Reading

First, create a reader from any Read source, such as a file or buffer.

let reader = brs::Reader::new(File::open("village.brs")?)?;

Brickadia save files have information split into sections ordered such that one can extract simple information without needing to parse the entire file.

This library surfaces this by strictly enforcing the way that data is read and made available at the type level; you can't go wrong.

To continue, reading the first header gets you basic information. For details on what is available, see HasHeader1.

use brs::HasHeader1;
let reader = reader.read_header1();
println!("Brick count: {}", reader.brick_count());
println!("Map: {}", reader.map());

The next header contains data less likely to be relevant for simpler introspection, but rather things such as tables for loading bricks. See HasHeader2.

use brs::HasHeader2;
let reader = reader.read_header2();
println!("Mods: {:?}", reader.mods());
println!("Color count: {}", reader.colors().len());
// Properties from header 1 are still available:
println!("Description: {}", reader.description();

After both headers have been read, you may now iterate over the bricks. See Brick.

for brick in reader.iter_bricks()? {
    let brick = brick?;
    println!("{:?}", brick);
}

You may retain access to the header information while getting the iterator:

let (rdr, bricks) = reader.iter_bricks_and_reader()?;

Writing

Writing save files isn't as fancy, for now you simply just put all the data in the WriteData struct and pass it to write_save along with a Write destination.

let data = brs::WriteData {
    map: String::from("Plate"),
    description: String::from("A quaint park full of ducks and turkeys."),
    // ...
};
brs::write_save(&mut File::create("park.brs")?, &data)?;
Commit count: 0

cargo fmt