fix: Stop granting berries for minutes passed in pause phase
This commit is contained in:
@@ -10,3 +10,6 @@ pub struct PhaseTimerPauseMessage;
|
||||
|
||||
#[derive(Message)]
|
||||
pub struct NextPhaseMessage;
|
||||
|
||||
#[derive(Message)]
|
||||
pub struct PhaseMinutePassedMessage;
|
||||
|
||||
@@ -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,30 +89,7 @@ fn tick_timer(
|
||||
let new_minutes = (*duration / 60.0).floor() as i32;
|
||||
|
||||
if new_minutes < old_minutes {
|
||||
println!(
|
||||
"A minute of focus has been completed. Granting {} berries as a reward.",
|
||||
config.berries_per_focus_minute
|
||||
);
|
||||
|
||||
inventory.update_item_stack(
|
||||
&mut commands,
|
||||
&mut items_query,
|
||||
ItemType::Berry,
|
||||
config.berries_per_focus_minute as i32,
|
||||
);
|
||||
session_tracker.total_berries_earned += config.berries_per_focus_minute;
|
||||
|
||||
let berries_name = match config.berries_per_focus_minute {
|
||||
1 => ItemType::Berry.singular(&game_config),
|
||||
_ => ItemType::Berry.plural(&game_config),
|
||||
};
|
||||
notifications.info(
|
||||
Some("Fokus Belohnung"),
|
||||
format!(
|
||||
"Du hast {} {} als Belohnung für das Abschließen einer Minute der Fokus-Phase erhalten!",
|
||||
config.berries_per_focus_minute, berries_name
|
||||
),
|
||||
);
|
||||
minute_writer.write(PhaseMinutePassedMessage);
|
||||
}
|
||||
|
||||
if *duration <= 0.0 {
|
||||
@@ -131,6 +109,47 @@ fn tick_timer(
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
);
|
||||
|
||||
inventory.update_item_stack(
|
||||
&mut commands,
|
||||
&mut items_query,
|
||||
ItemType::Berry,
|
||||
config.berries_per_focus_minute as i32,
|
||||
);
|
||||
session_tracker.total_berries_earned += config.berries_per_focus_minute;
|
||||
|
||||
let berries_name = match config.berries_per_focus_minute {
|
||||
1 => ItemType::Berry.singular(&game_config),
|
||||
_ => ItemType::Berry.plural(&game_config),
|
||||
};
|
||||
notifications.info(
|
||||
Some("Fokus Belohnung"),
|
||||
format!(
|
||||
"Du hast {} {} als Belohnung für das Abschließen einer Minute der Fokus-Phase erhalten!",
|
||||
config.berries_per_focus_minute, berries_name
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_pause(
|
||||
mut messages: MessageReader<PhaseTimerPauseMessage>,
|
||||
mut phase_res: ResMut<CurrentPhase>,
|
||||
|
||||
Reference in New Issue
Block a user