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 7618bc5 commit d270246
Show file tree
Hide file tree
Showing 19 changed files with 113 additions and 130 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.11.0 - 04.07.2024
- Update to Bevy 0.14
- Update `quick-xml` to `0.34`
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_common_assets"
version = "0.11.0"
version = "0.12.0-rc.1"
authors = ["Niklas Eicker <[email protected]>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand All @@ -23,21 +23,21 @@ csv = ["dep:csv"]
postcard = ["dep:postcard"]

[dependencies]
bevy = { version = "0.14", default-features = false, features = ["bevy_asset"] }
bevy = { version = "0.15.0-rc.1", default-features = false, features = ["bevy_asset"] }
serde_toml = { version = "0.8", package = "toml", optional = true }
serde_ron = { version = "0.8", package = "ron", optional = true }
serde_yaml = { version = "0.9", optional = true }
serde_json = { version = "1", optional = true }
rmp-serde = { version = "1", optional = true }
csv = { version = "1", optional = true }
thiserror = "1.0"
quick-xml = { version = "0.34", features = [ "serialize" ], optional = true }
quick-xml = { version = "0.36.2", features = [ "serialize" ], optional = true }
serde = { version = "1" }
anyhow = { version = "1" }
postcard = {version = "1.0", features = ["use-std"], optional = true}

[dev-dependencies]
bevy = { version = "0.14.0-rc.4" }
bevy = { version = "0.15.0-rc.1" }
serde = { version = "1" }

[package.metadata.docs.rs]
Expand Down
21 changes: 9 additions & 12 deletions examples/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ fn main() {
DefaultPlugins,
CsvAssetPlugin::<TreePosition>::new(&["level.csv"]),
))
.insert_resource(Msaa::Off)
.init_state::<AppState>()
.add_systems(Startup, setup)
.add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))
Expand All @@ -22,7 +21,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let tree = ImageHandle(asset_server.load("tree.png"));
commands.insert_resource(tree);

commands.spawn(Camera2dBundle::default());
commands.spawn((Camera2d, Msaa::Off));
}

fn spawn_level(
Expand All @@ -33,17 +32,15 @@ fn spawn_level(
positions: Res<Assets<TreePosition>>,
mut state: ResMut<NextState<AppState>>,
) {
if asset_server.get_recursive_dependency_load_state(&level.0)
== Some(RecursiveDependencyLoadState::Loaded)
{
if matches!(
asset_server.get_recursive_dependency_load_state(&level.0),
Some(RecursiveDependencyLoadState::Loaded)
) {
for (_, position) in positions.iter() {
commands.spawn(SpriteBundle {
transform: Transform::from_translation(Vec3::new(
position.x, position.y, position.z,
)),
texture: tree.0.clone(),
..default()
});
commands.spawn((
Sprite::from_image(tree.0.clone()),
Transform::from_translation(Vec3::new(position.x, position.y, position.z)),
));
}

state.set(AppState::Level);
Expand Down
12 changes: 5 additions & 7 deletions examples/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ fn main() {
DefaultPlugins,
JsonAssetPlugin::<Level>::new(&["level.json"]),
))
.insert_resource(Msaa::Off)
.init_state::<AppState>()
.add_systems(Startup, setup)
.add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))
Expand All @@ -21,7 +20,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let tree = ImageHandle(asset_server.load("tree.png"));
commands.insert_resource(tree);

commands.spawn(Camera2dBundle::default());
commands.spawn((Camera2d, Msaa::Off));
}

fn spawn_level(
Expand All @@ -33,11 +32,10 @@ fn spawn_level(
) {
if let Some(level) = levels.remove(level.0.id()) {
for position in level.positions {
commands.spawn(SpriteBundle {
transform: Transform::from_translation(position.into()),
texture: tree.0.clone(),
..default()
});
commands.spawn((
Sprite::from_image(tree.0.clone()),
Transform::from_translation(position.into()),
));
}

state.set(AppState::Level);
Expand Down
12 changes: 5 additions & 7 deletions examples/msgpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ fn main() {
DefaultPlugins,
MsgPackAssetPlugin::<Level>::new(&["level.msgpack"]),
))
.insert_resource(Msaa::Off)
.init_state::<AppState>()
.add_systems(Startup, setup)
.add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))
Expand All @@ -21,7 +20,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let tree = ImageHandle(asset_server.load("tree.png"));
commands.insert_resource(tree);

