Skip to content

Commit

Permalink
add PlayTime resource to record time spent playing while in active state
Browse files Browse the repository at this point in the history
  • Loading branch information
thombruce committed Nov 18, 2023
1 parent 8e48aec commit 6148d5f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- PlayTime resource records unpaused play time

## [0.0.26] - 2023-11-18

### Added
Expand Down
8 changes: 8 additions & 0 deletions src/core/resources/game_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ use bevy::{prelude::*, time::Stopwatch};
#[derive(Resource, Deref)]
pub struct GameTime(pub Stopwatch);

#[derive(Resource, Deref)]
pub struct PlayTime(pub Stopwatch);

pub struct GameTimePlugin;
impl Plugin for GameTimePlugin {
fn build(&self, app: &mut App) {
app.insert_resource(GameTime(Stopwatch::new()));
app.insert_resource(PlayTime(Stopwatch::new()));
}
}

Expand All @@ -21,3 +25,7 @@ pub(crate) fn tick_game_time(time: Res<Time>, mut game_time: ResMut<GameTime>) {
// too unnatural. It feels suitable for the game as an arcade shooter,
// so this is probably where we'll land for v0.1.
}

pub(crate) fn tick_play_time(time: Res<Time>, mut play_time: ResMut<PlayTime>) {
play_time.0.tick(time.delta());
}
1 change: 1 addition & 0 deletions src/systems/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ impl Plugin for SystemsPlugin {
app.add_systems(
Update,
(
resources::game_time::tick_play_time,
player::player_flight_system.in_set(MovementSet),
camera::follow_player.after(MovementSet),
player::player_weapons_system.in_set(AttackSet),
Expand Down

0 comments on commit 6148d5f

Please sign in to comment.