fix: Stop granting berries for minutes passed in pause phase

This commit is contained in:
demenik
2025-12-10 15:26:11 +01:00
parent 3a8e16d085
commit 3b310ea198
2 changed files with 54 additions and 32 deletions

View File

@@ -10,3 +10,6 @@ pub struct PhaseTimerPauseMessage;
#[derive(Message)]
pub struct NextPhaseMessage;
#[derive(Message)]
pub struct PhaseMinutePassedMessage;

View File

@@ -18,11 +18,18 @@ impl Plugin for PhasePlugin {
}));
app.add_message::<PhaseTimerFinishedMessage>();
app.add_message::<PhaseMinutePassedMessage>();
app.add_systems(OnEnter(AppState::GameScreen), load_rules);
app.add_systems(
Update,
(tick_timer, handle_pause, handle_continue).run_if(in_state(AppState::GameScreen)),
(
tick_timer,
handle_pause,
handle_continue,
grant_focus_rewards,
)
.run_if(in_state(AppState::GameScreen)),
);
#[cfg(debug_assertions)]
@@ -69,14 +76,8 @@ fn tick_timer(
time: Res<Time>,
mut phase_res: ResMut<CurrentPhase>,
mut finish_writer: MessageWriter<PhaseTimerFinishedMessage>,
mut minute_writer: MessageWriter<PhaseMinutePassedMessage>,
mut savegame_messages: MessageWriter<SavegameDumpMessage>,
config: Res<GameConfig>,
mut inventory: ResMut<Inventory>,
mut commands: Commands,
mut items_query: Query<&mut ItemStack>,
mut session_tracker: ResMut<SessionTracker>,
game_config: Res<GameConfig>,
mut notifications: ResMut<Notifications>,
) {
let delta = time.delta_secs();
let phase = &mut phase_res.0;
@@ -88,6 +89,39 @@ fn tick_timer(
let new_minutes = (*duration / 60.0).floor() as i32;
if new_minutes < old_minutes {
minute_writer.write(PhaseMinutePassedMessage);
}
if *duration <= 0.0 {
finish_writer.write(PhaseTimerFinishedMessage {
phase: phase.clone(),
});
let completed = phase.clone();
*phase = Phase::Finished {
completed_phase: Box::new(completed),
};
println!("phase ended");
savegame_messages.write(SavegameDumpMessage);
}
}
_ => {}
}
}
fn grant_focus_rewards(
mut messages: MessageReader<PhaseMinutePassedMessage>,
phase_res: Res<CurrentPhase>,
config: Res<GameConfig>,
mut inventory: ResMut<Inventory>,
mut commands: Commands,
mut items_query: Query<&mut ItemStack>,
mut session_tracker: ResMut<SessionTracker>,
game_config: Res<GameConfig>,
mut notifications: ResMut<Notifications>,
) {
for _ in messages.read() {
if let Phase::Focus { .. } = &phase_res.0 {
println!(
"A minute of focus has been completed. Granting {} berries as a reward.",
config.berries_per_focus_minute
@@ -113,21 +147,6 @@ fn tick_timer(
),
);
}
if *duration <= 0.0 {
finish_writer.write(PhaseTimerFinishedMessage {
phase: phase.clone(),
});
let completed = phase.clone();
*phase = Phase::Finished {
completed_phase: Box::new(completed),
};
println!("phase ended");
savegame_messages.write(SavegameDumpMessage);
}
}
_ => {}
}
}