fix: Grant focus reward berries at the end of the focus phase
This commit is contained in:
@@ -10,6 +10,3 @@ pub struct PhaseTimerPauseMessage;
|
|||||||
|
|
||||||
#[derive(Message)]
|
#[derive(Message)]
|
||||||
pub struct NextPhaseMessage;
|
pub struct NextPhaseMessage;
|
||||||
|
|
||||||
#[derive(Message)]
|
|
||||||
pub struct PhaseMinutePassedMessage;
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ impl Plugin for PhasePlugin {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
app.add_message::<PhaseTimerFinishedMessage>();
|
app.add_message::<PhaseTimerFinishedMessage>();
|
||||||
app.add_message::<PhaseMinutePassedMessage>();
|
|
||||||
|
|
||||||
app.add_systems(OnEnter(AppState::GameScreen), load_rules);
|
app.add_systems(OnEnter(AppState::GameScreen), load_rules);
|
||||||
app.add_systems(
|
app.add_systems(
|
||||||
@@ -76,7 +75,6 @@ fn tick_timer(
|
|||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
mut phase_res: ResMut<CurrentPhase>,
|
mut phase_res: ResMut<CurrentPhase>,
|
||||||
mut finish_writer: MessageWriter<PhaseTimerFinishedMessage>,
|
mut finish_writer: MessageWriter<PhaseTimerFinishedMessage>,
|
||||||
mut minute_writer: MessageWriter<PhaseMinutePassedMessage>,
|
|
||||||
mut savegame_messages: MessageWriter<SavegameDumpMessage>,
|
mut savegame_messages: MessageWriter<SavegameDumpMessage>,
|
||||||
) {
|
) {
|
||||||
let delta = time.delta_secs();
|
let delta = time.delta_secs();
|
||||||
@@ -84,13 +82,7 @@ fn tick_timer(
|
|||||||
|
|
||||||
match phase {
|
match phase {
|
||||||
Phase::Focus { duration } | Phase::Break { duration } => {
|
Phase::Focus { duration } | Phase::Break { duration } => {
|
||||||
let old_minutes = (*duration / 60.0).floor() as i32;
|
|
||||||
*duration -= delta;
|
*duration -= delta;
|
||||||
let new_minutes = (*duration / 60.0).floor() as i32;
|
|
||||||
|
|
||||||
if new_minutes < old_minutes {
|
|
||||||
minute_writer.write(PhaseMinutePassedMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
if *duration <= 0.0 {
|
if *duration <= 0.0 {
|
||||||
finish_writer.write(PhaseTimerFinishedMessage {
|
finish_writer.write(PhaseTimerFinishedMessage {
|
||||||
@@ -110,8 +102,7 @@ fn tick_timer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn grant_focus_rewards(
|
fn grant_focus_rewards(
|
||||||
mut messages: MessageReader<PhaseMinutePassedMessage>,
|
mut messages: MessageReader<PhaseTimerFinishedMessage>,
|
||||||
phase_res: Res<CurrentPhase>,
|
|
||||||
config: Res<GameConfig>,
|
config: Res<GameConfig>,
|
||||||
mut inventory: ResMut<Inventory>,
|
mut inventory: ResMut<Inventory>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
@@ -119,31 +110,30 @@ fn grant_focus_rewards(
|
|||||||
mut session_tracker: ResMut<SessionTracker>,
|
mut session_tracker: ResMut<SessionTracker>,
|
||||||
game_config: Res<GameConfig>,
|
game_config: Res<GameConfig>,
|
||||||
mut notifications: ResMut<Notifications>,
|
mut notifications: ResMut<Notifications>,
|
||||||
|
timer_settings: Res<TimerSettings>,
|
||||||
) {
|
) {
|
||||||
for _ in messages.read() {
|
for message in messages.read() {
|
||||||
if let Phase::Focus { .. } = &phase_res.0 {
|
if matches!(message.phase, Phase::Focus { .. }) {
|
||||||
println!(
|
let berries = config.berries_per_focus_minute
|
||||||
"A minute of focus has been completed. Granting {} berries as a reward.",
|
* (timer_settings.focus_duration as f32 / 60.0).floor() as u32;
|
||||||
config.berries_per_focus_minute
|
|
||||||
);
|
|
||||||
|
|
||||||
inventory.update_item_stack(
|
inventory.update_item_stack(
|
||||||
&mut commands,
|
&mut commands,
|
||||||
&mut items_query,
|
&mut items_query,
|
||||||
ItemType::Berry,
|
ItemType::Berry,
|
||||||
config.berries_per_focus_minute as i32,
|
berries as i32,
|
||||||
);
|
);
|
||||||
session_tracker.total_berries_earned += config.berries_per_focus_minute;
|
session_tracker.total_berries_earned += berries;
|
||||||
|
|
||||||
let berries_name = match config.berries_per_focus_minute {
|
let berries_name = match berries {
|
||||||
1 => ItemType::Berry.singular(&game_config),
|
1 => ItemType::Berry.singular(&game_config),
|
||||||
_ => ItemType::Berry.plural(&game_config),
|
_ => ItemType::Berry.plural(&game_config),
|
||||||
};
|
};
|
||||||
notifications.info(
|
notifications.info(
|
||||||
Some("Fokus Belohnung"),
|
Some("Fokus Belohnung"),
|
||||||
format!(
|
format!(
|
||||||
"Du hast {} {} als Belohnung für das Abschließen einer Minute der Fokus-Phase erhalten!",
|
"Du hast {} {} als Belohnung für das Abschließen einer Fokus-Phase erhalten!",
|
||||||
config.berries_per_focus_minute, berries_name
|
berries, berries_name
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user