Merge branch '54-sessiontracker-updates-too-late' into 'dev'

SessionTracker Update Fix

See merge request softwaregrundprojekt/2025-2026/einzelprojekt/tutorium-moritz/bernroider-dominik/bernroider-dominik!42
This commit is contained in:
Dominik Bernroider
2025-12-10 19:04:42 +00:00
2 changed files with 21 additions and 16 deletions

View File

@@ -135,6 +135,7 @@ fn grant_focus_rewards(
berries as i32,
);
session_tracker.total_berries_earned += berries;
session_tracker.completed_focus_phases += 1;
let berries_name = match berries {
1 => ItemType::Berry.singular(&game_config),
@@ -179,14 +180,12 @@ fn handle_pause(
/// Transitions to the next phase based on current state.
pub fn next_phase(
current_phase: &mut CurrentPhase,
session_tracker: &mut SessionTracker,
session_tracker: &SessionTracker,
settings: &TimerSettings,
) {
if let Phase::Finished { completed_phase } = &current_phase.0 {
match **completed_phase {
Phase::Focus { .. } => {
session_tracker.completed_focus_phases += 1;
let is_long_break = session_tracker.completed_focus_phases > 0
&& session_tracker.completed_focus_phases % settings.long_break_interval == 0;
@@ -214,7 +213,7 @@ pub fn next_phase(
pub fn handle_continue(
mut messages: MessageReader<NextPhaseMessage>,
mut phase_res: ResMut<CurrentPhase>,
mut session_tracker: ResMut<SessionTracker>,
session_tracker: Res<SessionTracker>,
settings: Res<TimerSettings>,
mut tile_query: Query<&mut TileState>,
game_config: Res<GameConfig>,
@@ -226,7 +225,7 @@ pub fn handle_continue(
false
};
next_phase(&mut phase_res, &mut session_tracker, &settings);
next_phase(&mut phase_res, &session_tracker, &settings);
if entering_break {
println!("Growing crops and resetting watered state.");

View File

@@ -11,9 +11,13 @@ fn test_session_tracker_focus_to_short_break() {
}),
});
let timer_settings = TimerSettings::default();
let mut session_tracker = SessionTracker::default();
// Simulate that grant_focus_rewards has already incremented the counter
let session_tracker = SessionTracker {
completed_focus_phases: 1,
total_berries_earned: 0,
};
next_phase(&mut current_phase, &mut session_tracker, &timer_settings);
next_phase(&mut current_phase, &session_tracker, &timer_settings);
assert_eq!(
session_tracker.completed_focus_phases, 1,
@@ -37,16 +41,17 @@ fn test_session_tracker_focus_to_long_break() {
}),
});
let timer_settings = TimerSettings::default();
let mut session_tracker = SessionTracker {
completed_focus_phases: timer_settings.long_break_interval - 1,
// Simulate that grant_focus_rewards has already incremented the counter to the interval
let session_tracker = SessionTracker {
completed_focus_phases: timer_settings.long_break_interval,
total_berries_earned: 0,
}; // To trigger long break on next phase
};
next_phase(&mut current_phase, &mut session_tracker, &timer_settings);
next_phase(&mut current_phase, &session_tracker, &timer_settings);
assert_eq!(
session_tracker.completed_focus_phases, timer_settings.long_break_interval,
"Completed focus phases should reach long break interval"
"Completed focus phases should remain at long break interval"
);
if let Phase::Break { duration } = current_phase.0 {
assert_eq!(
@@ -65,13 +70,13 @@ fn test_session_tracker_break_to_focus() {
duration: 5.0 * 60.0,
}),
});
let mut session_tracker = SessionTracker {
let session_tracker = SessionTracker {
completed_focus_phases: 1,
total_berries_earned: 0,
}; // Arbitrary value, should not change
let timer_settings = TimerSettings::default();
next_phase(&mut current_phase, &mut session_tracker, &timer_settings);
next_phase(&mut current_phase, &session_tracker, &timer_settings);
assert_eq!(
session_tracker.completed_focus_phases, 1,
@@ -91,7 +96,7 @@ fn test_session_tracker_break_to_focus() {
fn test_session_tracker_not_finished_phase_no_change() {
// Test that nothing changes if the phase is not `Finished`
let mut current_phase = CurrentPhase(Phase::Focus { duration: 100.0 });
let mut session_tracker = SessionTracker {
let session_tracker = SessionTracker {
completed_focus_phases: 0,
total_berries_earned: 0,
};
@@ -100,7 +105,7 @@ fn test_session_tracker_not_finished_phase_no_change() {
let initial_phase = current_phase.0.clone();
let initial_completed_focus = session_tracker.completed_focus_phases;
next_phase(&mut current_phase, &mut session_tracker, &timer_settings);
next_phase(&mut current_phase, &session_tracker, &timer_settings);
assert_eq!(
current_phase.0, initial_phase,
@@ -111,3 +116,4 @@ fn test_session_tracker_not_finished_phase_no_change() {
"Session tracker should not change if phase not Finished"
);
}