write_entity/
write_entity.rs

1use brdb::{BrFsReader, Brdb, Brick, Entity, IntoReader, World};
2use std::path::PathBuf;
3
4/// Writes a world a brick on a floating brick grid to example_entity.brdb
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let path = PathBuf::from("./example_entity.brdb");
7
8    // Ensures the memory db can be created without errors
9    let db = Brdb::new(&path)?.into_reader();
10    let mut world = World::new();
11    world.meta.bundle.description = "Example World".to_string();
12    world.add_brick_grid(
13        Entity {
14            frozen: true,
15            location: (0.0, 0.0, 40.0).into(),
16            ..Default::default()
17        },
18        [Brick {
19            position: (0, 0, 3).into(),
20            color: (0, 255, 0).into(),
21            ..Default::default()
22        }],
23    );
24
25    db.save("example world", &world)?;
26
27    println!("{}", db.get_fs()?.render());
28
29    Ok(())
30}