-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Impl multiplayer game readiness staging (#691)
- Loading branch information
Showing
9 changed files
with
88 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
use bevy::{app::PluginGroupBuilder, prelude::PluginGroup}; | ||
use map::MapLoaderPlugin; | ||
use readiness::ReadinessPlugin; | ||
|
||
mod map; | ||
mod readiness; | ||
|
||
pub struct LoaderPluginGroup; | ||
|
||
impl PluginGroup for LoaderPluginGroup { | ||
fn build(self) -> PluginGroupBuilder { | ||
PluginGroupBuilder::start::<Self>().add(MapLoaderPlugin) | ||
PluginGroupBuilder::start::<Self>() | ||
.add(MapLoaderPlugin) | ||
.add(ReadinessPlugin) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use bevy::prelude::*; | ||
use de_core::{gamestate::GameState, gconfig::GameConfig}; | ||
use de_messages::Readiness; | ||
use de_multiplayer::{GameReadinessEvent, SetReadinessEvent}; | ||
|
||
pub(crate) struct ReadinessPlugin; | ||
|
||
impl Plugin for ReadinessPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_systems( | ||
OnEnter(GameState::Prepared), | ||
set_readiness(Readiness::Prepared), | ||
) | ||
.add_systems( | ||
OnEnter(GameState::Waiting), | ||
set_readiness(Readiness::Initialized), | ||
) | ||
.add_systems( | ||
Update, | ||
( | ||
progress(Readiness::Prepared, GameState::Loading) | ||
.run_if(in_state(GameState::Prepared)), | ||
progress(Readiness::Initialized, GameState::Playing) | ||
.run_if(in_state(GameState::Waiting)), | ||
), | ||
); | ||
} | ||
} | ||
|
||
fn set_readiness(readiness: Readiness) -> impl Fn(EventWriter<SetReadinessEvent>) { | ||
move |mut events: EventWriter<SetReadinessEvent>| { | ||
events.send(SetReadinessEvent::from(readiness)); | ||
} | ||
} | ||
|
||
fn progress( | ||
readiness: Readiness, | ||
target_state: GameState, | ||
) -> impl Fn(Res<GameConfig>, EventReader<GameReadinessEvent>, ResMut<NextState<GameState>>) { | ||
move |conf: Res<GameConfig>, | ||
mut events: EventReader<GameReadinessEvent>, | ||
mut state: ResMut<NextState<GameState>>| { | ||
if !conf.multiplayer() || events.iter().any(|e| **e == readiness) { | ||
state.set(target_state); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters