Skip to content

Commit

Permalink
Remove AddCardEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Jul 26, 2024
1 parent 961b557 commit 220d665
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 38 deletions.
Binary file modified assets/mockup/pyrious.aseprite
Binary file not shown.
11 changes: 1 addition & 10 deletions src/game/card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub mod deck;
pub mod movement;

pub(super) fn plugin(app: &mut App) {
app.configure::<(ConfigHandle<CardConfig>, AddCardEvent)>();
app.configure::<ConfigHandle<CardConfig>>();

app.add_plugins((
action::plugin,
Expand Down Expand Up @@ -185,12 +185,3 @@ fn card(key: impl Into<String>, active: bool) -> impl EntityCommand {
});
}
}

#[derive(Event)]
pub struct AddCardEvent(pub String);

impl Configure for AddCardEvent {
fn configure(app: &mut App) {
app.add_event::<Self>();
}
}
24 changes: 6 additions & 18 deletions src/game/card/deck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use serde::Serialize;

use super::CardConfig;
use crate::core::UpdateSet;
use crate::game::actor::player::IsPlayer;
use crate::game::card::card;
use crate::game::card::AddCardEvent;
use crate::game::music::beat::on_full_beat;
use crate::util::prelude::*;

Expand All @@ -28,12 +26,9 @@ impl Configure for Deck {
app.register_type::<Self>();
app.add_systems(
Update,
(
add_cards_to_deck.in_set(UpdateSet::SyncLate),
advance_deck
.in_set(UpdateSet::PlayCards)
.run_if(on_full_beat(2)),
),
play_card_from_deck
.in_set(UpdateSet::PlayCards)
.run_if(on_full_beat(2)),
);
}
}
Expand Down Expand Up @@ -78,20 +73,13 @@ impl Deck {
self.active = 0;
}
}
}

fn add_cards_to_deck(
mut add_card_events: EventReader<AddCardEvent>,
mut player_deck: Query<&mut Deck, With<IsPlayer>>,
) {
for event in add_card_events.read() {
for mut deck in &mut player_deck {
deck.card_keys.push(event.0.clone());
}
pub fn add(&mut self, card_key: impl Into<String>) {
self.card_keys.insert(self.active, card_key.into());
}
}

fn advance_deck(
fn play_card_from_deck(
mut commands: Commands,
config: ConfigRef<CardConfig>,
mut deck_query: Query<(Entity, &mut Deck)>,
Expand Down
20 changes: 10 additions & 10 deletions src/screen/playing/level_up_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,6 @@ impl Configure for LevelUpMenuAction {
}
}

fn card_discard(
deck_display_query: Query<&Selection, With<IsDeckDisplay>>,
mut deck_query: Query<&mut Deck>,
) {
for selection in &deck_display_query {
let mut deck = c!(deck_query.get_mut(selection.0));
deck.discard();
}
}

fn card_select_left(
deck_display_query: Query<&Selection, With<IsDeckDisplay>>,
mut deck_query: Query<&mut Deck>,
Expand Down Expand Up @@ -221,3 +211,13 @@ fn card_swap_right(
deck.swap(1);
}
}

fn card_discard(
deck_display_query: Query<&Selection, With<IsDeckDisplay>>,
mut deck_query: Query<&mut Deck>,
) {
for selection in &deck_display_query {
let mut deck = c!(deck_query.get_mut(selection.0));
deck.discard();
}
}

0 comments on commit 220d665

Please sign in to comment.