Add Seed display

This commit is contained in:
Michael Bradley 2025-07-05 21:36:17 -04:00
parent 58795eb87e
commit e883f201c0
Signed by: MichaelBradley
SSH key fingerprint: SHA256:o/aaeYtRubILK7OYYjYP12DmU7BsPUhKji1AgaQ+ge4
4 changed files with 39 additions and 3 deletions

View file

@ -6,6 +6,7 @@ mod runtime;
mod seed; mod seed;
mod setup; mod setup;
pub mod state; pub mod state;
mod ui;
#[allow(unused_imports)] #[allow(unused_imports)]
pub mod prelude { pub mod prelude {

View file

@ -9,8 +9,11 @@ use super::{
net::{handle_deleted_peer, handle_incoming_packets, handle_new_peer}, net::{handle_deleted_peer, handle_incoming_packets, handle_new_peer},
runtime::{move_camera, move_player, quit, zoom_camera}, runtime::{move_camera, move_player, quit, zoom_camera},
seed::Seed, seed::Seed,
setup::{check_for_seed, setup_balls, setup_from_seed, setup_player, setup_ui, setup_walls}, setup::{
check_for_seed, setup_balls, setup_camera, setup_from_seed, setup_player, setup_walls,
},
state::AppState, state::AppState,
ui::{setup_seed_display, update_seed_display},
}; };
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
@ -56,7 +59,7 @@ impl Plugin for GamePlugin {
PhysicsPlugins::default().with_length_unit(50.0), PhysicsPlugins::default().with_length_unit(50.0),
)) ))
.init_state::<AppState>() .init_state::<AppState>()
.add_systems(Startup, setup_ui) .add_systems(Startup, (setup_camera, setup_seed_display))
.add_systems( .add_systems(
OnEnter(AppState::InGame), OnEnter(AppState::InGame),
( (
@ -81,6 +84,7 @@ impl Plugin for GamePlugin {
( (
((move_player, move_camera).chain(), zoom_camera) ((move_player, move_camera).chain(), zoom_camera)
.run_if(in_state(AppState::InGame)), .run_if(in_state(AppState::InGame)),
update_seed_display,
quit.run_if(input_pressed(KeyCode::KeyQ)), quit.run_if(input_pressed(KeyCode::KeyQ)),
), ),
); );

View file

@ -43,7 +43,7 @@ pub fn setup_from_seed(mut commands: Commands, seed: Res<Seed>) {
} }
/// I mean, a camera is technically a user interface, I guess /// I mean, a camera is technically a user interface, I guess
pub fn setup_ui(mut commands: Commands) { pub fn setup_camera(mut commands: Commands) {
commands.spawn((Name::new("Camera"), Camera2d, IsDefaultUiCamera)); commands.spawn((Name::new("Camera"), Camera2d, IsDefaultUiCamera));
} }

31
src/game/ui.rs Normal file
View file

@ -0,0 +1,31 @@
use bevy::prelude::*;
use super::seed::Seed;
#[derive(Component, Debug)]
pub struct SeedUI;
pub fn setup_seed_display(mut commands: Commands) {
commands
.spawn((
Text::new("Seed: "),
Node {
position_type: PositionType::Absolute,
bottom: Val::Px(5.0),
left: Val::Px(5.0),
..Default::default()
},
))
.with_child((TextSpan::new("<N/A>"), SeedUI));
}
pub fn update_seed_display(seed: Option<Res<Seed>>, text: Query<&mut TextSpan, With<SeedUI>>) {
if let Some(value) = seed {
if value.is_changed() {
for mut span in text {
let number: u64 = (*value).into();
**span = format!("{}", number);
}
}
}
}