commands.spawn(Camera2dBundle::default());
commands.spawn((Camera2d, Msaa::Off));
}

fn spawn_level(
Expand All @@ -33,11 +32,10 @@ fn spawn_level(
) {
if let Some(level) = levels.remove(level.0.id()) {
for position in level.positions {
commands.spawn(SpriteBundle {
transform: Transform::from_translation(position.into()),
texture: tree.0.clone(),
..default()
});
commands.spawn((
Sprite::from_image(tree.0.clone()),
Transform::from_translation(position.into()),
));
}

state.set(AppState::Level);
Expand Down
19 changes: 10 additions & 9 deletions examples/multiple_formats.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use bevy::asset::LoadState;
use bevy::prelude::*;
use bevy::reflect::TypePath;
use bevy_common_assets::json::JsonAssetPlugin;
Expand All @@ -13,7 +12,6 @@ fn main() {
RonAssetPlugin::<Level>::new(&["level.ron"]),
JsonAssetPlugin::<Level>::new(&["level.json"]),
))
.insert_resource(Msaa::Off)
.init_state::<AppState>()
.add_systems(Startup, setup)
.add_systems(Update, check_loading.run_if(in_state(AppState::Loading)))
Expand All @@ -33,7 +31,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let tree = ImageHandle(asset_server.load("tree.png"));
commands.insert_resource(tree);

commands.spawn(Camera2dBundle::default());
commands.spawn((Camera2d, Msaa::Off));
}

fn spawn_level(
Expand All @@ -45,11 +43,10 @@ fn spawn_level(
for handle in levels.0.iter() {
let level = level_assets.remove(handle).unwrap();
for position in level.positions {
commands.spawn(SpriteBundle {
transform: Transform::from_translation(position.into()),
texture: tree.0.clone(),
..default()
});
commands.spawn((
Sprite::from_image(tree.0.clone()),
Transform::from_translation(position.into()),
));
}
}
}
Expand All @@ -60,7 +57,11 @@ fn check_loading(
mut state: ResMut<NextState<AppState>>,
) {
for handle in &handles.0 {
if asset_server.get_load_state(handle) != Some(LoadState::Loaded) {
if asset_server
.get_load_state(handle)
.map(|state| !state.is_loaded())
.unwrap_or(true)
{
return;
}
}
Expand Down
12 changes: 5 additions & 7 deletions examples/postcard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ fn main() {
DefaultPlugins,
PostcardAssetPlugin::<Level>::new(&["level.postcard"]),
))
.insert_resource(Msaa::Off)
.init_state::<AppState>()
.add_systems(Startup, setup)
.add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))
Expand All @@ -20,7 +19,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.insert_resource(level);
let tree = ImageHandle(asset_server.load("tree.png"));
commands.insert_resource(tree);
commands.spawn(Camera2dBundle::default());
commands.spawn((Camera2d, Msaa::Off));
}

fn spawn_level(
Expand All @@ -32,11 +31,10 @@ fn spawn_level(
) {
if let Some(level) = levels.remove(level.0.id()) {
for position in level.positions {
commands.spawn(SpriteBundle {
transform: Transform::from_translation(position.into()),
texture: tree.0.clone(),
..default()
});
commands.spawn((
Sprite::from_image(tree.0.clone()),
Transform::from_translation(position.into()),
));
}
state.set(AppState::Level);
}
Expand Down
12 changes: 5 additions & 7 deletions examples/ron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use bevy_common_assets::ron::RonAssetPlugin;
fn main() {
App::new()
.add_plugins((DefaultPlugins, RonAssetPlugin::<Level>::new(&["level.ron"])))
.insert_resource(Msaa::Off)
.init_state::<AppState>()
.add_systems(Startup, setup)
.add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))
Expand All @@ -18,7 +17,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let tree = ImageHandle(asset_server.load("tree.png"));
commands.insert_resource(tree);

commands.spawn(Camera2dBundle::default());
commands.spawn((Camera2d, Msaa::Off));
}

