From 0c254b2ed08c6dd3a0bcc49943c9eab2afa58aa8 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Wed, 27 Aug 2025 13:37:36 -0500 Subject: [PATCH] Expand the dummy_machines spawner Spawn a machine entity for each kind of machine. This is where the trait impl becomes important -- now the compiler will make copies of that function for each concrete machine struct so I don't have to. --- src/main.rs | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/src/main.rs b/src/main.rs index ebf503f..32ff853 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,10 @@ -use bevy::{color::palettes::css::GREEN, prelude::*, window::WindowResolution}; +use bevy::{color::palettes::css::*, prelude::*, window::WindowResolution}; use bevy_inspector_egui::{bevy_egui::EguiPlugin, quick::WorldInspectorPlugin}; use crate::{ game::machines::{CuttingMachine, RotatingMachine}, resources::UiTheme, + widgets::SpawnUi, }; mod assets; @@ -24,7 +25,7 @@ fn main() { .add_plugins(EguiPlugin::default()) .add_plugins(WorldInspectorPlugin::new()) .add_plugins(widgets::GameUiPlugin) - .add_systems(Startup, (setup, assets::load_assets, dummy_machine)) + .add_systems(Startup, (setup, assets::load_assets, dummy_machines)) .run(); } @@ -39,26 +40,35 @@ fn despawn(mut commands: Commands, to_despawn: Query>, - // mut materials: ResMut>, -) { +/// Dev tool for spawning dummy entities. I'm developing their UIs by hooking +/// up to these while the TileMap gets ready. +fn dummy_machines(mut commands: Commands) { + // Spawn a dummy Cutting Machine commands .spawn(( - Sprite::from_color(GREEN, Vec2::splat(40.0)), - // WARN: Mesh picking is not part of the `DefaultPlugins` plugin collection! - // (but sprite picking is!) - - // Mesh2d(meshes.add(Rectangle::new(25., 25.))), - // MeshMaterial2d(materials.add(ColorMaterial::from_color(GREEN))), + Sprite::from_color(RED, Vec2::splat(40.0)), Transform::default(), Pickable::default(), )) - .observe( - |event: Trigger>, commands: Commands, theme: Res| { - let entity = event.target; - CuttingMachine::spawn_ui(commands, theme); - }, - ); + .observe(spawn_machine_ui::); + + commands + .spawn(( + Sprite::from_color(GREEN, Vec2::splat(40.0)), + Transform::from_translation(Vec3::new(80.0, 0.0, 0.0)), + Pickable::default(), + )) + .observe(spawn_machine_ui::); + + // TODO: The other machines, once they have a spawner struct & impl. +} + +fn spawn_machine_ui( + event: Trigger>, + commands: Commands, + theme: Res, +) { + let _entity = event.target; + // TODO: Hook up the Fuel component (and spawn one so that I can) + M::spawn_ui(commands, theme); }