1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//! Bevy Retrograde audio plugin
//!
//! Bevy Retrograde attempts to provide an _extremely_ simple, yet still effective API for playing audio
//! in games using [Kira]. If more control is desired you may want to look into [`bevy_kira_audio`]
//! which grants more control over audio playback.
//!
//! [`bevy_kira_audio`]: https://github.com/NiklasEi/bevy_kira_audio
//!
//! [Kira]: https://docs.rs/kira

use bevy::prelude::*;

pub use kira;

mod assets;
pub use assets::*;

mod components;
pub use components::*;

mod systems;
pub(crate) use systems::*;

/// Bevy Retrograde audio plugin
#[derive(Default)]
pub struct RetroAudioPlugin;

impl Plugin for RetroAudioPlugin {
    fn build(&self, app: &mut AppBuilder) {
        app
            // Add audio manager resource
            .insert_non_send_resource(AudioManager::default())
            .add_event::<SoundEvent>();

        // Add asssets and systems
        add_assets(app);
        add_systems(app);
    }
}

pub use events::*;
mod events {
    use super::*;

    /// A sound event used to control the sound playback system
    #[doc(hidden)]
    #[derive(Debug, Clone)]
    #[allow(clippy::large_enum_variant)]
    pub enum SoundEvent {
        CreateSound(Handle<SoundData>, Sound),
        PlaySound(Sound, PlaySoundSettings),
        PauseSound(Sound, PauseSoundSettings),
        ResumeSound(Sound, ResumeSoundSettings),
        StopSound(Sound, StopSoundSettings),
    }
}