From 57dea6b25e638c750122235c12b20c340bcd5846 Mon Sep 17 00:00:00 2001 From: Ben Frankel Date: Sat, 27 Jul 2024 17:03:43 -0700 Subject: [PATCH] Support card SFX --- assets/config/card.ron | 35 +++++++++++------- ...er_point.aseprite => major_chord.aseprite} | Bin .../{counter_point.png => major_chord.png} | Bin src/game/card.rs | 20 ++++++++++ src/game/card/deck.rs | 18 ++++++--- 5 files changed, 54 insertions(+), 19 deletions(-) rename assets/image/card/{counter_point.aseprite => major_chord.aseprite} (100%) rename assets/image/card/{counter_point.png => major_chord.png} (100%) diff --git a/assets/config/card.ron b/assets/config/card.ron index 8accc9c..30e8a5f 100644 --- a/assets/config/card.ron +++ b/assets/config/card.ron @@ -42,7 +42,7 @@ card_icon_map: { "step": CardIcon(texture: "image/card/step.png"), "double_beat": CardIcon(texture: "image/card/double_beat.png"), - "counter_point": CardIcon(texture: "image/card/counter_point.png"), + "major_chord": CardIcon(texture: "image/card/major_chord.png"), "splits": CardIcon(texture: "image/card/splits.png"), }, card_map: { @@ -51,16 +51,32 @@ description: "A-one and a-two and a-step.", background: "blue", icon: "step", + + // TODO: "Movement card" sfx. + play_sfx: "audio/sfx/Projectile Hits Enemy.ogg", action: Step, action_config: CardActionConfig( remove_on_beat: 8, ), ), + "splits": Card( + name: "Splits", + description: "Split in two!", + background: "blue", + icon: "splits", + + // TODO: "Movement card" sfx. + play_sfx: "audio/sfx/Projectile Hits Enemy.ogg", + action_config: CardActionConfig( + remove_on_beat: 16, + ), + ), "double_beat": Card( name: "Double Beat", description: "Two beats, rapid fire!", background: "pink", icon: "double_beat", + action: DoubleBeat, action_config: CardActionConfig( remove_on_beat: 4, @@ -71,21 +87,12 @@ ), ), ), - "counter_point": Card( - name: "Counter Point", + "major_chord": Card( + name: "Major Chord", description: "Notes that move apart synchronously", background: "pink", - icon: "counter_point", - action_config: CardActionConfig( - remove_on_beat: 16, - ), - ), - "splits": Card( - name: "Splits", - description: "Split in two!", - background: "blue", - icon: "splits", - modifier: 1.0, + icon: "major_chord", + action_config: CardActionConfig( remove_on_beat: 16, ), diff --git a/assets/image/card/counter_point.aseprite b/assets/image/card/major_chord.aseprite similarity index 100% rename from assets/image/card/counter_point.aseprite rename to assets/image/card/major_chord.aseprite diff --git a/assets/image/card/counter_point.png b/assets/image/card/major_chord.png similarity index 100% rename from assets/image/card/counter_point.png rename to assets/image/card/major_chord.png diff --git a/src/game/card.rs b/src/game/card.rs index 8f0d370..5bf2fbe 100644 --- a/src/game/card.rs +++ b/src/game/card.rs @@ -3,6 +3,7 @@ use bevy::ecs::system::SystemState; use bevy::prelude::*; use bevy::sprite::Anchor; use bevy::utils::HashMap; +use bevy_kira_audio::prelude::*; use serde::Deserialize; use serde::Serialize; @@ -64,6 +65,9 @@ impl Config for CardConfig { for card in self.card_map.values_mut() { card.action = *c!(card_action_map.0.get(&card.action_key)); + if !card.play_sfx_path.is_empty() { + card.play_sfx = Some(asset_server.load(&card.play_sfx_path)); + } } } @@ -75,6 +79,11 @@ impl Config for CardConfig { .card_icon_map .values() .all(|x| asset_server.is_loaded_with_dependencies(&x.texture)) + && self.card_map.values().all(|x| { + !x.play_sfx + .as_ref() + .is_some_and(|x| !asset_server.is_loaded_with_dependencies(x)) + }) } } @@ -161,6 +170,13 @@ pub struct Card { pub background_key: String, #[serde(rename = "icon")] pub icon_key: String, + + #[serde(rename = "play_sfx", default)] + play_sfx_path: String, + #[serde(skip)] + pub play_sfx: Option>, + #[serde(default = "one")] + pub play_sfx_volume: f64, #[serde(rename = "action", default)] action_key: CardActionKey, #[serde(skip)] @@ -168,6 +184,10 @@ pub struct Card { pub action_config: CardActionConfig, // TODO: Naming } +fn one() -> f64 { + 1.0 +} + pub fn card(key: impl Into, active: Option) -> impl EntityCommand { let key = key.into(); diff --git a/src/game/card/deck.rs b/src/game/card/deck.rs index 1c45434..1f22266 100644 --- a/src/game/card/deck.rs +++ b/src/game/card/deck.rs @@ -1,8 +1,10 @@ use bevy::prelude::*; +use bevy_kira_audio::prelude::*; use serde::Deserialize; use serde::Serialize; use crate::core::UpdateSet; +use crate::game::actor::faction::Faction; use crate::game::audio::music::on_full_beat; use crate::game::card::card; use crate::game::card::CardConfig; @@ -84,15 +86,21 @@ impl Deck { fn play_card_from_deck( mut commands: Commands, config: ConfigRef, - mut deck_query: Query<(Entity, &mut Deck)>, + audio: Res