pub struct Brick {
pub id: Option<usize>,
pub asset: BrickType,
pub owner_index: Option<usize>,
pub position: Position,
pub rotation: Rotation,
pub direction: Direction,
pub collision: Collision,
pub visible: bool,
pub color: Color,
pub material: BString,
pub material_intensity: u8,
pub components: Vec<Box<dyn BrdbComponent>>,
}Fields§
§id: Option<usize>An internal ID for linking bricks in the database.
asset: BrickType§owner_index: Option<usize>§position: Position§rotation: Rotation§direction: Direction§collision: Collision§visible: bool§color: Color§material: BString§material_intensity: u8§components: Vec<Box<dyn BrdbComponent>>Implementations§
Source§impl Brick
impl Brick
Sourcepub fn with_id(self) -> Self
pub fn with_id(self) -> Self
Sets the ID of the brick to a new value if it does not already have one.
Sourcepub fn with_id_split(self) -> (Self, usize)
pub fn with_id_split(self) -> (Self, usize)
Sets the ID of the brick to a new value if it does not already have one.
Examples found in repository?
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 add_component(&mut self, component: impl BrdbComponent + 'static)
pub fn add_component(&mut self, component: impl BrdbComponent + 'static)
Adds a component to the brick. The component must implement the BrdbComponent trait.
Sourcepub fn add_component_box(&mut self, component: Box<dyn BrdbComponent>)
pub fn add_component_box(&mut self, component: Box<dyn BrdbComponent>)
Adds a component to the brick. The component must implement the BrdbComponent trait.
Sourcepub fn add_components(
&mut self,
components: impl IntoIterator<Item = Box<dyn BrdbComponent>>,
)
pub fn add_components( &mut self, components: impl IntoIterator<Item = Box<dyn BrdbComponent>>, )
Adds multiple components to the brick. The components must implement the BrdbComponent trait.
Sourcepub fn with_component(self, component: impl BrdbComponent + 'static) -> Self
pub fn with_component(self, component: impl BrdbComponent + 'static) -> Self
Adds a component to the brick. The component must implement the BrdbComponent trait.
Examples found in repository?
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 with_component_box(self, component: Box<dyn BrdbComponent>) -> Self
pub fn with_component_box(self, component: Box<dyn BrdbComponent>) -> Self
Adds a component to the brick. The component must implement the BrdbComponent trait.
Sourcepub fn with_components(
self,
components: impl IntoIterator<Item = Box<dyn BrdbComponent>>,
) -> Self
pub fn with_components( self, components: impl IntoIterator<Item = Box<dyn BrdbComponent>>, ) -> Self
Adds multiple components to the brick. The components must implement the BrdbComponent trait.
pub fn cmp(&self, other: &Self) -> Ordering
Sourcepub fn set_material(&mut self, material: impl Into<BString>)
pub fn set_material(&mut self, material: impl Into<BString>)
Sets the material of the brick.
Sourcepub fn with_material(self, material: impl Into<BString>) -> Self
pub fn with_material(self, material: impl Into<BString>) -> Self
Sets the material of the brick.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Brick
impl !RefUnwindSafe for Brick
impl !Send for Brick
impl !Sync for Brick
impl Unpin for Brick
impl !UnwindSafe for Brick
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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