World

Struct World 

Source
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

Source

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
Hide additional 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}
Source

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}
Source

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}
Source

pub fn to_brz_vec(&self) -> Result<Vec<u8>, BrError>

Source

pub fn to_unsaved(&self) -> Result<UnsavedFs, BrError>

Source

pub fn add_brick(&mut self, brick: Brick)

Add a single brick to the world

Source

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}
Source

pub fn add_entity(&mut self, entity: Entity)

Source

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}
Source

pub fn add_wire(&mut self, conn: WireConnection)

Add a single wire connection to the world

Source

pub fn add_wires(&mut self, wires: impl IntoIterator<Item = WireConnection>)

Add multiple wire connections to the world

Source

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§

Source§

impl Default for World

Source§

fn default() -> World

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.