-
-
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.
- Loading branch information
Showing
6 changed files
with
111 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,32 @@ | ||
use bevy::prelude::*; | ||
use iyes_progress::prelude::*; | ||
use iyes_progress::ProgressPlugin; | ||
|
||
use crate::{ | ||
gconfig::GameConfig, | ||
state::AppState, | ||
transition::{DeStateTransition, StateWithSet}, | ||
}; | ||
use crate::{gconfig::GameConfig, nested_state, state::AppState}; | ||
|
||
pub(super) struct GameStatePlugin; | ||
pub(crate) struct GameStateSetupPlugin; | ||
|
||
impl Plugin for GameStatePlugin { | ||
impl Plugin for GameStateSetupPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_state_with_set::<GameState>() | ||
.configure_sets((AppState::state_set(), GameState::state_set()).chain()) | ||
.add_plugin(ProgressPlugin::new(GameState::Loading).continue_to(GameState::Playing)) | ||
.add_system(setup.in_schedule(OnEnter(AppState::InGame))) | ||
.add_system(cleanup.in_schedule(OnExit(AppState::InGame))); | ||
app.add_plugin(GameStatePlugin) | ||
.add_plugin(ProgressPlugin::new(GameState::Loading).continue_to(GameState::Playing)); | ||
} | ||
} | ||
|
||
/// Phase of an already started game. The game might be still loading or | ||
/// finishing. | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, States)] | ||
pub enum GameState { | ||
#[default] | ||
None, | ||
Loading, | ||
Playing, | ||
} | ||
|
||
impl StateWithSet for GameState { | ||
type Set = GameStateSet; | ||
|
||
fn state_set() -> Self::Set { | ||
GameStateSet | ||
nested_state!( | ||
AppState::InGame -> GameState, | ||
doc = "Phase of an already started game. The game might be still loading or finishing.", | ||
enter = setup, | ||
exit = cleanup, | ||
variants = { | ||
Loading, | ||
Playing, | ||
} | ||
} | ||
|
||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, SystemSet)] | ||
pub struct GameStateSet; | ||
); | ||
|
||
fn setup(mut next_state: ResMut<NextState<GameState>>) { | ||
next_state.set(GameState::Loading); | ||
} | ||
|
||
fn cleanup(mut commands: Commands, mut next_state: ResMut<NextState<GameState>>) { | ||
fn cleanup(mut commands: Commands) { | ||
commands.remove_resource::<GameConfig>(); | ||
next_state.set(GameState::None); | ||
} |
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