Giter Site home page Giter Site logo

brs's Introduction

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

brs's People

Contributors

dgunay avatar qoh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

suficio meshiest

brs's Issues

Outdated

Error: Custom { kind: InvalidData, error: "Unsupported version" }

Library may be reading data incorrectly for some saves

brs-rs does not read owners correctly

use brs::{Brick, Reader};
use std::collections::HashSet;
use std::fs::File;
use std::io::Error;
use std::result::Result;

// open and read a brs file, returns parsed write data
pub fn open(filename: &'_ str) -> Result<Vec<Brick>, Error> {
    // open brs file
    let reader = Reader::new(File::open(filename)?)?;

    // read headers and bricks
    let (_reader, bricks) = reader
        .read_header1()?
        .read_header2()?
        .iter_bricks_and_reader()?;

    // enerate some writedata as a mirror of the reader output
    Ok(bricks.map(|b| b.unwrap()).collect::<Vec<Brick>>())
}

fn main() {
    let bricks = open("./brickadia city.brs").expect("error!!");

    println!("Found {} bricks", bricks.len());

    // read all owners into a set
    let mut owners = HashSet::new();
    bricks.into_iter().for_each(|b| {
        owners.insert(b.owner_index);
    });

    println!("owners {:?}", owners);
}

brickadia_city.brs
expected: owners {1,2,3,4,5,6,7,8,9,10,11}
received: owners {8709136, 396740, 3901, 654432, 9776, 948106795, 92975640, 1114638700, 496275152, 3489, 33875467, 793, 12636, 327235, 10604, 16268, 7760, 11150, 1973305, 1651430, 160352779, ...

so i think i narrowed down the issue w/ brs to saves that have colors outside of the colorset, none of the img2brs saves work and sylvs dont work because he has dis weird gradient brick thing in de middle.

these bricks are loaded w/ wack sizes, positions, brick_owners, etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.