Skip to content

Commit

Permalink
Fix level up menu after victory menu
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Jul 28, 2024
1 parent b30bff0 commit 354f9d0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 29 deletions.
16 changes: 13 additions & 3 deletions src/game/actor/level/up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::core::UpdateSet;
use crate::game::actor::level::xp::Xp;
use crate::game::actor::level::Level;
use crate::game::actor::level::LevelConfig;
use crate::screen::playing::victory_menu::EndlessMode;
use crate::screen::playing::PlayingAssets;
use crate::screen::playing::PlayingMenu;
use crate::util::prelude::*;
Expand Down Expand Up @@ -62,15 +63,24 @@ fn update_level_up_from_xp(
fn trigger_level_up(
mut level_up_events: EventWriter<LevelUp>,
mut level_query: Query<(Entity, &mut Level)>,
endless_mode: Res<EndlessMode>,
mut playing_menu: NextMut<PlayingMenu>,
audio: Res<Audio>,
assets: Res<PlayingAssets>,
) {
for (entity, mut level) in &mut level_query {
if level.up == 0 {
continue;
}

level.up -= 1;
level.current += 1;
level_up_events.send(LevelUp(entity));
if !endless_mode.0 && level.current + 1 == 10 {
playing_menu.enter(PlayingMenu::Victory);
audio.play(assets.sfx_level_up.clone()).with_volume(0.8);
} else {
level.up -= 1;
level.current += 1;
level_up_events.send(LevelUp(entity));
}
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/screen/playing/level_up_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use crate::game::card::card;
use crate::game::card::deck::Deck;
use crate::game::card::deck::IsDeckDisplay;
use crate::game::card::CardConfig;
use crate::screen::playing::victory_menu::detect_victory;
use crate::screen::playing::PlayingAssets;
use crate::screen::playing::PlayingMenu;
use crate::ui::prelude::*;
Expand All @@ -33,7 +32,7 @@ pub(super) fn plugin(app: &mut App) {
PlayingMenu::LevelUp
.enter()
.in_set(UpdateSet::SyncLate)
.run_if(on_event::<LevelUp>().and_then(not(detect_victory))),
.run_if(on_event::<LevelUp>()),
);

app.configure::<(LevelUpMenuAction, ToggleDisplay)>();
Expand Down
25 changes: 1 addition & 24 deletions src/screen/playing/victory_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ use pyri_state::extra::entity_scope::StateScope;
use pyri_state::prelude::*;

use crate::core::pause::Pause;
use crate::core::UpdateSet;
use crate::game::actor::level::up::LevelUp;
use crate::game::actor::level::IsLevelDisplay;
use crate::game::actor::level::Level;
use crate::game::stats::Stats;
use crate::screen::fade_out;
use crate::screen::playing::PlayingAssets;
Expand All @@ -24,30 +20,11 @@ pub(super) fn plugin(app: &mut App) {
);

app.configure::<EndlessMode>();

app.add_systems(
Update,
PlayingMenu::Victory
.enter()
.in_set(UpdateSet::SyncLate)
.run_if(on_event::<LevelUp>().and_then(detect_victory)),
);
}

pub fn detect_victory(
level_display_query: Query<&Selection, With<IsLevelDisplay>>,
level_query: Query<&Level>,
endless_mode: Res<EndlessMode>,
) -> bool {
let selection = r!(false, level_display_query.get_single());
let level = r!(false, level_query.get(selection.0));

!endless_mode.0 && level.current >= 10
}

#[derive(Resource, Reflect, Default)]
#[reflect(Resource)]
pub struct EndlessMode(bool);
pub struct EndlessMode(pub bool);

impl Configure for EndlessMode {
fn configure(app: &mut App) {
Expand Down

0 comments on commit 354f9d0

Please sign in to comment.