Skip to content

Commit

Permalink
Fix missed renames (TheBevyFlock#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
janhohenheim authored Aug 9, 2024
1 parent 6617534 commit 33f50bf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
34 changes: 17 additions & 17 deletions src/audio/bgm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,53 @@ use bevy::{
use crate::assets::BgmHandles;

pub(super) fn plugin(app: &mut App) {
app.register_type::<IsSoundtrack>();
app.register_type::<IsBgm>();
}

/// Marker component for the soundtrack entity so we can find it later.
#[derive(Component, Reflect)]
#[reflect(Component)]
struct IsSoundtrack;
struct IsBgm;

/// A custom command used to play soundtracks.
#[derive(Debug)]
enum PlaySoundtrack {
enum PlayBgm {
Key(String),
Disable,
}

impl Command for PlaySoundtrack {
impl Command for PlayBgm {
/// This command will despawn the current soundtrack, then spawn a new one
/// if necessary.
fn apply(self, world: &mut World) {
world.run_system_once_with(self, play_soundtrack);
world.run_system_once_with(self, play_bgm);
}
}

fn play_soundtrack(
In(config): In<PlaySoundtrack>,
fn play_bgm(
In(config): In<PlayBgm>,
mut commands: Commands,
soundtrack_query: Query<Entity, With<IsSoundtrack>>,
soundtrack_handles: Res<BgmHandles>,
bgm_query: Query<Entity, With<IsBgm>>,
bgm_handles: Res<BgmHandles>,
) {
for entity in soundtrack_query.iter() {
for entity in bgm_query.iter() {
commands.entity(entity).despawn_recursive();
}

let soundtrack_key = match config {
PlaySoundtrack::Key(key) => key,
PlaySoundtrack::Disable => return,
let bgm_key = match config {
PlayBgm::Key(key) => key,
PlayBgm::Disable => return,
};

commands.spawn((
AudioSourceBundle {
source: soundtrack_handles[&soundtrack_key].clone_weak(),
source: bgm_handles[&bgm_key].clone_weak(),
settings: PlaybackSettings {
mode: PlaybackMode::Loop,
..default()
},
},
IsSoundtrack,
IsBgm,
));
}

Expand All @@ -69,10 +69,10 @@ pub trait BgmCommands {

impl BgmCommands for Commands<'_, '_> {
fn play_bgm(&mut self, name: impl Into<String>) {
self.add(PlaySoundtrack::Key(name.into()));
self.add(PlayBgm::Key(name.into()));
}

fn stop_bgm(&mut self) {
self.add(PlaySoundtrack::Disable);
self.add(PlayBgm::Disable);
}
}
4 changes: 2 additions & 2 deletions src/screens/credits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{assets::BgmHandles, audio::bgm::BgmCommands as _, theme::prelude::*}

pub(super) fn plugin(app: &mut App) {
app.add_systems(OnEnter(Screen::Credits), show_credits_screen);
app.add_systems(OnExit(Screen::Credits), disable_bgm);
app.add_systems(OnExit(Screen::Credits), stop_bgm);
}

fn show_credits_screen(mut commands: Commands) {
Expand All @@ -32,7 +32,7 @@ fn show_credits_screen(mut commands: Commands) {
commands.play_bgm(BgmHandles::PATH_CREDITS);
}

fn disable_bgm(mut commands: Commands) {
fn stop_bgm(mut commands: Commands) {
commands.stop_bgm();
}

Expand Down
4 changes: 2 additions & 2 deletions src/screens/playing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{assets::BgmHandles, audio::bgm::BgmCommands as _, demo::level::Spawn

pub(super) fn plugin(app: &mut App) {
app.add_systems(OnEnter(Screen::Playing), spawn_level);
app.add_systems(OnExit(Screen::Playing), disable_bgm);
app.add_systems(OnExit(Screen::Playing), stop_bgm);

app.add_systems(
Update,
Expand All @@ -21,7 +21,7 @@ fn spawn_level(mut commands: Commands) {
commands.play_bgm(BgmHandles::PATH_GAMEPLAY);
}

fn disable_bgm(mut commands: Commands) {
fn stop_bgm(mut commands: Commands) {
commands.stop_bgm();
}

Expand Down

0 comments on commit 33f50bf

Please sign in to comment.