Change trait SpawnUi to require a target entity

The UIs aren't *any* UIs. They are specifically *machine* UIs. They need
to be able to fetch data from components on those machine entities,
which means they need some way to find the machine. Passing an entity ID
is the easiest way, IMO.
This commit is contained in:
2025-08-28 12:25:56 -05:00
parent 8f6dfc3e49
commit 5f1f283500
3 changed files with 8 additions and 8 deletions

View File

@@ -86,5 +86,5 @@ fn spawn_machine_ui<M: SpawnUi>(
) {
let _entity = event.target;
// TODO: Hook up the Fuel component (and spawn one so that I can)
M::spawn_ui(commands, theme);
M::spawn_ui(commands, theme, event.target());
}

View File

@@ -7,7 +7,7 @@ use crate::{
};
impl SpawnUi for CuttingMachine {
fn spawn_ui(mut commands: Commands, theme: Res<UiTheme>) {
fn spawn_ui(mut commands: Commands, theme: Res<UiTheme>, machine_id: Entity) {
let base_entity = machine_ui_base(&mut commands, "Cutting Machine", &theme);
commands.entity(base_entity).with_children(|commands| {
// Left panel. For fuel or machine stats or whatever.
@@ -58,7 +58,7 @@ impl SpawnUi for CuttingMachine {
}
impl SpawnUi for RotatingMachine {
fn spawn_ui(mut commands: Commands, theme: Res<UiTheme>) {
fn spawn_ui(mut commands: Commands, theme: Res<UiTheme>, machine_id: Entity) {
let base_entity = machine_ui_base(&mut commands, "Rotating Machine", &theme);
commands.entity(base_entity).with_children(|commands| {
commands.spawn(FuelGauge::bundle(Entity::PLACEHOLDER));
@@ -93,7 +93,7 @@ impl SpawnUi for RotatingMachine {
}
impl SpawnUi for FlippingMachine {
fn spawn_ui(mut commands: Commands, theme: Res<UiTheme>) {
fn spawn_ui(mut commands: Commands, theme: Res<UiTheme>, machine_id: Entity) {
let base_entity = machine_ui_base(&mut commands, "Flipping Machine", &theme);
commands.entity(base_entity).with_children(|commands| {
commands.spawn(FuelGauge::bundle(Entity::PLACEHOLDER));
@@ -128,7 +128,7 @@ impl SpawnUi for FlippingMachine {
}
impl SpawnUi for TransposingMachine {
fn spawn_ui(mut commands: Commands, theme: Res<UiTheme>) {
fn spawn_ui(mut commands: Commands, theme: Res<UiTheme>, machine_id: Entity) {
let base_entity = machine_ui_base(&mut commands, "Transposing Machine", &theme);
commands.entity(base_entity).with_children(|commands| {
commands.spawn(FuelGauge::bundle(Entity::PLACEHOLDER));

View File

@@ -30,12 +30,12 @@ impl Plugin for GameUiPlugin {
}
}
/// Anything that can spawn a themed UI should impl this trait.
/// Machines spawn their UI through this trait.
///
/// This exists mainly so that I can write generic functions and have the *compiler*
/// This exists mainly so that I can write generic functions and have the compiler
/// expand the code for me, instead of doing it by hand.
pub trait SpawnUi {
fn spawn_ui(commands: Commands, theme: Res<UiTheme>);
fn spawn_ui(commands: Commands, theme: Res<UiTheme>, machine_id: Entity);
}
/// The base panel for the machines that manipulate the room cards.