Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Bevy 0.15 #241

Merged
merged 17 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.22.0 - 01.12.2024
- support for Bevy 0.15
- support for using sub states as loading states ([@mgi388](https://github.com/mgi388) in [#239](https://github.com/NiklasEi/bevy_asset_loader/pull/239))
- support image sampler address modes for image assets ([@pcwalton](https://github.com/pcwalton) in [#238](https://github.com/NiklasEi/bevy_asset_loader/pull/238))
- custom `on_unimplemented` diagnostics for the `AssetCollection` trait
- image derive attribute `array_texture_layers`
- wait for dependencies of assets to load
Expand Down
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This [Bevy][bevy] plugin reduces boilerplate for handling game assets. The crate

In most cases you will want to load your asset collections during loading states (think loading screens). During such a state, all assets are loaded and their loading progress is observed. Only when asset collections can be built with fully loaded asset handles, the collections are inserted to Bevy's ECS as resources. If you do not want to use a loading state, asset collections can still result in cleaner code and improved maintainability (see the ["usage without a loading state"](#usage-without-a-loading-state) section).

_The `main` branch and the latest release support Bevy version `0.14` (see [version table](#compatible-bevy-versions))_
_The `main` branch and the latest release support Bevy version `0.15` (see [version table](#compatible-bevy-versions))_

## Loading states

Expand Down Expand Up @@ -45,10 +45,7 @@ struct AudioAssets {
/// This system runs in MyStates::Next. Thus, AudioAssets is available as a resource
/// and the contained handle is done loading.
fn start_background_audio(mut commands: Commands, audio_assets: Res<AudioAssets>) {
commands.spawn(AudioBundle {
source: audio_assets.background.clone(),
settings: PlaybackSettings::LOOP,
});
commands.spawn((AudioPlayer(audio_assets.background.clone()), PlaybackSettings::LOOP));
}

#[derive(Clone, Eq, PartialEq, Debug, Hash, Default, States)]
Expand Down Expand Up @@ -540,6 +537,7 @@ Compatibility of `bevy_asset_loader` versions:

| Bevy version | `bevy_asset_loader` version |
|:-------------|:----------------------------|
| `0.15` | `0.22` |
| `0.14` | `0.21` |
| `0.13` | `0.20` |
| `0.12` | `0.18` - `0.19` |
Expand All @@ -550,7 +548,7 @@ Compatibility of `bevy_asset_loader` versions:
| `0.7` | `0.10` - `0.11` |
| `0.6` | `0.8` - `0.9` |
| `0.5` | `0.1` - `0.7` |
| `0.13` | branch `main` |
| `0.15` | branch `main` |
| `main` | branch `bevy_main` |

## License
Expand Down
20 changes: 10 additions & 10 deletions bevy_asset_loader/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_asset_loader"
version = "0.21.0"
version = "0.22.0"
authors = ["Niklas Eicker <[email protected]>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand All @@ -15,27 +15,27 @@ readme = "README.md"

[features]
# This feature adds support for bevy's TextureAtlas assets
2d = ["bevy/bevy_sprite", "bevy_asset_loader_derive/2d"]
2d = ["bevy/bevy_sprite", "bevy/png", "bevy_asset_loader_derive/2d"]
# This feature adds support for bevy's StandardMaterial assets
3d = ["bevy/bevy_pbr", "bevy_asset_loader_derive/3d"]
3d = ["bevy/bevy_pbr", "bevy/png", "bevy_asset_loader_derive/3d"]
standard_dynamic_assets = ["dep:bevy_common_assets", "dep:serde"]
progress_tracking = ["dep:iyes_progress"]

[dependencies]
bevy = { version = "0.14.0", default-features = false, features = ["bevy_asset", "bevy_state"] }
bevy_asset_loader_derive = { version = "=0.21.0", path = "../bevy_asset_loader_derive" }
bevy = { version = "0.15.0", default-features = false, features = ["bevy_asset", "bevy_state"] }
bevy_asset_loader_derive = { version = "0.22.0", path = "../bevy_asset_loader_derive" }
anyhow = "1"
path-slash = "0.2"

bevy_common_assets = { version = "0.11.0", features = ["ron"], optional = true }
bevy_common_assets = { version = "0.12.0", features = ["ron"], optional = true }
serde = { version = "1", optional = true }
iyes_progress = { version = "0.12.0", optional = true }
iyes_progress = { version = "0.13.0", optional = true }

[dev-dependencies]
bevy = { version = "0.14.0", features = ["vorbis"] }
bevy = { version = "0.15.0", features = ["vorbis"] }
anyhow = "1"
iyes_progress = { version = "0.12.0" }
bevy_common_assets = { version = "0.11.0", features = ["ron"] }
iyes_progress = { version = "0.13.0" }
bevy_common_assets = { version = "0.12.0", features = ["ron"] }
serde = { version = "1" }
ron = "0.8.1"
trybuild = { version = "1.0" }
Expand Down
33 changes: 15 additions & 18 deletions bevy_asset_loader/examples/atlas_from_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,33 @@ struct MyAssets {
}

fn draw_atlas(mut commands: Commands, my_assets: Res<MyAssets>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
// draw the original image (whole sprite sheet)
commands.spawn(SpriteBundle {
texture: my_assets.female_adventurer.clone(),
transform: Transform::from_xyz(0., -150., 0.),
..Default::default()
});
commands.spawn((
Sprite::from_image(my_assets.female_adventurer.clone()),
Transform::from_xyz(0., -150., 0.),
));
// draw animated sprite using the texture atlas layout
commands.spawn((
SpriteBundle {
texture: my_assets.female_adventurer.clone(),
transform: Transform::from_xyz(0., 150., 0.),
..Default::default()
},
TextureAtlas::from(my_assets.female_adventurer_layout.clone()),
Sprite::from_atlas_image(
my_assets.female_adventurer.clone(),
TextureAtlas::from(my_assets.female_adventurer_layout.clone()),
),
Transform::from_xyz(0., 150., 0.),
AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
));
}

#[derive(Component)]
struct AnimationTimer(Timer);

fn animate_sprite_system(
time: Res<Time>,
mut sprites_to_animate: Query<(&mut AnimationTimer, &mut TextureAtlas)>,
) {
for (mut timer, mut sprite) in &mut sprites_to_animate {
fn animate_sprite_system(time: Res<Time>, mut query: Query<(&mut AnimationTimer, &mut Sprite)>) {
for (mut timer, mut sprite) in &mut query {
timer.0.tick(time.delta());
if timer.0.finished() {
sprite.index = (sprite.index + 1) % 8;
if let Some(atlas) = &mut sprite.texture_atlas {
atlas.index = (atlas.index + 1) % 8;
}
}
}
}
Expand Down
19 changes: 9 additions & 10 deletions bevy_asset_loader/examples/configure_loading_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,18 @@ impl FromWorld for ExampleResource {
}

fn spawn_player(mut commands: Commands, image_assets: Res<ImageAssets>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(SpriteBundle {
texture: image_assets.player.clone(),
transform: Transform::from_translation(Vec3::new(0., 0., 1.)),
..Default::default()
});
commands.spawn(Camera2d);
commands.spawn((
Sprite::from_image(image_assets.player.clone()),
Transform::from_translation(Vec3::new(0., 0., 1.)),
));
}

fn play_background_audio(mut commands: Commands, audio_assets: Res<AudioAssets>) {
commands.spawn(AudioBundle {
source: audio_assets.background.clone(),
settings: PlaybackSettings::LOOP,
});
commands.spawn((
AudioPlayer(audio_assets.background.clone()),
PlaybackSettings::LOOP,
));
}

#[derive(Clone, Eq, PartialEq, Debug, Hash, Default, States)]
Expand Down
56 changes: 26 additions & 30 deletions bevy_asset_loader/examples/custom_dynamic_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,46 +26,42 @@ fn main() {
}

fn render_stuff(mut commands: Commands, assets: Res<MyAssets>) {
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..Camera3dBundle::default()
});
commands.spawn(PbrBundle {
mesh: assets.cube.clone(),
material: assets.tree_standard_material.clone(),
transform: Transform::from_xyz(-1., 0., 1.),
..default()
});
commands.spawn(PbrBundle {
mesh: assets.cube.clone(),
material: assets.player_standard_material.clone(),
transform: Transform::from_xyz(1., 0., 1.),
..default()
});
commands.spawn(PointLightBundle {
point_light: PointLight {
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
));
commands.spawn((
Mesh3d(assets.cube.clone()),
MeshMaterial3d(assets.tree_standard_material.clone()),
Transform::from_xyz(-1., 0., 1.),
));
commands.spawn((
Mesh3d(assets.cube.clone()),
MeshMaterial3d(assets.player_standard_material.clone()),
Transform::from_xyz(1., 0., 1.),
));
commands.spawn((
PointLight {
intensity: 1500.0,
shadows_enabled: true,
..default()
},
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..default()
});
Transform::from_xyz(4.0, 8.0, 4.0),
));

commands.spawn(Camera2dBundle {
camera: Camera {
commands.spawn((
Camera2d,
Camera {
order: 1,
clear_color: ClearColorConfig::None,
..default()
},
..default()
});
));
// Combined image as sprite
commands.spawn(SpriteBundle {
texture: assets.combined_image.clone(),
transform: Transform::from_xyz(0.0, 200.0, 0.0),
..default()
});
commands.spawn((
Sprite::from_image(assets.combined_image.clone()),
Transform::from_xyz(0.0, 200.0, 0.0),
));
}

#[derive(AssetCollection, Resource)]
Expand Down
57 changes: 22 additions & 35 deletions bevy_asset_loader/examples/dynamic_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,41 +46,29 @@ struct AudioAssets {
}

fn spawn_player_and_tree(mut commands: Commands, image_assets: Res<ImageAssets>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
let mut transform = Transform::from_translation(Vec3::new(0., 0., 1.));
transform.scale = Vec3::splat(0.5);
commands
.spawn((
SpriteBundle {
transform: Transform {
translation: Vec3::new(0., 150., 0.),
..Default::default()
},
texture: image_assets.player.clone(),
..Default::default()
},
TextureAtlas {
layout: image_assets.player_layout.clone(),
index: 0,
},
))
.insert(AnimationTimer(Timer::from_seconds(
0.1,
TimerMode::Repeating,
)))
.insert(Player);
commands.spawn(SpriteBundle {
texture: image_assets.tree.clone(),
transform: Transform::from_translation(Vec3::new(50., 30., 1.)),
..Default::default()
});
commands.spawn((
Sprite::from_atlas_image(
image_assets.player.clone(),
TextureAtlas::from(image_assets.player_layout.clone()),
),
Transform::from_translation(Vec3::new(0., 150., 0.)),
AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
Player,
));
commands.spawn((
Sprite::from_image(image_assets.tree.clone()),
Transform::from_translation(Vec3::new(50., 30., 1.)),
));
}

fn play_background_audio(mut commands: Commands, audio_assets: Res<AudioAssets>) {
commands.spawn(AudioBundle {
source: audio_assets.background.clone(),
settings: PlaybackSettings::LOOP,
});
commands.spawn((
AudioPlayer(audio_assets.background.clone()),
PlaybackSettings::LOOP,
));
}

#[derive(Clone, Eq, PartialEq, Debug, Hash, Default, States)]
Expand All @@ -96,14 +84,13 @@ struct Player;
#[derive(Component)]
struct AnimationTimer(Timer);

fn animate_sprite_system(
time: Res<Time>,
mut query: Query<(&mut AnimationTimer, &mut TextureAtlas)>,
) {
fn animate_sprite_system(time: Res<Time>, mut query: Query<(&mut AnimationTimer, &mut Sprite)>) {
for (mut timer, mut sprite) in &mut query {
timer.0.tick(time.delta());
if timer.0.finished() {
sprite.index = (sprite.index + 1) % 8;
if let Some(atlas) = &mut sprite.texture_atlas {
atlas.index = (atlas.index + 1) % 8;
}
}
}
}
Loading
Loading