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