Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Indy2222 committed Aug 18, 2023
1 parent 49ce374 commit 4dcc718
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion crates/camera/src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl Plugin for CameraPlugin {
Update,
setup_shadows
.track_progress()
.run_if(in_state(GameState::Loading)),
.run_if(in_state(GameState::Initializing)),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/camera/src/skybox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl Plugin for SkyboxPlugin {
configure_cubemap
.track_progress()
.run_if(in_state(AppState::AppLoading)),
setup_camera.run_if(in_state(GameState::Loading)),
setup_camera.run_if(in_state(GameState::Initializing)),
),
);
}
Expand Down
9 changes: 7 additions & 2 deletions crates/core/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ use bevy::{

use crate::gamestate::GameState;

/// This plugin accumulates events received during [`GameState::Waiting`] and
/// [`GameState::Initializing`] and re-sends them on enter of
/// [`GameState::Playing`].
pub struct ResendEventPlugin<T: Event> {
_marker: PhantomData<T>,
}
Expand All @@ -24,10 +27,12 @@ impl<T: Event> Default for ResendEventPlugin<T> {

impl<T: Event> Plugin for ResendEventPlugin<T> {
fn build(&self, app: &mut App) {
app.add_systems(OnEnter(GameState::Loading), setup::<T>)
app.add_systems(OnEnter(GameState::Waiting), setup::<T>)
.add_systems(
Update,
enqueue_events::<T>.run_if(in_state(GameState::Loading)),
enqueue_events::<T>.run_if(
in_state(GameState::Waiting).or_else(in_state(GameState::Initializing)),
),
)
.add_systems(
OnEnter(GameState::Playing),
Expand Down
8 changes: 5 additions & 3 deletions crates/core/src/gamestate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ impl Plugin for GameStateSetupPlugin {
fn build(&self, app: &mut App) {
app.add_plugins((
GameStatePlugin,
ProgressPlugin::new(GameState::Loading).continue_to(GameState::Playing),
ProgressPlugin::new(GameState::Waiting).continue_to(GameState::Initializing),
ProgressPlugin::new(GameState::Initializing).continue_to(GameState::Playing),
));
}
}
Expand All @@ -20,13 +21,14 @@ nested_state!(
enter = setup,
exit = cleanup,
variants = {
Loading,
Waiting,
Initializing,
Playing,
}
);

fn setup(mut next_state: ResMut<NextState<GameState>>) {
next_state.set(GameState::Loading);
next_state.set(GameState::Waiting);
}

fn cleanup(mut commands: Commands) {
Expand Down
9 changes: 8 additions & 1 deletion crates/core/src/gconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ use crate::player::{Player, PlayerRange};
#[derive(Resource)]
pub struct GameConfig {
map_path: PathBuf,
multiplayer: bool,
locals: LocalPlayers,
}

impl GameConfig {
pub fn new<P: Into<PathBuf>>(map_path: P, locals: LocalPlayers) -> Self {
pub fn new<P: Into<PathBuf>>(map_path: P, multiplayer: bool, locals: LocalPlayers) -> Self {
Self {
map_path: map_path.into(),
multiplayer,
locals,
}
}
Expand All @@ -25,6 +27,10 @@ impl GameConfig {
self.map_path.as_path()
}

pub fn multiplayer(&self) -> bool {
self.multiplayer
}

pub fn locals(&self) -> &LocalPlayers {
&self.locals
}
Expand Down Expand Up @@ -95,6 +101,7 @@ mod tests {
fn test_game_config() {
let config = GameConfig::new(
"/some/path",
false,
LocalPlayers::from_max_player(Player::Player1, Player::Player4),
);
assert_eq!(config.map_path().to_string_lossy(), "/some/path");
Expand Down
2 changes: 1 addition & 1 deletion crates/loader/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Plugin for MapLoaderPlugin {
Update,
spawn_map
.track_progress()
.run_if(in_state(GameState::Loading)),
.run_if(in_state(GameState::Initializing)),
);
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/menu/src/multiplayer/joined/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ fn start(

commands.insert_resource(GameConfig::new(
map_path,
true,
LocalPlayers::from_single(player.0),
));
app_state.set(AppState::InGame);
Expand Down
1 change: 1 addition & 0 deletions crates/menu/src/singleplayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ fn button_system(
Some(path) => {
commands.insert_resource(GameConfig::new(
path,
false,
LocalPlayers::from_max_player(Player::Player1, Player::Player4),
));
next_state.set(AppState::InGame);
Expand Down
2 changes: 1 addition & 1 deletion crates/terrain/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Plugin for TerrainPlugin {
(
setup_textures
.track_progress()
.run_if(in_state(GameState::Loading)),
.run_if(in_state(GameState::Initializing)),
init.run_if(in_state(AppState::InGame)),
),
);
Expand Down

0 comments on commit 4dcc718

Please sign in to comment.