From 79679759c5083835e80005923aaa5693e92aab51 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Mon, 11 Aug 2025 23:42:06 -0500 Subject: [PATCH] Move HUD spawning system into widgets It actually needs to be completely replaced. When that finally happens, the new bits will live here. --- src/lib.rs | 9 +-------- src/widgets.rs | 12 +++++++++++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 006ece5..8567a2b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,7 +47,7 @@ impl Plugin for AsteroidPlugin { .add_systems(Startup, spawn_camera) .add_systems( OnEnter(GameState::Playing), - (objects::spawn_player, spawn_ui), + (objects::spawn_player, widgets::spawn_ui), ) .add_systems( FixedUpdate, @@ -186,10 +186,3 @@ fn input_ship_shoot( )); } } - -fn spawn_ui(mut commands: Commands, score: Res, lives: Res) { - commands.spawn(( - Text::new(format!("Score: {score:?} | Lives: {lives:?}")), - TextFont::from_font_size(25.0), - )); -} diff --git a/src/widgets.rs b/src/widgets.rs index 11733be..c9b898e 100644 --- a/src/widgets.rs +++ b/src/widgets.rs @@ -1,10 +1,20 @@ -use crate::GameState; +use crate::{ + GameState, + resources::{Lives, Score}, +}; use bevy::{ color::palettes::css::{BLACK, GREEN, LIGHT_BLUE, RED}, prelude::*, }; +pub fn spawn_ui(mut commands: Commands, score: Res, lives: Res) { + commands.spawn(( + Text::new(format!("Score: {score:?} | Lives: {lives:?}")), + TextFont::from_font_size(25.0), + )); +} + pub fn preparation_widget_plugin(app: &mut App) { app.add_systems(OnEnter(GameState::GetReady), spawn_get_ready) .add_systems(OnExit(GameState::GetReady), despawn_get_ready)