diff --git a/assets/config/step.ron b/assets/config/step.ron new file mode 100644 index 0000000..adacca2 --- /dev/null +++ b/assets/config/step.ron @@ -0,0 +1,3 @@ +( + duration_millis: 125, +) diff --git a/src/core.rs b/src/core.rs index af73c77..9907178 100644 --- a/src/core.rs +++ b/src/core.rs @@ -46,10 +46,10 @@ pub(super) fn plugin(app: &mut App) { /// Game logic system ordering in the [`Update`] schedule. #[derive(SystemSet, Clone, Eq, PartialEq, Hash, Debug)] pub enum UpdateSet { - /// Synchronize start-of-frame values. - SyncEarly, /// Tick timers. TickTimers, + /// Synchronize start-of-frame values. + SyncEarly, /// Record player and AI input. RecordInput, /// Step game logic. @@ -67,8 +67,8 @@ impl Configure for UpdateSet { app.configure_sets( Update, ( - Self::SyncEarly, Self::TickTimers, + Self::SyncEarly, Self::Update, Self::RecordInput, Self::HandleEvents, diff --git a/src/game.rs b/src/game.rs index 0862944..272d4e0 100644 --- a/src/game.rs +++ b/src/game.rs @@ -1,5 +1,7 @@ //! Game mechanics and content +mod step; + use bevy::prelude::*; use crate::util::prelude::*; @@ -7,7 +9,7 @@ use crate::util::prelude::*; pub(super) fn plugin(app: &mut App) { app.configure::(); - app.add_plugins(()); + app.add_plugins(step::plugin); } #[derive(Resource, Reflect)] diff --git a/src/game/step.rs b/src/game/step.rs new file mode 100644 index 0000000..61707d6 --- /dev/null +++ b/src/game/step.rs @@ -0,0 +1,83 @@ +use std::time::Duration; + +use bevy::prelude::*; +use serde::Deserialize; +use serde::Serialize; + +use crate::core::UpdateSet; +use crate::util::prelude::*; + +pub(super) fn plugin(app: &mut App) { + app.configure::<(ConfigHandle, StepTimer, Step)>(); +} + +#[derive(Asset, Reflect, Serialize, Deserialize)] +struct StepConfig { + duration_millis: u64, +} + +impl Config for StepConfig { + const PATH: &'static str = "config/step.ron"; + + const EXTENSION: &'static str = "step.ron"; + + fn apply(&self, world: &mut World) { + world + .resource_mut::() + .0 + .set_duration(Duration::from_millis(self.duration_millis)); + } +} + +#[derive(Resource, Reflect)] +#[reflect(Resource)] +pub struct StepTimer(pub Timer); + +impl Configure for StepTimer { + fn configure(app: &mut App) { + app.register_type::(); + app.init_resource::(); + app.add_systems(Update, tick_step_timer.in_set(UpdateSet::TickTimers)); + } +} + +impl Default for StepTimer { + fn default() -> Self { + Self(Timer::new(Duration::from_millis(125), TimerMode::Repeating)) + } +} + +fn tick_step_timer(time: Res