pub struct World {
pub meta: WorldMeta,
pub owners: IndexMap<Guid, Owner>,
pub bricks: Vec<Brick>,
pub grids: Vec<(Entity, Vec<Brick>)>,
pub wires: Vec<WireConnection>,
pub entities: Vec<Entity>,
}Fields§
§meta: WorldMeta§owners: IndexMap<Guid, Owner>§bricks: Vec<Brick>Bricks on the main grid
grids: Vec<(Entity, Vec<Brick>)>Non-main grids require an entity to be created for them
wires: Vec<WireConnection>§entities: Vec<Entity>Implementations§
Source§impl World
impl World
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/write_brick.rs (line 8)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let path = PathBuf::from("./example_brick.brdb");
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 world.write_brdb(&path)?;
17
18 let db = Brdb::new(&path)?.into_reader();
19
20 println!("file structure: {}", db.get_fs()?.render());
21
22 let soa = db.brick_chunk_soa(1, (0, 0, 0).into())?;
23 let color = soa.colors_and_alphas[0];
24 assert_eq!(color.r, 255);
25 assert_eq!(color.g, 0);
26 assert_eq!(color.b, 0);
27 assert_eq!(color.a, 5);
28
29 Ok(())
30}More examples
examples/write_entity.rs (line 10)
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}examples/write_brz.rs (line 8)
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}examples/write_wire.rs (line 10)
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}Sourcepub fn write_brdb(&self, path: impl AsRef<Path>) -> Result<(), BrError>
pub fn write_brdb(&self, path: impl AsRef<Path>) -> Result<(), BrError>
Examples found in repository?
examples/write_brick.rs (line 16)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let path = PathBuf::from("./example_brick.brdb");
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 world.write_brdb(&path)?;
17
18 let db = Brdb::new(&path)?.into_reader();
19
20 println!("file structure: {}", db.get_fs()?.render());
21
22 let soa = db.brick_chunk_soa(1, (0, 0, 0).into())?;
23 let color = soa.colors_and_alphas[0];
24 assert_eq!(color.r, 255);
25 assert_eq!(color.g, 0);
26 assert_eq!(color.b, 0);
27 assert_eq!(color.a, 5);
28
29 Ok(())
30}Sourcepub fn write_brz(&self, path: impl AsRef<Path>) -> Result<(), BrError>
pub fn write_brz(&self, path: impl AsRef<Path>) -> Result<(), BrError>
Examples found in repository?
examples/write_brz.rs (line 19)
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}pub fn to_brz_vec(&self) -> Result<Vec<u8>, BrError>
pub fn to_unsaved(&self) -> Result<UnsavedFs, BrError>
Sourcepub fn add_bricks(&mut self, bricks: impl IntoIterator<Item = Brick>)
pub fn add_bricks(&mut self, bricks: impl IntoIterator<Item = Brick>)
Add multiple bricks to the world
Examples found in repository?
examples/write_wire.rs (line 30)
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}pub fn add_entity(&mut self, entity: Entity)
Sourcepub fn add_brick_grid(
&mut self,
entity: Entity,
bricks: impl IntoIterator<Item = Brick>,
)
pub fn add_brick_grid( &mut self, entity: Entity, bricks: impl IntoIterator<Item = Brick>, )
Examples found in repository?
examples/write_entity.rs (lines 12-23)
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}Sourcepub fn add_wire(&mut self, conn: WireConnection)
pub fn add_wire(&mut self, conn: WireConnection)
Add a single wire connection to the world
Sourcepub fn add_wires(&mut self, wires: impl IntoIterator<Item = WireConnection>)
pub fn add_wires(&mut self, wires: impl IntoIterator<Item = WireConnection>)
Add multiple wire connections to the world
Sourcepub fn add_wire_connection(&mut self, source: WirePort, target: WirePort)
pub fn add_wire_connection(&mut self, source: WirePort, target: WirePort)
Add a wire connection from one port to another
Examples found in repository?
examples/write_wire.rs (lines 31-34)
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}Trait Implementations§
Auto Trait Implementations§
impl Freeze for World
impl !RefUnwindSafe for World
impl !Send for World
impl !Sync for World
impl Unpin for World
impl !UnwindSafe for World
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more