Proof-of-concept for fuel change event handling

Added a `FuelChanged` event which is to be used to trigger Observers
watching for a machine's fuel level change.

I've written a slapdash observer to emit these events when the cutting
machine's big red button is pressed. That observer *must* be replaced
because of how it feeds the machine ID into the UI (it only works when
there is exactly 1 CuttingMachine, which won't be the case).

The dummy machines are missing their machine components. I've added the
`CuttingMachine` component to the cutting machine just to test the event
passing.
This commit is contained in:
2025-08-28 12:01:30 -05:00
parent e169750923
commit 8f6dfc3e49
5 changed files with 62 additions and 22 deletions

32
src/widgets/fuel_gauge.rs Normal file
View File

@@ -0,0 +1,32 @@
use bevy::{color::palettes::css::*, prelude::*, ui::Val::*};
use crate::game::consumables::{Fuel, FuelChanged};
#[derive(Component)]
#[require(Label)]
pub struct FuelGauge(Entity);
impl FuelGauge {
/// Default bundle for a machine's fuel gauge widget. Give it the ID of the
/// machine whose info it is displaying.
pub fn bundle(target: Entity) -> impl Bundle {
(
FuelGauge(target),
Node {
min_width: Px(20.0),
min_height: Px(10.0),
..default()
},
BackgroundColor(GREEN.into()),
Text::new("Fuel: "),
children![TextSpan::new("<n>"),],
)
}
pub fn detect_fuel_change(event: Trigger<FuelChanged>) {
dbg!(format!(
"Detected fuel change on entity ID: {}",
event.target()
));
}
}