Skip to content

Commit

Permalink
WIP Update to Bevy 0.14.0-rc2
Browse files Browse the repository at this point in the history
This currently includes some unsafe that will be removed before a release
  • Loading branch information
NiklasEi committed Jun 8, 2024
1 parent e7c389d commit adf1df8
Show file tree
Hide file tree
Showing 38 changed files with 410 additions and 333 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

- all texture atlas layout parameters are integers (u32) now

## v0.20.2 - 18.05.2024
- Fix texture atlas layout in asset collections (see [#212](https://github.com/NiklasEi/bevy_asset_loader/pull/212))

Expand Down
16 changes: 8 additions & 8 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.20.2"
version = "0.21.0-rc2.1"
authors = ["Niklas Eicker <git@nikl.me>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand All @@ -22,20 +22,20 @@ standard_dynamic_assets = ["dep:bevy_common_assets", "dep:serde"]
progress_tracking = ["dep:iyes_progress"]

[dependencies]
bevy = { version = "0.13", default-features = false, features = ["bevy_asset"] }
bevy_asset_loader_derive = { version = "=0.20.2", path = "../bevy_asset_loader_derive" }
bevy = { version = "0.14.0-rc.2", default-features = false, features = ["bevy_asset"] }
bevy_asset_loader_derive = { version = "=0.21.0-rc2.1", path = "../bevy_asset_loader_derive" }
anyhow = "1"
path-slash = "0.2"

bevy_common_assets = { version = "0.10", features = ["ron"], optional = true }
bevy_common_assets = { version = "0.11.0-rc.2.1", features = ["ron"], optional = true }
serde = { version = "1", optional = true }
iyes_progress = { version = "0.11", optional = true }
iyes_progress = { git = "https://github.com/NiklasEi/iyes_progress", branch = "update_bevy_main_for_0_14_cycle", optional = true }

[dev-dependencies]
bevy = { version = "0.13", features = ["vorbis"] }
bevy = { version = "0.14.0-rc.2", features = ["vorbis"] }
anyhow = "1"
iyes_progress = { version = "0.11" }
bevy_common_assets = { version = "0.10", features = ["ron"] }
iyes_progress = { git = "https://github.com/NiklasEi/iyes_progress", branch = "update_bevy_main_for_0_14_cycle" }
bevy_common_assets = { version = "0.11.0-rc.2.1", features = ["ron"] }
serde = { version = "1" }
ron = "0.8.1"
trybuild = { version = "1.0" }
Expand Down
4 changes: 2 additions & 2 deletions bevy_asset_loader/assets/dynamic_asset.assets.ron
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
path: "images/female_adventurer_sheet.png",
),
"layout.player_sheet": TextureAtlasLayout (
tile_size_x: 96.,
tile_size_y: 99.,
tile_size_x: 96,
tile_size_y: 99,
columns: 8,
rows: 1
),
Expand Down
16 changes: 8 additions & 8 deletions bevy_asset_loader/assets/dynamic_asset_arrays.asset_arrays.ron
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
({
"layouts": [
TextureAtlasLayout(
tile_size_x: 96.,
tile_size_y: 99.,
tile_size_x: 96,
tile_size_y: 99,
columns: 8,
rows: 1,
),
TextureAtlasLayout(
tile_size_x: 32.,
tile_size_y: 64.,
tile_size_x: 32,
tile_size_y: 64,
columns: 12,
rows: 6,
),
TextureAtlasLayout(
tile_size_x: 64.,
tile_size_y: 32.,
tile_size_x: 64,
tile_size_y: 32,
columns: 6,
rows: 12,
),
TextureAtlasLayout(
tile_size_x: 64.,
tile_size_y: 64.,
tile_size_x: 64,
tile_size_y: 64,
columns: 6,
rows: 6,
),
Expand Down
4 changes: 2 additions & 2 deletions bevy_asset_loader/assets/full_dynamic_collection.assets.ron
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
path: "images/tree.png",
),
"texture_atlas_layout": TextureAtlasLayout (
tile_size_x: 96.,
tile_size_y: 99.,
tile_size_x: 96,
tile_size_y: 99,
columns: 8,
rows: 1,
),
Expand Down
2 changes: 1 addition & 1 deletion bevy_asset_loader/examples/asset_maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn use_audio_assets(audio_assets: Res<AudioAssets>, mut quit: EventWriter<AppExi

info!("Everything looks good!");
info!("Quitting the application...");
quit.send(AppExit);
quit.send(AppExit::Success);
}

#[derive(PartialEq, Eq, Hash)]
Expand Down
2 changes: 1 addition & 1 deletion bevy_asset_loader/examples/atlas_from_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct MyAssets {
// if the sheet would have padding, you could set that with `padding_x` and `padding_y`.
// if there would be space between the top left corner of the sheet and the first sprite, you could configure that with `offset_x` and `offset_y`
// A texture atlas layout does not have a path as no asset file will be loaded for the layout
#[asset(texture_atlas_layout(tile_size_x = 96., tile_size_y = 99., columns = 8, rows = 1))]
#[asset(texture_atlas_layout(tile_size_x = 96, tile_size_y = 99, columns = 8, rows = 1))]
female_adventurer_layout: Handle<TextureAtlasLayout>,
// you can configure the sampler for the sprite sheet image
#[asset(image(sampler = nearest))]
Expand Down
24 changes: 11 additions & 13 deletions bevy_asset_loader/examples/custom_dynamic_assets.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bevy::ecs::system::SystemState;
use bevy::prelude::*;
use bevy::reflect::TypePath;
use bevy::render::render_asset::RenderAssetUsages;
Expand Down Expand Up @@ -117,18 +118,14 @@ impl DynamicAsset for CustomDynamicAsset {
// This method is called when all asset handles returned from `load` are done loading.
// The handles that you return, should also be loaded.
fn build(&self, world: &mut World) -> Result<DynamicAssetType, anyhow::Error> {
let cell = world.cell();
let asset_server = cell
.get_resource::<AssetServer>()
.expect("Failed to get asset server");
match self {
CustomDynamicAsset::CombinedImage {
top_layer,
bottom_layer,
} => {
let mut images = cell
.get_resource_mut::<Assets<Image>>()
.expect("Failed to get image assets");
let mut system_state =
SystemState::<(ResMut<Assets<Image>>, Res<AssetServer>)>::new(world);
let (mut images, asset_server) = system_state.get_mut(world);
let first = images
.get(&asset_server.load(top_layer))
.expect("Failed to get first layer");
Expand Down Expand Up @@ -161,10 +158,11 @@ impl DynamicAsset for CustomDynamicAsset {
base_color_texture,
base_color,
} => {
let mut materials = cell
.get_resource_mut::<Assets<StandardMaterial>>()
.expect("Failed to get standard material assets");
let color = Color::rgba(base_color[0], base_color[1], base_color[2], base_color[3]);
let mut system_state =
SystemState::<(ResMut<Assets<StandardMaterial>>, Res<AssetServer>)>::new(world);
let (mut materials, asset_server) = system_state.get_mut(world);
let color =
Color::linear_rgba(base_color[0], base_color[1], base_color[2], base_color[3]);
let image = asset_server.load(base_color_texture);
let mut material = StandardMaterial::from(color);
material.base_color_texture = Some(image);
Expand All @@ -173,9 +171,9 @@ impl DynamicAsset for CustomDynamicAsset {
Ok(DynamicAssetType::Single(materials.add(material).untyped()))
}
CustomDynamicAsset::Cube { size } => {
let mut meshes = cell
let mut meshes = world
.get_resource_mut::<Assets<Mesh>>()
.expect("Failed to get mesh assets");
.expect("Cannot get Assets<Mesh>");
let handle = meshes
.add(Mesh::from(Cuboid {
half_size: Vec3::splat(size / 2.),
Expand Down
16 changes: 9 additions & 7 deletions bevy_asset_loader/examples/dynamic_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,20 @@ fn spawn_player_and_tree(mut commands: Commands, image_assets: Res<ImageAssets>)
let mut transform = Transform::from_translation(Vec3::new(0., 0., 1.));
transform.scale = Vec3::splat(0.5);
commands
.spawn(SpriteSheetBundle {
transform: Transform {
translation: Vec3::new(0., 150., 0.),
.spawn((
SpriteBundle {
transform: Transform {
translation: Vec3::new(0., 150., 0.),
..Default::default()
},
texture: image_assets.player.clone(),
..Default::default()
},
texture: image_assets.player.clone(),
atlas: TextureAtlas {
TextureAtlas {
layout: image_assets.player_layout.clone(),
index: 0,
},
..Default::default()
})
))
.insert(AnimationTimer(Timer::from_seconds(
0.1,
TimerMode::Repeating,
Expand Down
16 changes: 9 additions & 7 deletions bevy_asset_loader/examples/dynamic_asset_arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,20 @@ fn spawn_player_and_tree(mut commands: Commands, image_assets: Res<ImageAssets>)
let mut transform = Transform::from_translation(Vec3::new(0., 0., 1.));
transform.scale = Vec3::splat(0.5);
commands
.spawn(SpriteSheetBundle {
transform: Transform {
translation: Vec3::new(0., 150., 0.),
.spawn((
SpriteBundle {
transform: Transform {
translation: Vec3::new(0., 150., 0.),
..Default::default()
},
texture: image_assets.mixed_handlers[1].clone().typed(),
..Default::default()
},
texture: image_assets.mixed_handlers[1].clone().typed(),
atlas: TextureAtlas {
TextureAtlas {
layout: image_assets.atlas_layout[0].clone(),
index: 0,
},
..Default::default()
})
))
.insert(AnimationTimer(Timer::from_seconds(
0.1,
TimerMode::Repeating,
Expand Down
2 changes: 1 addition & 1 deletion bevy_asset_loader/examples/failure_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn fail() {
fn ok(mut quit: EventWriter<AppExit>) {
info!("As expected, bevy_asset_loader switched to the failure state");
info!("Quitting the application...");
quit.send(AppExit);
quit.send(AppExit::Success);
}

fn timeout(time: Res<Time>) {
Expand Down
17 changes: 11 additions & 6 deletions bevy_asset_loader/examples/full_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct MyAssets {
#[asset(path = "images/player.png", standard_material)]
standard_material: Handle<StandardMaterial>,
// Create a texture atlas layout
#[asset(texture_atlas_layout(tile_size_x = 96., tile_size_y = 99., columns = 8, rows = 1))]
#[asset(texture_atlas_layout(tile_size_x = 96, tile_size_y = 99, columns = 8, rows = 1))]
texture_atlas_layout: Handle<TextureAtlasLayout>,
// Example field with type that implements `FromWorld`
// If no derive attributes are set, `from_world` will be used to set the value.
Expand Down Expand Up @@ -80,15 +80,15 @@ fn expectations(
info!("Done loading the collection. Checking expectations...");

assert_eq!(
asset_server.get_recursive_dependency_load_state(assets.single_file.clone()),
asset_server.get_recursive_dependency_load_state(&assets.single_file.clone()),
Some(RecursiveDependencyLoadState::Loaded)
);
let material = standard_materials
.get(&assets.standard_material)
.expect("Standard material should be added to its assets resource.");
assert_eq!(
asset_server.get_recursive_dependency_load_state(
material
&material
.base_color_texture
.clone()
.expect("Material should have image as base color texture")
Expand All @@ -102,7 +102,7 @@ fn expectations(
let material = standard_materials
.get(&assets.from_world.handle)
.expect("Standard material should be added to its assets resource.");
assert_eq!(material.base_color, Color::RED);
assert_eq!(material.base_color, Color::LinearRgba(LinearRgba::RED));

let image = images
.get(&assets.image_tree_nearest)
Expand Down Expand Up @@ -178,7 +178,7 @@ fn expectations(

info!("Everything looks good!");
info!("Quitting the application...");
quit.send(AppExit);
quit.send(AppExit::Success);
}

struct ColorStandardMaterial<const R: u8, const G: u8, const B: u8, const A: u8> {
Expand All @@ -193,7 +193,12 @@ impl<const R: u8, const G: u8, const B: u8, const A: u8> FromWorld
.get_resource_mut::<Assets<StandardMaterial>>()
.unwrap();
ColorStandardMaterial {
handle: materials.add(StandardMaterial::from(Color::rgba_u8(R, G, B, A))),
handle: materials.add(StandardMaterial::from(Color::linear_rgba(
R as f32 / u8::MAX as f32,
G as f32 / u8::MAX as f32,
B as f32 / u8::MAX as f32,
A as f32 / u8::MAX as f32,
))),
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions bevy_asset_loader/examples/full_dynamic_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn expectations(
info!("Done loading the collection. Checking expectations...");

assert_eq!(
asset_server.get_recursive_dependency_load_state(assets.single_file.clone()),
asset_server.get_recursive_dependency_load_state(&assets.single_file),
Some(RecursiveDependencyLoadState::Loaded)
);
let material = standard_materials
Expand All @@ -125,7 +125,7 @@ fn expectations(
asset_server.get_recursive_dependency_load_state(
material
.base_color_texture
.clone()
.as_ref()
.expect("Material should have image as base color texture")
),
Some(RecursiveDependencyLoadState::Loaded)
Expand Down Expand Up @@ -194,14 +194,14 @@ fn expectations(
assert_eq!(assets.files_typed.len(), 2);
for handle in assets.files_typed.iter() {
assert_eq!(
asset_server.get_recursive_dependency_load_state(handle.clone()),
asset_server.get_recursive_dependency_load_state(handle),
Some(RecursiveDependencyLoadState::Loaded)
);
}
assert_eq!(assets.files_typed_mapped.len(), 2);
for (name, handle) in assets.files_typed_mapped.iter() {
assert_eq!(
asset_server.get_recursive_dependency_load_state(handle.clone()),
asset_server.get_recursive_dependency_load_state(handle),
Some(RecursiveDependencyLoadState::Loaded)
);
assert_eq!(&handle.path().unwrap().to_string(), name);
Expand Down Expand Up @@ -279,7 +279,7 @@ fn expectations(
assert_eq!(optional_files_typed.len(), 2);
for handle in optional_files_typed.iter() {
assert_eq!(
asset_server.get_recursive_dependency_load_state(handle.clone()),
asset_server.get_recursive_dependency_load_state(handle),
Some(RecursiveDependencyLoadState::Loaded)
);
}
Expand All @@ -289,15 +289,15 @@ fn expectations(
assert_eq!(optional_files_typed_mapped.len(), 2);
for (name, handle) in optional_files_typed_mapped.iter() {
assert_eq!(
asset_server.get_recursive_dependency_load_state(handle.clone()),
asset_server.get_recursive_dependency_load_state(handle),
Some(RecursiveDependencyLoadState::Loaded)
);
assert_eq!(&handle.path().unwrap().to_string(), name);
}

info!("Everything looks good!");
info!("Quitting the application...");
quit.send(AppExit);
quit.send(AppExit::Success);
}

#[derive(Clone, Eq, PartialEq, Debug, Hash, Default, States)]
Expand Down
10 changes: 3 additions & 7 deletions bevy_asset_loader/examples/init_resource.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bevy::ecs::system::SystemState;
use bevy::prelude::*;
use bevy_asset_loader::prelude::*;

Expand Down Expand Up @@ -36,13 +37,8 @@ struct CombinedImage {

impl FromWorld for CombinedImage {
fn from_world(world: &mut World) -> Self {
let cell = world.cell();
let mut images = cell
.get_resource_mut::<Assets<Image>>()
.expect("Failed to get Assets<Image>");
let image_assets = cell
.get_resource::<ImageAssets>()
.expect("Failed to get ImageAssets");
let mut system_state = SystemState::<(ResMut<Assets<Image>>, Res<ImageAssets>)>::new(world);
let (mut images, image_assets) = system_state.get_mut(world);
let player_image = images.get(&image_assets.player).unwrap();
let tree_image = images.get(&image_assets.tree).unwrap();
let mut combined = player_image.clone();
Expand Down
Loading

0 comments on commit adf1df8

Please sign in to comment.