feat(engine): fire CardFlippedEvent + play flip sound on tableau reveal

When a move exposes a face-down tableau card, game_plugin now fires
CardFlippedEvent carrying the flipped card's id. AudioPlugin listens
and plays card_flip.wav so the reveal has satisfying audio feedback.
Two unit tests verify the event fires only when needed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
root
2026-04-27 02:48:25 +00:00
parent ed0aff4714
commit dfeaed6de2
2 changed files with 124 additions and 1 deletions
+17 -1
View File
@@ -26,7 +26,8 @@ use kira::track::{TrackBuilder, TrackHandle};
use kira::tween::Tween;
use crate::events::{
DrawRequestEvent, GameWonEvent, MoveRejectedEvent, MoveRequestEvent, NewGameRequestEvent,
CardFlippedEvent, DrawRequestEvent, GameWonEvent, MoveRejectedEvent, MoveRequestEvent,
NewGameRequestEvent,
};
use crate::settings_plugin::{SettingsChangedEvent, SettingsResource};
@@ -85,6 +86,7 @@ impl Plugin for AudioPlugin {
.add_event::<MoveRejectedEvent>()
.add_event::<NewGameRequestEvent>()
.add_event::<GameWonEvent>()
.add_event::<CardFlippedEvent>()
.add_event::<SettingsChangedEvent>()
.add_systems(
Startup,
@@ -98,6 +100,7 @@ impl Plugin for AudioPlugin {
play_on_rejected,
play_on_new_game,
play_on_win,
play_on_card_flip,
apply_volume_on_change,
),
);
@@ -240,6 +243,19 @@ fn play_on_win(
}
}
fn play_on_card_flip(
mut events: EventReader<CardFlippedEvent>,
mut audio: NonSendMut<AudioState>,
lib: Option<Res<SoundLibrary>>,
) {
let Some(lib) = lib else {
return;
};
for _ in events.read() {
play(&mut audio, &lib.flip);
}
}
#[cfg(test)]
mod tests {
use super::*;