Skip to content
Snippets Groups Projects
Verified Commit dd6d1c5f authored by Louis's avatar Louis :fire:
Browse files

Update to bevy 0.10

parent 18181ce5
No related branches found
No related tags found
No related merge requests found
[package] [package]
name = "micro_musicbox" name = "micro_musicbox"
version = "0.5.1" version = "0.6.0"
edition = "2021" edition = "2021"
license = "Apache-2.0" license = "Apache-2.0"
authors = ["Louis Capitanchik <louis@microhacks.co.uk>"] authors = ["Louis Capitanchik <louis@microhacks.co.uk>"]
...@@ -19,10 +19,10 @@ wav = ["bevy_kira_audio/wav"] ...@@ -19,10 +19,10 @@ wav = ["bevy_kira_audio/wav"]
ogg = ["bevy_kira_audio/ogg"] ogg = ["bevy_kira_audio/ogg"]
[dependencies] [dependencies]
bevy = { version = "0.9.1", default-features = false } bevy = { version = "0.10.0", default-features = false }
bevy_kira_audio = { version = "0.13.0", default-features = false } bevy_kira_audio = { version = "0.15.0", default-features = false }
serde = { version = "1", optional = true } serde = { version = "1", optional = true }
[dev_dependencies] [dev_dependencies]
bevy = "0.9.1" bevy = "0.10.0"
log = "0.4" log = "0.4"
...@@ -139,5 +139,6 @@ The examples in this repository use assets available under the following license ...@@ -139,5 +139,6 @@ The examples in this repository use assets available under the following license
| musicbox version | bevy version | bka version | | musicbox version | bevy version | bka version |
|------------------|--------------|-------------| |------------------|--------------|-------------|
| 0.6 | 0.10 | 0.15 |
| 0.5 | 0.9 | 0.13 | | 0.5 | 0.9 | 0.13 |
| 0.4 | 0.8.0 | 0.12 | | 0.4 | 0.8.0 | 0.12 |
\ No newline at end of file
use bevy::prelude::*; use bevy::prelude::*;
use bevy::window::WindowResolution;
use micro_musicbox::prelude::*; use micro_musicbox::prelude::*;
use micro_musicbox::CombinedAudioPlugins; use micro_musicbox::CombinedAudioPlugins;
fn main() { fn main() {
App::new() App::new()
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
resolution: WindowResolution::new(800.0, 600.0),
title: String::from("Kitchen Sink Example"),
..Default::default()
}),
..Default::default()
}))
.add_plugins(CombinedAudioPlugins::<AssetServer>::new()) .add_plugins(CombinedAudioPlugins::<AssetServer>::new())
.add_startup_system(play_audio) .add_startup_system(play_audio)
.run(); .run();
......
...@@ -5,9 +5,8 @@ ...@@ -5,9 +5,8 @@
use std::time::Duration; use std::time::Duration;
use bevy::ecs::schedule::ShouldRun;
use bevy::prelude::*; use bevy::prelude::*;
use micro_musicbox::prelude::AudioSource; use bevy::window::WindowResolution;
use micro_musicbox::prelude::*; use micro_musicbox::prelude::*;
use micro_musicbox::CombinedAudioPlugins; use micro_musicbox::CombinedAudioPlugins;
...@@ -18,22 +17,34 @@ mod utilities; ...@@ -18,22 +17,34 @@ mod utilities;
pub fn main() { pub fn main() {
App::new() App::new()
.add_plugin(utilities::SetupPlugin) // Loads resources .add_plugin(utilities::SetupPlugin) // Loads resources
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins.set(WindowPlugin {
.add_plugins(CombinedAudioPlugins::<AssetServer>::new()) primary_window: Some(Window {
.add_system_set(SystemSet::on_enter(AppState::Running).with_system(setup_audio).with_system(set_instructions)) resolution: WindowResolution::new(800.0, 600.0),
.add_system_set(SystemSet::on_update(AppState::Running).with_run_criteria(has_music_state).with_system(cross_fade_tracks)) title: String::from("Kitchen Sink Example"),
..Default::default()
}),
..Default::default()
})) .add_plugins(CombinedAudioPlugins::<AssetServer>::new())
.add_system(
setup_audio.in_schedule(OnEnter(AppState::Running))
)
.add_system(
set_instructions.in_schedule(OnEnter(AppState::Running))
)
.add_system(cross_fade_tracks.run_if(resource_exists::<MusicState>()))
.run(); .run();
} }
/// A resource that we'll use to keep track of which track is currently the active one, for fading /// A resource that we'll use to keep track of which track is currently the active one, for fading
/// in and out /// in and out
#[derive(Resource)]
pub struct MusicState { pub struct MusicState {
pub playing_first: bool, pub playing_first: bool,
} }
pub fn has_music_state(state: Option<Res<MusicState>>) -> ShouldRun { // pub fn has_music_state(state: Option<Res<MusicState>>) -> ShouldRun {
state.is_some().into() // state.is_some().into()
} // }
pub fn set_instructions( pub fn set_instructions(
mut instructions: Query<&mut Text, (With<TextMarker>, Without<DetailsMarker>)>, mut instructions: Query<&mut Text, (With<TextMarker>, Without<DetailsMarker>)>,
......
use bevy::app::Plugin; use bevy::app::Plugin;
use bevy::asset::{Handle, LoadState}; use bevy::asset::{Handle, LoadState};
use bevy::ecs::schedule::ShouldRun;
use bevy::prelude::*; use bevy::prelude::*;
use bevy_kira_audio::AudioSource; use bevy_kira_audio::AudioSource;
/// We store our asset handles in this to avoid Bevy from dropping the assets and reloading /// We store our asset handles in this to avoid Bevy from dropping the assets and reloading
/// when we switch tracks /// when we switch tracks
#[derive(Resource)]
pub struct AudioResources { pub struct AudioResources {
pub white_kitty: Handle<AudioSource>, pub white_kitty: Handle<AudioSource>,
pub great_madeja: Handle<AudioSource>, pub great_madeja: Handle<AudioSource>,
} }
#[derive(Default, Eq, PartialEq, Debug, Clone, Hash)] #[derive(Default, Eq, PartialEq, Debug, Clone, Hash, States)]
pub enum AppState { pub enum AppState {
#[default] #[default]
Loading, Loading,
...@@ -31,14 +31,18 @@ pub fn load_resources(mut commands: Commands, assets: Res<AssetServer>) { ...@@ -31,14 +31,18 @@ pub fn load_resources(mut commands: Commands, assets: Res<AssetServer>) {
pub fn check_load_state( pub fn check_load_state(
assets: Res<AssetServer>, assets: Res<AssetServer>,
resources: Res<AudioResources>, resources: Res<AudioResources>,
mut appstate: ResMut<State<AppState>>, appstate: Res<State<AppState>>,
mut next_state: ResMut<NextState<AppState>>,
) { ) {
let load_state = let load_state = assets.get_group_load_state(vec![
assets.get_group_load_state(vec![resources.white_kitty.id, resources.great_madeja.id]); resources.white_kitty.id(),
resources.great_madeja.id(),
]);
match load_state { match load_state {
LoadState::Loaded => { LoadState::Loaded => {
appstate.set(AppState::Running); log::info!("STATE {:?}", appstate);
*next_state = NextState(Some(AppState::Running)); // appstate.set(AppState::Running);
} }
LoadState::Loading => {} LoadState::Loading => {}
_ => { _ => {
...@@ -47,15 +51,15 @@ pub fn check_load_state( ...@@ -47,15 +51,15 @@ pub fn check_load_state(
} }
} }
pub fn has_audio_resources(res: Option<Res<AudioResources>>) -> ShouldRun { // pub fn has_audio_resources(res: Option<Res<AudioResources>>) -> ShouldRun {
res.is_some().into() // res.is_some().into()
} // }
pub fn is_state_loading(state: Res<AppState>) -> ShouldRun { // pub fn is_state_loading(state: Res<AppState>) -> ShouldRun {
(*state == AppState::Loading).into() // (*state == AppState::Loading).into()
} // }
pub fn is_state_running(state: Res<AppState>) -> ShouldRun { // pub fn is_state_running(state: Res<AppState>) -> ShouldRun {
(*state == AppState::Running).into() // (*state == AppState::Running).into()
} // }
/// This component allows us to easily grab the on screen text /// This component allows us to easily grab the on screen text
#[derive(Component)] #[derive(Component)]
...@@ -65,9 +69,9 @@ pub struct TextMarker; ...@@ -65,9 +69,9 @@ pub struct TextMarker;
pub struct DetailsMarker; pub struct DetailsMarker;
pub fn create_ui(mut commands: Commands, assets: Res<AssetServer>) { pub fn create_ui(mut commands: Commands, assets: Res<AssetServer>) {
commands.spawn_bundle(Camera2dBundle::default()); commands.spawn(Camera2dBundle::default());
commands commands
.spawn_bundle(NodeBundle { .spawn(NodeBundle {
style: Style { style: Style {
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)), size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
justify_content: JustifyContent::Center, justify_content: JustifyContent::Center,
...@@ -79,7 +83,7 @@ pub fn create_ui(mut commands: Commands, assets: Res<AssetServer>) { ...@@ -79,7 +83,7 @@ pub fn create_ui(mut commands: Commands, assets: Res<AssetServer>) {
}) })
.with_children(|children| { .with_children(|children| {
children children
.spawn_bundle(TextBundle { .spawn(TextBundle {
text: Text::from_section( text: Text::from_section(
"Loading Audio Tracks", "Loading Audio Tracks",
TextStyle { TextStyle {
...@@ -92,7 +96,7 @@ pub fn create_ui(mut commands: Commands, assets: Res<AssetServer>) { ...@@ -92,7 +96,7 @@ pub fn create_ui(mut commands: Commands, assets: Res<AssetServer>) {
}) })
.insert(TextMarker); .insert(TextMarker);
children children
.spawn_bundle(TextBundle { .spawn(TextBundle {
text: Text::from_section( text: Text::from_section(
"...", "...",
TextStyle { TextStyle {
...@@ -110,19 +114,13 @@ pub fn create_ui(mut commands: Commands, assets: Res<AssetServer>) { ...@@ -110,19 +114,13 @@ pub fn create_ui(mut commands: Commands, assets: Res<AssetServer>) {
pub struct SetupPlugin; pub struct SetupPlugin;
impl Plugin for SetupPlugin { impl Plugin for SetupPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_state(AppState::Loading) app.add_state::<AppState>()
.insert_resource(WindowDescriptor {
width: 800.0,
height: 600.0,
title: String::from("Kitchen Sink Example"),
..Default::default()
})
.add_startup_system(load_resources) .add_startup_system(load_resources)
.add_startup_system(create_ui) .add_startup_system(create_ui)
.add_system_set( .add_system(
SystemSet::on_update(AppState::Loading) check_load_state
.with_run_criteria(has_audio_resources) .run_if(resource_exists::<AudioResources>())
.with_system(check_load_state), .run_if(in_state(AppState::Loading)),
); );
} }
} }
...@@ -25,7 +25,8 @@ ...@@ -25,7 +25,8 @@
use std::marker::PhantomData; use std::marker::PhantomData;
use bevy::app::{App, CoreStage, Plugin, PluginGroup, PluginGroupBuilder}; use bevy::app::{App, CoreSet, Plugin, PluginGroup, PluginGroupBuilder};
use bevy::prelude::{IntoSystemConfig, SystemSet};
use bevy_kira_audio::{AudioApp, AudioPlugin}; use bevy_kira_audio::{AudioApp, AudioPlugin};
use crate::channels::{ use crate::channels::{
...@@ -81,7 +82,7 @@ impl<T: SuppliesAudio> Plugin for MusicBoxPlugin<T> { ...@@ -81,7 +82,7 @@ impl<T: SuppliesAudio> Plugin for MusicBoxPlugin<T> {
.add_audio_channel::<UiSfxAudioChannel>() .add_audio_channel::<UiSfxAudioChannel>()
.insert_resource(AudioSettings::default()) .insert_resource(AudioSettings::default())
.insert_resource(MusicBoxState::default()) .insert_resource(MusicBoxState::default())
.add_system_to_stage(CoreStage::Last, utilities::sync_music_volume::<T>); .add_system(utilities::sync_music_volume::<T>.in_base_set(CoreSet::Last));
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment