write_brz/
write_brz.rs

1use brdb::{BrFsReader, Brick, Brz, IntoReader, World};
2use std::path::PathBuf;
3
4/// Writes a world with one brick to example_brick
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let path = PathBuf::from("./example_brick.brz");
7
8    let mut world = World::new();
9    world.meta.bundle.description = "Example World".to_string();
10    world.bricks.push(Brick {
11        position: (0, 0, 6).into(),
12        color: (255, 0, 0).into(),
13        ..Default::default()
14    });
15
16    if path.exists() {
17        std::fs::remove_file(&path)?;
18    }
19    world.write_brz(&path)?;
20
21    let db = Brz::new(&path)?.into_reader();
22
23    println!("{}", db.get_fs()?.render());
24
25    let soa = db.brick_chunk_soa(1, (0, 0, 0).into())?;
26    let color = soa.colors_and_alphas[0];
27    assert_eq!(color.r, 255);
28    assert_eq!(color.g, 0);
29    assert_eq!(color.b, 0);
30    assert_eq!(color.a, 5);
31
32    Ok(())
33}