Skip to main content

WirePort

Struct WirePort 

Source
pub struct WirePort {
    pub brick_id: usize,
    pub component_type: BString,
    pub port_name: BString,
}

Fields§

§brick_id: usize

The remote brick where the port is located

§component_type: BString

Name of the component in the brick to connect

§port_name: BString

Name of the port in the component to connect

Implementations§

Source§

impl WirePort

Source

pub fn new( brick_id: usize, component_type: impl Into<BString>, port_name: impl Into<BString>, ) -> Self

Examples found in repository?
examples/write_prefab_spawner.rs (line 70)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11    // 1. Build the prefab that gets spawned: a single red brick.
12    let mut prefab = World::new();
13    prefab.meta.bundle.name = "Spawned Brick".to_string();
14    prefab.bricks.push(Brick {
15        position: (0, 0, 6).into(),
16        color: (255, 0, 0).into(),
17        ..Default::default()
18    });
19    prefab.make_prefab();
20    let prefab_bytes = prefab.to_brz_vec()?;
21
22    // 2. Build the outer world holding the button + spawner.
23    let mut world = World::new();
24    // Registers the built-in component/port tables so the Button and
25    // PrefabSpawner component types and their wire ports resolve.
26    world.register_all_components();
27    world.meta.bundle.description = "Button-triggered prefab spawner".to_string();
28
29    // Embed the prefab; the returned path is what the spawner references.
30    let prefab_path = world.add_prefab(prefab_bytes);
31
32    // A pressable button (Component_Button on a 1x1 flat round brick). The
33    // crate exposes brick assets as constants; components it doesn't model as
34    // typed gates (like the button and spawner) are built from string names
35    // via LiteralComponent.
36    let (button, button_id) = Brick {
37        position: (0, 0, 2).into(),
38        color: (0, 255, 0).into(),
39        asset: assets::bricks::B_1X1F_ROUND,
40        ..Default::default()
41    }
42    .with_component(assets::LiteralComponent::new("Component_Button").with_data([(
43        "PromptCustomLabel",
44        Box::new("Spawn Brick".to_string()) as Box<dyn AsBrdbValue>,
45    )]))
46    .with_id_split();
47
48    // The prefab-spawner gate, pointed at the embedded prefab.
49    let (spawner, spawner_id) = Brick {
50        position: (15, 0, 1).into(),
51        color: (0, 0, 255).into(),
52        asset: assets::bricks::B_1X1_GATE_EXEC_PREFAB_SPAWNER,
53        ..Default::default()
54    }
55    .with_component(
56        assets::LiteralComponent::new("BrickComponentType_WireGraph_Exec_PrefabSpawner").with_data(
57            [(
58                "Prefab",
59                Box::new(prefab_path.clone()) as Box<dyn AsBrdbValue>,
60            )],
61        ),
62    )
63    .with_id_split();
64
65    world.add_bricks([button, spawner]);
66
67    // Wire the button's held signal into the spawner's Exec input, so a
68    // press fires the spawn.
69    world.add_wire_connection(
70        WirePort::new(button_id, "Component_Button", "bHeld"),
71        WirePort::new(
72            spawner_id,
73            "BrickComponentType_WireGraph_Exec_PrefabSpawner",
74            "Exec",
75        ),
76    );
77
78    // 3. Write it out.
79    let path = PathBuf::from("./example_prefab_spawner.brz");
80    world.write_brz(&path)?;
81    println!("wrote {}", path.display());
82
83    // Read it back to confirm the embedded prefab and wire survived.
84    let reader = Brz::open(&path)?.into_reader();
85    println!("embedded prefab: {}", prefab_path);
86    println!("prefab paths in archive: {:?}", reader.prefab_paths()?);
87    println!("{}", reader.get_fs()?.render());
88
89    Ok(())
90}

Trait Implementations§

Source§

impl Clone for WirePort

Source§

fn clone(&self) -> WirePort

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WirePort

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for WirePort

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.