create scaffolding
This commit is contained in:
commit
82a0fbdb50
25 changed files with 6993 additions and 0 deletions
88
crates/state/src/lib.rs
Normal file
88
crates/state/src/lib.rs
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
//bevy system signatures often violate these rules
|
||||
#![allow(clippy::type_complexity)]
|
||||
#![allow(clippy::too_many_arguments)]
|
||||
|
||||
use avian3d::prelude::*;
|
||||
use bevy::prelude::*;
|
||||
|
||||
pub struct StatePlugin;
|
||||
|
||||
impl Plugin for StatePlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.init_state::<AppState>()
|
||||
.enable_state_scoped_entities::<AppState>()
|
||||
.add_sub_state::<GameState>()
|
||||
.enable_state_scoped_entities::<GameState>()
|
||||
.configure_sets(
|
||||
FixedUpdate,
|
||||
GameSystemSet::LoadingTick.run_if(in_state(GameState::Loading)),
|
||||
)
|
||||
.configure_sets(
|
||||
FixedUpdate,
|
||||
(
|
||||
// these all run before physics, which is in FixedPostUpdate by default
|
||||
GameSystemSet::PreTick,
|
||||
GameSystemSet::Tick,
|
||||
GameSystemSet::PostTick,
|
||||
)
|
||||
.run_if(in_state(GameState::Running))
|
||||
.chain(),
|
||||
)
|
||||
.configure_sets(
|
||||
Update,
|
||||
(
|
||||
GameSystemSet::UpdateInputs,
|
||||
(
|
||||
GameSystemSet::PreUpdate,
|
||||
GameSystemSet::Update,
|
||||
GameSystemSet::PostUpdate,
|
||||
)
|
||||
.run_if(in_state(GameState::Running).or(in_state(GameState::Paused)))
|
||||
.chain(),
|
||||
)
|
||||
.chain(),
|
||||
)
|
||||
.add_systems(OnEnter(GameState::Running), start_physics)
|
||||
.add_systems(OnExit(GameState::Running), stop_physics);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(States, Default, Debug, Hash, PartialEq, Eq, Clone)]
|
||||
pub enum AppState {
|
||||
#[default]
|
||||
Setup,
|
||||
Menu,
|
||||
Game,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Hash, SubStates, Default)]
|
||||
#[source(AppState = AppState::Game)]
|
||||
pub enum GameState {
|
||||
Loading,
|
||||
#[default]
|
||||
Running,
|
||||
Paused,
|
||||
}
|
||||
|
||||
#[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone)]
|
||||
pub enum GameSystemSet {
|
||||
// runs even if game is not loaded/active
|
||||
UpdateInputs,
|
||||
// update - cosmetic only. runs while game is paused
|
||||
PreUpdate,
|
||||
Update,
|
||||
PostUpdate,
|
||||
// fixed update - contains all gameplay logic. does not run when game is paused
|
||||
LoadingTick,
|
||||
PreTick,
|
||||
Tick,
|
||||
PostTick,
|
||||
}
|
||||
|
||||
fn start_physics(mut time: ResMut<Time<Physics>>) {
|
||||
time.unpause();
|
||||
}
|
||||
|
||||
fn stop_physics(mut time: ResMut<Time<Physics>>) {
|
||||
time.pause();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue