diff --git a/Cargo.toml b/Cargo.toml index c2f77da..1badcb8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,12 +10,11 @@ repository = "https://labs.lightsout.games/projects/bevy_synthizer" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -anyhow = "1" -bevy = { version = "0.11", default-features = false, features = ["bevy_asset"] } +bevy = { version = "0.12", default-features = false, features = ["bevy_asset"] } synthizer = "0.5.6" [dev-dependencies] -bevy = { version = "0.11", default-features = true } +bevy = { version = "0.12", default-features = true } [package.metadata.release] publish = false diff --git a/examples/buffer.rs b/examples/buffer.rs index 5580cc8..3021fa2 100644 --- a/examples/buffer.rs +++ b/examples/buffer.rs @@ -1,6 +1,6 @@ use std::f32; -use bevy::{asset::LoadState, prelude::*}; +use bevy::{asset::LoadedFolder, prelude::*}; use bevy_synthizer::*; #[derive(Component, Deref, DerefMut)] @@ -12,45 +12,40 @@ impl Default for RotationTimer { } } -#[derive(Resource, Default)] -struct AssetHandles { - sounds: Vec, - loaded: bool, -} +#[derive(Resource, Default, Deref, DerefMut)] +struct AssetHandles(Handle); fn setup(asset_server: Res, mut handles: ResMut) { - handles.sounds = asset_server.load_folder(".").expect("Failed to load sfx"); + **handles = asset_server.load_folder("."); } fn load_and_create( mut commands: Commands, asset_server: Res, - mut handles: ResMut, + handles: Res, + listeners: Query<&Listener>, ) { - if handles.loaded { + if !asset_server.is_loaded_with_dependencies(&**handles) { return; } - handles.loaded = asset_server - .get_group_load_state(handles.sounds.iter().map(|handle| handle.id())) - == LoadState::Loaded; - if handles.loaded { - commands.spawn(( - TransformBundle::default(), - Listener, - RotationTimer::default(), - )); - let handle = handles.sounds[0].clone(); - let buffer = asset_server.get_handle(handle); - commands.spawn(( - TransformBundle::from(Transform::from_translation(Vec3::new(10., 0., 0.))), - Source::default(), - Sound { - audio: buffer.into(), - looping: true, - ..default() - }, - )); + if !listeners.is_empty() { + return; } + commands.spawn(( + TransformBundle::default(), + Listener, + RotationTimer::default(), + )); + let handle = asset_server.load("footstep.wav"); + commands.spawn(( + TransformBundle::from(Transform::from_translation(Vec3::new(10., 0., 0.))), + Source::default(), + Sound { + audio: handle.into(), + looping: true, + ..default() + }, + )); } fn rotate_listener(time: Res