Add basic loading state
All checks were successful
CI / Formatting (push) Successful in 1m6s

This commit is contained in:
Michael Bradley 2025-05-24 18:44:04 -04:00
parent 85ca3af12d
commit f0d690a9f8
Signed by: MichaelBradley
SSH key fingerprint: SHA256:o/aaeYtRubILK7OYYjYP12DmU7BsPUhKji1AgaQ+ge4
2 changed files with 24 additions and 7 deletions

View file

@ -11,6 +11,8 @@ use bevy::{
use rand::{Rng as _, SeedableRng}; use rand::{Rng as _, SeedableRng};
use wyrand::WyRand; use wyrand::WyRand;
use crate::AppState;
use super::{ use super::{
objects::{Ball, Player, Radius, Wall}, objects::{Ball, Player, Radius, Wall},
rng::thread_rng, rng::thread_rng,
@ -21,6 +23,12 @@ const BALL_COUNT: u8 = 32;
const BALL_SIZES: Range<f32> = 10.0..25.0; const BALL_SIZES: Range<f32> = 10.0..25.0;
const DIMENSION_SIZES: Range<f32> = 500.0..2000.0; const DIMENSION_SIZES: Range<f32> = 500.0..2000.0;
pub fn check_for_seed(seed: Option<Res<Seed>>, mut next_state: ResMut<NextState<AppState>>) {
if seed.is_some() {
next_state.set(AppState::InGame);
}
}
/// The size of the playable area (x, y) /// The size of the playable area (x, y)
#[derive(Resource)] #[derive(Resource)]
pub struct PlayableArea(f32, f32); pub struct PlayableArea(f32, f32);

View file

@ -11,7 +11,7 @@ mod game;
use game::{ use game::{
runtime::{move_camera, move_player, quit, zoom_camera}, runtime::{move_camera, move_player, quit, zoom_camera},
seed::Seed, seed::Seed,
setup::{setup_balls, setup_from_seed, setup_player, setup_ui, setup_walls}, setup::{check_for_seed, setup_balls, setup_from_seed, setup_player, setup_ui, setup_walls},
}; };
/// The initial configuration passed to the game's setup functions. /// The initial configuration passed to the game's setup functions.
@ -39,6 +39,13 @@ struct Source {
connect: Option<SocketAddr>, connect: Option<SocketAddr>,
} }
#[derive(States, Default, Debug, Clone, PartialEq, Eq, Hash)]
enum AppState {
#[default]
Loading,
InGame,
}
impl Plugin for AppSettings { impl Plugin for AppSettings {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.insert_resource(Gravity(Vector::ZERO)) app.insert_resource(Gravity(Vector::ZERO))
@ -56,23 +63,25 @@ impl Plugin for AppSettings {
#[cfg(feature = "dev")] #[cfg(feature = "dev")]
dev::dev_tools, dev::dev_tools,
)) ))
.init_state::<AppState>()
.add_systems(Startup, setup_ui)
.add_systems( .add_systems(
Startup, OnEnter(AppState::InGame),
( (
setup_from_seed, setup_from_seed,
setup_ui,
(setup_player, setup_balls, setup_walls).after(setup_from_seed), (setup_player, setup_balls, setup_walls).after(setup_from_seed),
), ),
) )
.add_systems( .add_systems(
Update, Update,
( (
move_player, check_for_seed.run_if(in_state(AppState::Loading)),
(move_player, move_camera.after(move_player), zoom_camera)
.run_if(in_state(AppState::InGame)),
quit.run_if(input_pressed(KeyCode::KeyQ)), quit.run_if(input_pressed(KeyCode::KeyQ)),
zoom_camera,
), ),
) );
.add_systems(PostUpdate, move_camera);
if let Some(ref seed) = self.source.seed { if let Some(ref seed) = self.source.seed {
app.insert_resource(seed.clone()); app.insert_resource(seed.clone());
} else if let Some(ref peer) = self.source.connect { } else if let Some(ref peer) = self.source.connect {