Skip to content

Commit 57dea6b

Browse files
committed
Support card SFX
1 parent 7d3abaf commit 57dea6b

File tree

5 files changed

+54
-19
lines changed

5 files changed

+54
-19
lines changed

assets/config/card.ron

+21-14
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
card_icon_map: {
4343
"step": CardIcon(texture: "image/card/step.png"),
4444
"double_beat": CardIcon(texture: "image/card/double_beat.png"),
45-
"counter_point": CardIcon(texture: "image/card/counter_point.png"),
45+
"major_chord": CardIcon(texture: "image/card/major_chord.png"),
4646
"splits": CardIcon(texture: "image/card/splits.png"),
4747
},
4848
card_map: {
@@ -51,16 +51,32 @@
5151
description: "A-one and a-two and a-step.",
5252
background: "blue",
5353
icon: "step",
54+
55+
// TODO: "Movement card" sfx.
56+
play_sfx: "audio/sfx/Projectile Hits Enemy.ogg",
5457
action: Step,
5558
action_config: CardActionConfig(
5659
remove_on_beat: 8,
5760
),
5861
),
62+
"splits": Card(
63+
name: "Splits",
64+
description: "Split in two!",
65+
background: "blue",
66+
icon: "splits",
67+
68+
// TODO: "Movement card" sfx.
69+
play_sfx: "audio/sfx/Projectile Hits Enemy.ogg",
70+
action_config: CardActionConfig(
71+
remove_on_beat: 16,
72+
),
73+
),
5974
"double_beat": Card(
6075
name: "Double Beat",
6176
description: "Two beats, rapid fire!",
6277
background: "pink",
6378
icon: "double_beat",
79+
6480
action: DoubleBeat,
6581
action_config: CardActionConfig(
6682
remove_on_beat: 4,
@@ -71,21 +87,12 @@
7187
),
7288
),
7389
),
74-
"counter_point": Card(
75-
name: "Counter Point",
90+
"major_chord": Card(
91+
name: "Major Chord",
7692
description: "Notes that move apart synchronously",
7793
background: "pink",
78-
icon: "counter_point",
79-
action_config: CardActionConfig(
80-
remove_on_beat: 16,
81-
),
82-
),
83-
"splits": Card(
84-
name: "Splits",
85-
description: "Split in two!",
86-
background: "blue",
87-
icon: "splits",
88-
modifier: 1.0,
94+
icon: "major_chord",
95+
8996
action_config: CardActionConfig(
9097
remove_on_beat: 16,
9198
),
File renamed without changes.

src/game/card.rs

+20
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use bevy::ecs::system::SystemState;
33
use bevy::prelude::*;
44
use bevy::sprite::Anchor;
55
use bevy::utils::HashMap;
6+
use bevy_kira_audio::prelude::*;
67
use serde::Deserialize;
78
use serde::Serialize;
89

@@ -64,6 +65,9 @@ impl Config for CardConfig {
6465

6566
for card in self.card_map.values_mut() {
6667
card.action = *c!(card_action_map.0.get(&card.action_key));
68+
if !card.play_sfx_path.is_empty() {
69+
card.play_sfx = Some(asset_server.load(&card.play_sfx_path));
70+
}
6771
}
6872
}
6973

@@ -75,6 +79,11 @@ impl Config for CardConfig {
7579
.card_icon_map
7680
.values()
7781
.all(|x| asset_server.is_loaded_with_dependencies(&x.texture))
82+
&& self.card_map.values().all(|x| {
83+
!x.play_sfx
84+
.as_ref()
85+
.is_some_and(|x| !asset_server.is_loaded_with_dependencies(x))
86+
})
7887
}
7988
}
8089

@@ -161,13 +170,24 @@ pub struct Card {
161170
pub background_key: String,
162171
#[serde(rename = "icon")]
163172
pub icon_key: String,
173+
174+
#[serde(rename = "play_sfx", default)]
175+
play_sfx_path: String,
176+
#[serde(skip)]
177+
pub play_sfx: Option<Handle<AudioSource>>,
178+
#[serde(default = "one")]
179+
pub play_sfx_volume: f64,
164180
#[serde(rename = "action", default)]
165181
action_key: CardActionKey,
166182
#[serde(skip)]
167183
pub action: CardAction,
168184
pub action_config: CardActionConfig, // TODO: Naming
169185
}
170186

187+
fn one() -> f64 {
188+
1.0
189+
}
190+
171191
pub fn card(key: impl Into<String>, active: Option<bool>) -> impl EntityCommand {
172192
let key = key.into();
173193

src/game/card/deck.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use bevy::prelude::*;
2+
use bevy_kira_audio::prelude::*;
23
use serde::Deserialize;
34
use serde::Serialize;
45

56
use crate::core::UpdateSet;
7+
use crate::game::actor::faction::Faction;
68
use crate::game::audio::music::on_full_beat;
79
use crate::game::card::card;
810
use crate::game::card::CardConfig;
@@ -84,15 +86,21 @@ impl Deck {
8486
fn play_card_from_deck(
8587
mut commands: Commands,
8688
config: ConfigRef<CardConfig>,
87-
mut deck_query: Query<(Entity, &mut Deck)>,
89+
audio: Res<Audio>,
90+
mut deck_query: Query<(Entity, &Faction, &mut Deck)>,
8891
) {
8992
let config = r!(config.get());
9093

91-
for (entity, mut deck) in &mut deck_query {
94+
for (entity, &faction, mut deck) in &mut deck_query {
9295
let card_key = c!(deck.advance(1));
93-
let card_action = c!(config.card_map.get(card_key));
94-
let action = card_action.action;
95-
let action_config = card_action.action_config.clone();
96+
let card = c!(config.card_map.get(card_key));
97+
98+
if let (Faction::Player, Some(play_sfx)) = (faction, card.play_sfx.clone()) {
99+
audio.play(play_sfx).with_volume(card.play_sfx_volume);
100+
}
101+
102+
let action = card.action;
103+
let action_config = card.action_config.clone();
96104
commands.run_system_with_input(action.0, (entity, action_config));
97105
}
98106
}

0 commit comments

Comments
 (0)