fn spawn_level(
Expand All @@ -30,11 +29,10 @@ fn spawn_level(
) {
if let Some(level) = levels.remove(level.0.id()) {
for position in level.positions {
commands.spawn(SpriteBundle {
transform: Transform::from_translation(position.into()),
texture: tree.0.clone(),
..default()
});
commands.spawn((
Sprite::from_image(tree.0.clone()),
Transform::from_translation(position.into()),
));
}

state.set(AppState::Level);
Expand Down
12 changes: 5 additions & 7 deletions examples/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ fn main() {
DefaultPlugins,
TomlAssetPlugin::<Level>::new(&["level.toml"]),
))
.insert_resource(Msaa::Off)
.init_state::<AppState>()
.add_systems(Startup, setup)
.add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))
Expand All @@ -21,7 +20,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let tree = ImageHandle(asset_server.load("tree.png"));
commands.insert_resource(tree);

commands.spawn(Camera2dBundle::default());
commands.spawn((Camera2d, Msaa::Off));
}

fn spawn_level(
Expand All @@ -33,11 +32,10 @@ fn spawn_level(
) {
if let Some(level) = levels.remove(level.0.id()) {
for position in level.positions {
commands.spawn(SpriteBundle {
transform: Transform::from_translation(position.into()),
texture: tree.0.clone(),
..default()
});
commands.spawn((
Sprite::from_image(tree.0.clone()),
Transform::from_translation(position.into()),
));
}

state.set(AppState::Level);
Expand Down
14 changes: 5 additions & 9 deletions examples/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use bevy_common_assets::xml::XmlAssetPlugin;
fn main() {
App::new()
.add_plugins((DefaultPlugins, XmlAssetPlugin::<Level>::new(&["level.xml"])))
.insert_resource(Msaa::Off)
.init_state::<AppState>()
.add_systems(Startup, setup)
.add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))
Expand All @@ -19,7 +18,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let tree = ImageHandle(asset_server.load("tree.png"));
commands.insert_resource(tree);

commands.spawn(Camera2dBundle::default());
commands.spawn((Camera2d, Msaa::Off));
}

fn spawn_level(
Expand All @@ -31,13 +30,10 @@ fn spawn_level(
) {
if let Some(level) = levels.remove(level.0.id()) {
for position in level.positions {
commands.spawn(SpriteBundle {
transform: Transform::from_translation(Vec3::new(
position.x, position.y, position.z,
)),
texture: tree.0.clone(),
..default()
});
commands.spawn((
Sprite::from_image(tree.0.clone()),
Transform::from_translation(Vec3::new(position.x, position.y, position.z)),
));
}

state.set(AppState::Level);
Expand Down
12 changes: 5 additions & 7 deletions examples/yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ fn main() {
DefaultPlugins,
YamlAssetPlugin::<Level>::new(&["level.yaml"]),
))
.insert_resource(Msaa::Off)
.init_state::<AppState>()
.add_systems(Startup, setup)
.add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))
Expand All @@ -21,7 +20,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let tree = ImageHandle(asset_server.load("tree.png"));
commands.insert_resource(tree);

commands.spawn(Camera2dBundle::default());
commands.spawn((Camera2d, Msaa::Off));
}

fn spawn_level(
Expand All @@ -33,11 +32,10 @@ fn spawn_level(
) {
if let Some(level) = levels.remove(level.0.id()) {
for position in level.positions {
commands.spawn(SpriteBundle {
transform: Transform::from_translation(position.into()),
texture: tree.0.clone(),
..default()
});
commands.spawn((
Sprite::from_image(tree.0.clone()),
Transform::from_translation(position.into()),
));
}

state.set(AppState::Level);
Expand Down
12 changes: 6 additions & 6 deletions src/csv.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy::app::{App, Plugin};
use bevy::asset::io::Reader;
use bevy::asset::{Asset, AssetApp, AssetLoader, AsyncReadExt, Handle, LoadContext};
use bevy::asset::{Asset, AssetApp, AssetLoader, Handle, LoadContext};
use bevy::prelude::TypePath;
use std::marker::PhantomData;
use thiserror::Error;
Expand Down Expand Up @@ -99,11 +99,11 @@ where
type Settings = ();
type Error = CsvLoaderError;

async fn load<'a>(
&'a self,
reader: &'a mut Reader<'_>,
_settings: &'a (),
load_context: &'a mut LoadContext<'_>,
async fn load(
&self,
reader: &mut dyn Reader,
_settings: &(),
load_context: &mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
Expand Down
Loading

0 comments on commit d270246

Please sign in to comment.