Skip to main content

write_prefab/
write_prefab.rs

1use brdb::{Brick, BrickSize, BrickType, World, assets};
2use std::path::PathBuf;
3
4/// Writes a single-brick prefab and dumps its Meta JSON for inspection.
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let path = PathBuf::from("./example_prefab.brz");
7
8    let mut world = World::new();
9    // A single 1x1 plate-ish brick (half-extent 5,5,2) at the origin so the
10    // bounds match the hand-captured reference prefab.
11    world.bricks.push(Brick {
12        asset: BrickType::Procedural {
13            asset: assets::bricks::PB_DEFAULT_BRICK.into(),
14            size: BrickSize { x: 5, y: 5, z: 2 },
15        },
16        position: (0, 0, 0).into(),
17        ..Default::default()
18    });
19
20    world.make_prefab();
21    println!(
22        "Prefab.json:\n{}",
23        serde_json::to_string_pretty(world.meta.prefab.as_ref().unwrap())?
24    );
25    println!(
26        "Bundle.json:\n{}",
27        serde_json::to_string_pretty(&world.meta.bundle)?
28    );
29
30    if path.exists() {
31        std::fs::remove_file(&path)?;
32    }
33    world.write_brz(&path)?;
34    println!("wrote {}", path.display());
35    Ok(())
36}