Merge pull request #6 from kristoferssolo/feature/update-bevy

chore: update to bevy0.15
This commit is contained in:
Kristofers Solo 2024-12-11 18:01:40 +02:00 committed by GitHub
commit 80bc027477
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 1000 additions and 597 deletions

1347
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
[package]
name = "maze-ascension"
authors = ["Kristofers Solo <dev@kristofers.xyz>"]
version = "0.0.6"
version = "0.1.0"
edition = "2021"
[dependencies]
bevy = { version = "0.14", features = ["wayland"] }
bevy = { version = "0.15", features = ["wayland"] }
rand = "0.8"
# Compile low-severity logs out of native builds for performance.
log = { version = "0.4", features = [
@ -17,10 +17,10 @@ tracing = { version = "0.1", features = [
"max_level_debug",
"release_max_level_warn",
] }
hexx = { version = "0.18", features = ["bevy_reflect", "grid"] }
hexlab = { version = "0.1", features = ["bevy"] }
bevy-inspector-egui = { version = "0.27", optional = true }
bevy_egui = { version = "0.30", optional = true }
hexx = { version = "0.19", features = ["bevy_reflect", "grid"] }
hexlab = { version = "0.2", features = ["bevy"] }
bevy-inspector-egui = { version = "0.28", optional = true }
bevy_egui = { version = "0.31", optional = true }
thiserror = "2.0"

View File

@ -84,10 +84,8 @@ enum AppSet {
fn spawn_camera(mut commands: Commands) {
commands.spawn((
Name::new("Camera"),
Camera3dBundle {
transform: Transform::from_xyz(200., 200., 0.).looking_at(Vec3::ZERO, Vec3::Y),
..default()
},
Camera3d::default(),
Transform::from_xyz(200., 200., 0.).looking_at(Vec3::ZERO, Vec3::Y),
// Render all UI to this camera.
// Not strictly necessary since we only use one camera,
// but if we don't use this component, our UI will disappear as soon

View File

@ -3,7 +3,7 @@ use bevy::prelude::*;
use std::f32::consts::FRAC_PI_2;
const WALL_OVERLAP_MODIFIER: f32 = 1.25;
const HEX_SIDES: usize = 6;
const HEX_SIDES: u32 = 6;
const WHITE_EMISSION_INTENSITY: f32 = 10.;
pub(crate) struct MazeAssets {

View File

@ -23,6 +23,6 @@ impl Plugin for MazePlugin {
impl Command for MazePlugin {
fn apply(self, world: &mut World) {
world.insert_resource(MazePluginLoaded);
world.run_system_once(systems::setup::setup);
let _ = world.run_system_once(systems::setup::setup);
}
}

View File

@ -32,10 +32,8 @@ pub(super) fn setup_maze(
.spawn((
Name::new("Floor"),
MazeFloor(1),
SpatialBundle {
transform: Transform::from_translation(Vec3::ZERO),
..default()
},
Transform::from_translation(Vec3::ZERO),
Visibility::Visible,
))
.with_children(|parent| {
for tile in maze.values() {

View File

@ -26,12 +26,9 @@ pub(super) fn spawn_single_hex_tile(
.spawn((
Name::new(format!("Hex {}", tile)),
MazeTile,
PbrBundle {
mesh: assets.hex_mesh.clone(),
material: assets.hex_material.clone(),
transform: Transform::from_translation(world_pos).with_rotation(rotation),
..default()
},
Mesh3d(assets.hex_mesh.clone()),
MeshMaterial3d(assets.hex_material.clone()),
Transform::from_translation(world_pos).with_rotation(rotation),
))
.with_children(|parent| spawn_walls(parent, assets, config, tile.walls()));
}
@ -58,20 +55,12 @@ fn spawn_walls(parent: &mut ChildBuilder, assets: &MazeAssets, config: &MazeConf
}
}
fn spawn_single_wall(
parent: &mut ChildBuilder,
asstets: &MazeAssets,
rotation: Quat,
offset: Vec3,
) {
fn spawn_single_wall(parent: &mut ChildBuilder, assets: &MazeAssets, rotation: Quat, offset: Vec3) {
parent.spawn((
Name::new("Wall"),
MazeWall,
PbrBundle {
mesh: asstets.wall_mesh.clone(),
material: asstets.wall_material.clone(),
transform: Transform::from_translation(offset).with_rotation(rotation),
..default()
},
Mesh3d(assets.wall_mesh.clone()),
MeshMaterial3d(assets.wall_material.clone()),
Transform::from_translation(offset).with_rotation(rotation),
));
}

View File

@ -56,10 +56,8 @@ fn play_credits_music(mut commands: Commands, mut music: ResMut<CreditsMusic>) {
music.entity = Some(
commands
.spawn((
AudioBundle {
source: music.music.clone(),
settings: PlaybackSettings::LOOP,
},
AudioPlayer::<AudioSource>(music.music.clone()),
PlaybackSettings::LOOP,
Music,
))
.id(),

View File

@ -15,12 +15,12 @@ pub(super) fn plugin(app: &mut App) {
app.add_systems(
Update,
return_to_title_screen
.run_if(in_state(Screen::Gameplay).and_then(input_just_pressed(KeyCode::Escape))),
.run_if(in_state(Screen::Gameplay).and(input_just_pressed(KeyCode::Escape))),
);
}
fn spawn_level(mut commands: Commands) {
commands.add(spawn_level_command);
commands.queue(spawn_level_command);
}
#[derive(Resource, Asset, Reflect, Clone)]
@ -44,10 +44,8 @@ fn play_gameplay_music(mut commands: Commands, mut music: ResMut<GameplayMusic>)
music.entity = Some(
commands
.spawn((
AudioBundle {
source: music.handle.clone(),
settings: PlaybackSettings::LOOP,
},
AudioPlayer::<AudioSource>(music.handle.clone()),
PlaybackSettings::LOOP,
Music,
))
.id(),

View File

@ -13,7 +13,7 @@ pub(super) fn plugin(app: &mut App) {
app.add_systems(
Update,
continue_to_title_screen.run_if(in_state(Screen::Loading).and_then(all_assets_loaded)),
continue_to_title_screen.run_if(in_state(Screen::Loading).and(all_assets_loaded)),
);
}
@ -22,7 +22,7 @@ fn spawn_loading_screen(mut commands: Commands) {
.ui_root()
.insert(StateScoped(Screen::Loading))
.with_children(|children| {
children.label("Loading...").insert(Style {
children.label("Loading...").insert(Node {
justify_content: JustifyContent::Center,
..default()
});

View File

@ -1,9 +1,9 @@
//! A splash screen that plays briefly at startup.
//! A splash screen that plays bdelta_secsriefly at startup.
use bevy::{
image::{ImageLoaderSettings, ImageSampler},
input::common_conditions::input_just_pressed,
prelude::*,
render::texture::{ImageLoaderSettings, ImageSampler},
};
use crate::{screens::Screen, theme::prelude::*, AppSet};
@ -40,7 +40,7 @@ pub(super) fn plugin(app: &mut App) {
app.add_systems(
Update,
continue_to_loading_screen
.run_if(input_just_pressed(KeyCode::Escape).and_then(in_state(Screen::Splash))),
.run_if(input_just_pressed(KeyCode::Escape).and(in_state(Screen::Splash))),
);
}
@ -59,24 +59,21 @@ fn spawn_splash_screen(mut commands: Commands, asset_server: Res<AssetServer>) {
.with_children(|children| {
children.spawn((
Name::new("Splash image"),
ImageBundle {
style: Style {
margin: UiRect::all(Val::Auto),
width: Val::Percent(70.0),
..default()
},
image: UiImage::new(asset_server.load_with_settings(
// This should be an embedded asset for instant loading, but that is
// currently [broken on Windows Wasm builds](https://github.com/bevyengine/bevy/issues/14246).
"images/splash.png",
|settings: &mut ImageLoaderSettings| {
// Make an exception for the splash image in case
// `ImagePlugin::default_nearest()` is used for pixel art.
settings.sampler = ImageSampler::linear();
},
)),
Node {
margin: UiRect::all(Val::Auto),
width: Val::Percent(70.0),
..default()
},
ImageNode::new(asset_server.load_with_settings(
// This should be an embedded asset for instant loading, but that is
// currently [broken on Windows Wasm builds](https://github.com/bevyengine/bevy/issues/14246).
"images/splash.png",
|settings: &mut ImageLoaderSettings| {
// Make an exception for the splash image in case
// `ImagePlugin::default_nearest()` is used for pixel art.
settings.sampler = ImageSampler::linear();
},
)),
UiImageFadeInOut {
total_duration: SPLASH_DURATION_SECS,
fade_duration: SPLASH_FADE_DURATION_SECS,
@ -110,11 +107,11 @@ impl UiImageFadeInOut {
fn tick_fade_in_out(time: Res<Time>, mut animation_query: Query<&mut UiImageFadeInOut>) {
for mut anim in &mut animation_query {
anim.t += time.delta_seconds();
anim.t += time.delta_secs();
}
}
fn apply_fade_in_out(mut animation_query: Query<(&UiImageFadeInOut, &mut UiImage)>) {
fn apply_fade_in_out(mut animation_query: Query<(&UiImageFadeInOut, &mut ImageNode)>) {
for (anim, mut image) in &mut animation_query {
image.color.set_alpha(anim.alpha())
}

View File

@ -94,10 +94,8 @@ fn trigger_interaction_sound_effect(
_ => continue,
};
commands.spawn((
AudioBundle {
source,
settings: PlaybackSettings::DESPAWN,
},
AudioPlayer::<AudioSource>(source),
PlaybackSettings::DESPAWN,
SoundEffect,
));
}

View File

@ -16,19 +16,20 @@ pub trait Widgets {
fn label(&mut self, text: impl Into<String>) -> EntityCommands;
}
impl<T: Spawn> Widgets for T {
impl<T: SpawnUi> Widgets for T {
fn button(&mut self, text: impl Into<String>) -> EntityCommands {
let mut entity = self.spawn((
let mut entity = self.spawn_ui((
Name::new("Button"),
ButtonBundle {
style: Style {
width: Px(200.0),
height: Px(65.0),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
background_color: BackgroundColor(NODE_BACKGROUND),
Button,
ImageNode {
color: NODE_BACKGROUND,
..default()
},
Node {
width: Px(200.0),
height: Px(65.0),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
InteractionPalette {
@ -38,16 +39,14 @@ impl<T: Spawn> Widgets for T {
},
));
entity.with_children(|children| {
children.spawn((
children.spawn_ui((
Name::new("Button Text"),
TextBundle::from_section(
text,
TextStyle {
font_size: 40.0,
color: BUTTON_TEXT,
..default()
},
),
Text(text.into()),
TextFont {
font_size: 40.0,
..default()
},
TextColor(BUTTON_TEXT),
));
});
@ -55,51 +54,47 @@ impl<T: Spawn> Widgets for T {
}
fn header(&mut self, text: impl Into<String>) -> EntityCommands {
let mut entity = self.spawn((
let mut entity = self.spawn_ui((
Name::new("Header"),
NodeBundle {
style: Style {
width: Px(500.0),
height: Px(65.0),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
background_color: BackgroundColor(NODE_BACKGROUND),
Node {
width: Px(500.0),
height: Px(65.0),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
BackgroundColor(NODE_BACKGROUND),
));
entity.with_children(|children| {
children.spawn((
children.spawn_ui((
Name::new("Header Text"),
TextBundle::from_section(
text,
TextStyle {
font_size: 40.0,
color: HEADER_TEXT,
..default()
},
),
Text(text.into()),
TextFont {
font_size: 40.0,
..default()
},
TextColor(HEADER_TEXT),
));
});
entity
}
fn label(&mut self, text: impl Into<String>) -> EntityCommands {
let entity = self.spawn((
fn label(&mut self, _text: impl Into<String>) -> EntityCommands {
let entity = self.spawn_ui((
Name::new("Label"),
TextBundle::from_section(
text,
TextStyle {
font_size: 24.0,
color: LABEL_TEXT,
..default()
},
)
.with_style(Style {
width: Px(500.0),
..default()
}),
Text::default(),
// TextBundle::from_section(
// text,
// TextStyle {
// font_size: 24.0,
// color: LABEL_TEXT,
// ..default()
// },
// )
// .with_style(Style {
// width: Px(500.0),
// ..default()
// }),
));
entity
}
@ -116,17 +111,14 @@ impl Containers for Commands<'_, '_> {
fn ui_root(&mut self) -> EntityCommands {
self.spawn((
Name::new("UI Root"),
NodeBundle {
style: Style {
width: Percent(100.0),
height: Percent(100.0),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
flex_direction: FlexDirection::Column,
row_gap: Px(10.0),
position_type: PositionType::Absolute,
..default()
},
Node {
width: Percent(100.0),
height: Percent(100.0),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
flex_direction: FlexDirection::Column,
row_gap: Px(10.0),
position_type: PositionType::Absolute,
..default()
},
))
@ -137,18 +129,18 @@ impl Containers for Commands<'_, '_> {
/// This is here so that [`Widgets`] can be implemented on all types that
/// are able to spawn entities.
/// Ideally, this trait should be [part of Bevy itself](https://github.com/bevyengine/bevy/issues/14231).
trait Spawn {
fn spawn<B: Bundle>(&mut self, bundle: B) -> EntityCommands;
trait SpawnUi {
fn spawn_ui<B: Bundle>(&mut self, bundle: B) -> EntityCommands;
}
impl Spawn for Commands<'_, '_> {
fn spawn<B: Bundle>(&mut self, bundle: B) -> EntityCommands {
impl SpawnUi for Commands<'_, '_> {
fn spawn_ui<B: Bundle>(&mut self, bundle: B) -> EntityCommands {
self.spawn(bundle)
}
}
impl Spawn for ChildBuilder<'_> {
fn spawn<B: Bundle>(&mut self, bundle: B) -> EntityCommands {
impl SpawnUi for ChildBuilder<'_> {
fn spawn_ui<B: Bundle>(&mut self, bundle: B) -> EntityCommands {
self.spawn(bundle)
}
}