#file #binary #parser #brickadia

bin+lib brs

Read and write Brickadia save files

2 unstable releases

0.2.0 May 8, 2020
0.1.0 Apr 19, 2019
0.0.0 Apr 14, 2019

#1821 in Encoding

29 downloads per month

MIT license

42KB
933 lines

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

Dependencies

~3.5MB
~72K SLoC