Skip to content

Commit

Permalink
Update to bevy 0.15 rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasEi committed Oct 24, 2024
1 parent 9b35b7c commit 64f9eae
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 199 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

- Update to Bevy `0.15`

## v0.20.0 - 04.07.2024
- Update to Bevy `0.14`
- Asset loaders are now public
Expand Down
8 changes: 4 additions & 4 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-rc.1"
authors = ["Niklas Eicker <[email protected]>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand All @@ -22,17 +22,17 @@ 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-rc.1", 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-rc.1"
default-features = false
features = [
"bevy_asset",
Expand Down
101 changes: 41 additions & 60 deletions examples/multiple_channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn play_pause_button<T: Component + Default>(
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 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 Down Expand Up @@ -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()
})
UiImage::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));
});
}
87 changes: 33 additions & 54 deletions examples/spatial.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use bevy::ecs::event::ManualEventReader;
use bevy::input::mouse::MouseMotion;
use bevy::prelude::*;
use bevy::window::{CursorGrabMode, PrimaryWindow};
Expand All @@ -25,11 +24,10 @@ fn setup(
.looped()
.handle();
commands
.spawn(SceneBundle {
scene: asset_server.load("models/panStew.glb#Scene0"),
transform: Transform::from_xyz(-5.0, 0., 0.),
..default()
})
.spawn((
SceneRoot(asset_server.load("models/panStew.glb#Scene0")),
Transform::from_xyz(-5.0, 0., 0.),
))
.insert(AudioEmitter {
instances: vec![cooking],
});
Expand All @@ -39,58 +37,40 @@ fn setup(
.looped()
.handle();
commands
.spawn(SceneBundle {
scene: asset_server.load("models/boxOpen.glb#Scene0"),
transform: Transform::from_xyz(10., 0., 0.),
..default()
})
.spawn((
SceneRoot(asset_server.load("models/boxOpen.glb#Scene0")),
Transform::from_xyz(10., 0., 0.),
))
.insert(AudioEmitter {
instances: vec![elevator_music],
});
// Our camera will be the receiver
commands
.spawn(Camera3dBundle {
transform: Transform::from_xyz(0.0, 0.5, 10.0),
..default()
})
.spawn((Camera3d::default(), Transform::from_xyz(0.0, 0.5, 10.0)))
.insert(AudioReceiver)
.insert(FlyCam);

// Other scene setup...
commands.spawn(PointLightBundle {
point_light: PointLight {
commands.spawn((
PointLight {
intensity: 1500.0,
shadows_enabled: true,
..default()
},
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..default()
});
commands.spawn( TextBundle {
text: Text {
sections: vec![TextSection {
value: "WASD to move horizontally\nSPACE to ascend\nLSHIFT to descend\nESC to grab/release cursor.".to_string(),
style: TextStyle {
font: asset_server.load("fonts/monogram.ttf"),
font_size: 40.0,
color: Color::linear_rgb(0.9, 0.9, 0.9),
},
}],
..default()
},
style: Style {
margin: UiRect::all(Val::Px(15.)),
..default()
},
Transform::from_xyz(4.0, 8.0, 4.0),
));
commands.spawn( (Text::new("WASD to move horizontally\nSPACE to ascend\nLSHIFT to descend\nESC to grab/release cursor."), TextFont{
font:asset_server.load("fonts/monogram.ttf"),
font_size: 40.0,
..default()
});
commands.spawn(PbrBundle {
mesh: meshes.add(Cuboid {
}, TextColor(Color::linear_rgb(0.9, 0.9, 0.9)),
Node {margin: UiRect::all(Val::Px(15.)), ..default()}));
commands.spawn((
Mesh3d(meshes.add(Cuboid {
half_size: Vec3::new(25., 0., 25.),
}),
material: materials.add(StandardMaterial::from_color(LinearRgba::GREEN)),
..default()
});
})),
MeshMaterial3d(materials.add(StandardMaterial::from_color(LinearRgba::GREEN))),
));
}

// only camera handling code from here on...
Expand Down Expand Up @@ -141,14 +121,14 @@ fn cursor_grab(

/// Grabs/ungrabs mouse cursor
fn toggle_grab_cursor(window: &mut Window) {
match window.cursor.grab_mode {
match window.cursor_options.grab_mode {
CursorGrabMode::None => {
window.cursor.grab_mode = CursorGrabMode::Confined;
window.cursor.visible = false;
window.cursor_options.grab_mode = CursorGrabMode::Confined;
window.cursor_options.visible = false;
}
_ => {
window.cursor.grab_mode = CursorGrabMode::None;
window.cursor.visible = true;
window.cursor_options.grab_mode = CursorGrabMode::None;
window.cursor_options.visible = true;
}
}
}
Expand All @@ -168,7 +148,7 @@ fn player_move(
let right = Vec3::new(local_z.z, 0., -local_z.x);

for key in keys.get_pressed() {
match window.cursor.grab_mode {
match window.cursor_options.grab_mode {
CursorGrabMode::None => (),
_ => match key {
KeyCode::KeyW => velocity += forward,
Expand All @@ -184,7 +164,7 @@ fn player_move(

velocity = velocity.normalize_or_zero();

transform.translation += velocity * time.delta_seconds() * SPEED;
transform.translation += velocity * time.delta_secs() * SPEED;
}
} else {
warn!("Primary window not found for `player_move`!");
Expand All @@ -193,7 +173,6 @@ fn player_move(

#[derive(Resource, Default)]
struct InputState {
reader_motion: ManualEventReader<MouseMotion>,
pitch: f32,
yaw: f32,
}
Expand All @@ -202,14 +181,14 @@ struct InputState {
fn player_look(
primary_window: Query<&Window, With<PrimaryWindow>>,
mut state: ResMut<InputState>,
motion: Res<Events<MouseMotion>>,
mut motion: EventReader<MouseMotion>,
mut query: Query<&mut Transform, With<FlyCam>>,
) {
if let Ok(window) = primary_window.get_single() {
let delta_state = state.as_mut();
for mut transform in query.iter_mut() {
for ev in delta_state.reader_motion.read(&motion) {
match window.cursor.grab_mode {
for ev in motion.read() {
match window.cursor_options.grab_mode {
CursorGrabMode::None => (),
_ => {
// Using smallest of height or width ensures equal vertical and horizontal sensitivity
Expand Down
Loading

0 comments on commit 64f9eae

Please sign in to comment.