write_wire/
write_wire.rs

1use brdb::{BrFsReader, Brdb, Brick, IntoReader, World, assets};
2use std::path::PathBuf;
3
4/// Writes a world with two bricks and a wire to example_wire
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let path = PathBuf::from("./example_wire.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
13    let (a, a_id) = Brick {
14        position: (0, 0, 1).into(),
15        color: (255, 0, 0).into(),
16        asset: assets::bricks::B_REROUTE,
17        ..Default::default()
18    }
19    .with_component(assets::components::Rerouter)
20    .with_id_split();
21    let (b, b_id) = Brick {
22        position: (15, 0, 1).into(),
23        color: (255, 0, 0).into(),
24        asset: assets::components::LogicGate::BoolNot.brick(),
25        ..Default::default()
26    }
27    .with_component(assets::components::LogicGate::BoolNot.component())
28    .with_id_split();
29
30    world.add_bricks([a, b]);
31    world.add_wire_connection(
32        assets::components::LogicGate::BoolNot.output_of(b_id),
33        assets::components::Rerouter::input_of(a_id),
34    );
35
36    db.save("example world", &world)?;
37
38    println!("{}", db.get_fs()?.render());
39
40    Ok(())
41}