Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on bevy_audio feature #88

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ license = "MIT OR Apache-2.0"

[dependencies]
anyhow = "1.0"
bevy = { version = "0.14", default-features = false, features = ["bevy_audio"] }
bevy = { version = "0.14", default-features = false }
bevy_mod_sysfail = "3.0"
libfmod = "~2.206.2"

[dev-dependencies]
# The examples need the default features of bevy
bevy = { version = "0.14", default-features = true }
[dev-dependencies.bevy]
version = "0.14"
features = [
"bevy_core_pipeline",
"bevy_render",
"bevy_winit",
"multi_threaded"
]

[features]
default = []
Expand Down
30 changes: 19 additions & 11 deletions src/components/audio_source.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bevy::math::Vec3;
use bevy::prelude::{AudioSinkPlayback, Component, GlobalTransform, Query};
use bevy::prelude::{Component, GlobalTransform, Query};
use libfmod::StopMode::Immediate;
use libfmod::{EventDescription, EventInstance, StopMode};

Expand Down Expand Up @@ -44,46 +44,54 @@ impl AudioSource {
}
}

impl AudioSinkPlayback for AudioSource {
fn volume(&self) -> f32 {
impl AudioSource {
pub fn volume(&self) -> f32 {
self.event_instance.get_volume().unwrap().0
}

fn set_volume(&self, volume: f32) {
pub fn set_volume(&self, volume: f32) {
self.event_instance.set_volume(volume).unwrap();
}

fn speed(&self) -> f32 {
pub fn speed(&self) -> f32 {
self.event_instance.get_pitch().unwrap().0
}

fn set_speed(&self, speed: f32) {
pub fn set_speed(&self, speed: f32) {
self.event_instance.set_pitch(speed).unwrap();
}

fn play(&self) {
pub fn play(&self) {
if self.event_instance.get_paused().unwrap() {
self.event_instance.set_paused(false).unwrap();
} else {
self.event_instance.start().unwrap();
}
}

fn pause(&self) {
pub fn pause(&self) {
self.event_instance.set_paused(true).unwrap();
}

fn is_paused(&self) -> bool {
pub fn is_paused(&self) -> bool {
self.event_instance.get_paused().unwrap()
}

fn stop(&self) {
pub fn stop(&self) {
self.event_instance.stop(StopMode::AllowFadeout).unwrap();
}

fn empty(&self) -> bool {
pub fn empty(&self) -> bool {
self.event_instance.is_valid()
}

pub fn toggle(&self) {
if self.is_paused() {
self.play();
} else {
self.pause();
}
}
}

impl Drop for AudioSource {
Expand Down