Skip to content

Commit

Permalink
Merge pull request #133 from NiklasEi/bevy-0-15
Browse files Browse the repository at this point in the history
Update to bevy 0.15
  • Loading branch information
NiklasEi authored Nov 30, 2024
2 parents 9b35b7c + 3a60c31 commit e029b4c
Show file tree
Hide file tree
Showing 14 changed files with 192 additions and 220 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v0.21.0 - 30.11.2024
- Update to Bevy `0.15`

## v0.20.0 - 04.07.2024
- Update to Bevy `0.14`
- Asset loaders are now public
Expand Down
45 changes: 31 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_kira_audio"
version = "0.20.0"
version = "0.21.0"
authors = ["Niklas Eicker <[email protected]>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand All @@ -22,34 +22,51 @@ wav = ["kira/wav"]
settings_loader = ["dep:ron", "dep:serde", "kira/serde"]

[dependencies]
bevy = { version = "0.14.0", default-features = false, features = ["bevy_asset"] }
bevy = { version = "0.15.0", default-features = false, features = ["bevy_asset"] }
anyhow = "1.0"
uuid = { version = "1", features = ["fast-rng"] }
kira = { version = "0.8", default-features = false, features = ["cpal"] }
kira = { version = "0.8.7", default-features = false, features = ["cpal"] }
ron = { version = "0.8", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
parking_lot = "0.12"
thiserror = "1.0"

[dev-dependencies.bevy]
version = "0.14.0"
version = "0.15.0"
default-features = false
# default features minus "bevy_audio" and "vorbis"
features = [
"android-game-activity",
"animation",
"bevy_asset",
"bevy_winit",
"bevy_render",
"x11",
"bevy_ui",
"bevy_text",
"bevy_color",
"bevy_core_pipeline",
"bevy_sprite",
"bevy_gilrs",
"bevy_gizmos",
"bevy_gltf",
"bevy_scene",
"bevy_mesh_picking_backend",
"bevy_pbr",
"bevy_picking",
"bevy_render",
"bevy_scene",
"bevy_sprite",
"bevy_sprite_picking_backend",
"bevy_state",
"bevy_text",
"bevy_ui",
"bevy_ui_picking_backend",
"bevy_window",
"bevy_winit",
"custom_cursor",
"default_font",
"hdr",
"multi_threaded",
"png",
"smaa_luts",
"sysinfo_plugin",
"tonemapping_luts",
"ktx2",
"zstd",
"multi_threaded"
"webgl2",
"x11",
]

[[example]]
Expand Down
11 changes: 10 additions & 1 deletion examples/channel_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@ fn channel_control(input: Res<ButtonInput<MouseButton>>, audio: Res<Audio>) {
}
}

fn play_loop(asset_server: Res<AssetServer>, audio: Res<Audio>) {
fn play_loop(mut commands: Commands, asset_server: Res<AssetServer>, audio: Res<Audio>) {
audio.play(asset_server.load("sounds/loop.ogg")).looped();
audio.play(asset_server.load("sounds/sound.ogg"));
commands.spawn(Camera2d);
commands.spawn(Text::new(
r#"
This example demonstrates how to control an audio channel
The audio commands have 2s linear fade in/out
Left-click to pause the audio
Right-click to resume the audio"#,
));
}
7 changes: 7 additions & 0 deletions examples/instance_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,11 @@ fn play_loop(mut commands: Commands, asset_server: Res<AssetServer>, audio: Res<
.looped()
.handle();
commands.insert_resource(InstanceHandle(handle));
commands.spawn(Camera2d);
commands.spawn(Text::new(
r#"
This example demonstrates how to control a single audio instance
Left-click to toggle the audio"#,
));
}
111 changes: 46 additions & 65 deletions examples/multiple_channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ fn play_pause_button<T: Component + Default>(
mut channel_state: ResMut<ChannelAudioState<T>>,
time: Res<Time>,
mut last_action: ResMut<LastAction>,
mut interaction_query: Query<(&Interaction, &mut UiImage), With<PlayPauseButton<T>>>,
mut play_pause_text: Query<&mut Text, With<PlayPauseButton<T>>>,
mut interaction_query: Query<(&Interaction, &mut ImageNode), With<PlayPauseButton<T>>>,
mut play_pause_text: Query<&mut TextSpan, With<PlayPauseButton<T>>>,
) {
let (interaction, mut image) = interaction_query.single_mut();
image.color = if channel_state.stopped {
Expand All @@ -48,7 +48,7 @@ fn play_pause_button<T: Component + Default>(
NORMAL_BUTTON
};
let mut text = play_pause_text.single_mut();
text.sections.first_mut().unwrap().value = if channel_state.paused {
text.0 = if channel_state.paused {
"Play".to_owned()
} else {
"Pause".to_owned()
Expand All @@ -74,7 +74,7 @@ fn stop_button<T: Component + Default>(
time: Res<Time>,
mut last_action: ResMut<LastAction>,
mut channel_state: ResMut<ChannelAudioState<T>>,
mut interaction_query: Query<(&Interaction, &mut UiImage), With<StopButton<T>>>,
mut interaction_query: Query<(&Interaction, &mut ImageNode), With<StopButton<T>>>,
) {
let (interaction, mut image) = interaction_query.single_mut();
image.color = if channel_state.stopped {
Expand Down Expand Up @@ -102,7 +102,7 @@ fn loop_button<T: Component + Default>(
mut last_action: ResMut<LastAction>,
mut channel_state: ResMut<ChannelAudioState<T>>,
audio_handles: Res<AudioHandles>,
mut interaction_query: Query<(&Interaction, &mut UiImage), With<StartLoopButton<T>>>,
mut interaction_query: Query<(&Interaction, &mut ImageNode), With<StartLoopButton<T>>>,
) {
let (interaction, mut image) = interaction_query.single_mut();
image.color = if !channel_state.loop_started {
Expand Down Expand Up @@ -133,7 +133,7 @@ fn play_sound_button<T: Component + Default>(
mut last_action: ResMut<LastAction>,
mut channel_state: ResMut<ChannelAudioState<T>>,
audio_handles: Res<AudioHandles>,
mut interaction_query: Query<(&Interaction, &mut UiImage), With<PlaySoundButton<T>>>,
mut interaction_query: Query<(&Interaction, &mut ImageNode), With<PlaySoundButton<T>>>,
) {
let (interaction, mut image) = interaction_query.single_mut();
image.color = if interaction == &Interaction::Hovered {
Expand All @@ -156,7 +156,7 @@ fn volume_buttons<T: Component + Default>(
time: Res<Time>,
mut last_action: ResMut<LastAction>,
mut channel_state: ResMut<ChannelAudioState<T>>,
mut interaction_query: Query<(&Interaction, &mut UiImage, &ChangeVolumeButton<T>)>,
mut interaction_query: Query<(&Interaction, &mut ImageNode, &ChangeVolumeButton<T>)>,
) {
for (interaction, mut image, volume) in &mut interaction_query {
image.color = if interaction == &Interaction::Hovered {
Expand All @@ -183,10 +183,10 @@ struct LastAction(f64);

impl LastAction {
fn action(&mut self, time: &Time) -> bool {
if time.elapsed_seconds_f64() - self.0 < 0.2 {
if time.elapsed_secs_f64() - self.0 < 0.2 {
return false;
}
self.0 = time.elapsed_seconds_f64();
self.0 = time.elapsed_secs_f64();

true
}
Expand Down Expand Up @@ -273,16 +273,13 @@ fn prepare_audio_and_ui(mut commands: Commands, asset_server: ResMut<AssetServer

fn set_up_ui(commands: &mut Commands, asset_server: ResMut<AssetServer>) {
let font = asset_server.load("fonts/monogram.ttf");
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
commands
.spawn(NodeBundle {
style: Style {
display: Display::Flex,
flex_direction: FlexDirection::Column,
width: Val::Percent(100.),
height: Val::Percent(100.),
..Default::default()
},
.spawn(Node {
display: Display::Flex,
flex_direction: FlexDirection::Column,
width: Val::Percent(100.),
height: Val::Percent(100.),
..Default::default()
})
.with_children(|parent| {
Expand All @@ -298,43 +295,32 @@ fn build_button_row<T: Component + Default + Clone>(
channel_index: u8,
) {
parent
.spawn(NodeBundle {
style: Style {
display: Display::Flex,
flex_direction: FlexDirection::Row,
width: Val::Percent(100.),
height: Val::Percent(33.3),
..Default::default()
},
.spawn(Node {
display: Display::Flex,
flex_direction: FlexDirection::Row,
width: Val::Percent(100.),
height: Val::Percent(33.3),
..Default::default()
})
.with_children(|parent| {
parent
.spawn(NodeBundle {
style: Style {
width: Val::Px(120.0),
height: Val::Percent(100.),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..Default::default()
},
.spawn(Node {
width: Val::Px(120.0),
height: Val::Percent(100.),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..Default::default()
})
.with_children(|parent| {
parent.spawn(TextBundle {
text: Text {
sections: vec![TextSection {
value: format!("Channel {}", 4 - channel_index),
style: TextStyle {
font_size: 20.0,
color: Color::linear_rgb(0.9, 0.9, 0.9),
font: font.clone(),
},
}],
parent.spawn((
Text::new(format!("Channel {}", 4 - channel_index)),
TextFont {
font: font.clone(),
font_size: 20.0,
..Default::default()
},
..Default::default()
});
TextColor(Color::linear_rgb(0.9, 0.9, 0.9)),
));
});
spawn_button(
parent,
Expand Down Expand Up @@ -395,36 +381,31 @@ fn spawn_button<T: Component + Clone>(
font: Handle<Font>,
) {
parent
.spawn(ButtonBundle {
style: Style {
.spawn((
Node {
width: Val::Px(100.0),
height: Val::Px(65.0),
margin: UiRect::all(Val::Auto),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..Default::default()
},
image: UiImage::default().with_color(color),
..Default::default()
})
ImageNode::default().with_color(color),
Button,
))
.insert(marker.clone())
.with_children(|parent| {
parent
.spawn(TextBundle {
text: Text {
sections: vec![TextSection {
value: text.to_string(),
style: TextStyle {
font_size: 20.0,
color: Color::linear_rgb(0.9, 0.9, 0.9),
font: font.clone(),
},
}],
justify: JustifyText::Center,
.spawn((
Text::new(String::new()),
TextFont {
font: font.clone(),
font_size: 20.0,
..Default::default()
},
..Default::default()
})
.insert(marker);
TextColor(Color::linear_rgb(0.9, 0.9, 0.9)),
TextLayout::new_with_justify(JustifyText::Center),
))
.with_child((TextSpan::new(text), marker));
});
}
Loading

0 comments on commit e029b4c

Please sign in to comment.