Skip to content

Commit

Permalink
Merge pull request #37 from brandon-reinhart/bevy_main
Browse files Browse the repository at this point in the history
update to bevy 0.14
  • Loading branch information
NiklasEi authored Jul 4, 2024
2 parents b6316a7 + 94cddb4 commit 090fe83
Show file tree
Hide file tree
Showing 20 changed files with 101 additions and 117 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v0.11.0 - 04.07.2024
- Update to Bevy 0.14

## v0.10.0 - 17.02.2024
- Update to Bevy 0.13

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.10.0"
version = "0.11.0"
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.13", default-features = false, features = ["bevy_asset"] }
bevy = { version = "0.14", 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.31", features = [ "serialize" ], optional = true }
quick-xml = { version = "0.34", features = [ "serialize" ], optional = true }
serde = { version = "1" }
anyhow = { version = "1" }
postcard = {version = "1.0", features = ["use-std"], optional = true}

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

[package.metadata.docs.rs]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Compatibility of `bevy_common_assets` versions:

| `bevy_common_assets` | `bevy` |
|:---------------------|:-------|
| `0.11` | `0.14` |
| `0.10` | `0.13` |
| `0.8` - `0.9` | `0.12` |
| `0.7` | `0.11` |
Expand Down
2 changes: 1 addition & 1 deletion examples/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn main() {
.init_state::<AppState>()
.add_systems(Startup, setup)
.add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))
.run()
.run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
Expand Down
2 changes: 1 addition & 1 deletion examples/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn main() {
.init_state::<AppState>()
.add_systems(Startup, setup)
.add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))
.run()
.run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
Expand Down
2 changes: 1 addition & 1 deletion examples/msgpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn main() {
.init_state::<AppState>()
.add_systems(Startup, setup)
.add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))
.run()
.run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
Expand Down
2 changes: 1 addition & 1 deletion examples/postcard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn main() {
.init_state::<AppState>()
.add_systems(Startup, setup)
.add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))
.run()
.run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
Expand Down
2 changes: 1 addition & 1 deletion examples/ron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() {
.init_state::<AppState>()
.add_systems(Startup, setup)
.add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))
.run()
.run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
Expand Down
2 changes: 1 addition & 1 deletion examples/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn main() {
.init_state::<AppState>()
.add_systems(Startup, setup)
.add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))
.run()
.run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
Expand Down
2 changes: 1 addition & 1 deletion examples/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() {
.init_state::<AppState>()
.add_systems(Startup, setup)
.add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))
.run()
.run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
Expand Down
2 changes: 1 addition & 1 deletion examples/yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn main() {
.init_state::<AppState>()
.add_systems(Startup, setup)
.add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))
.run()
.run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
Expand Down
35 changes: 16 additions & 19 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, BoxedFuture, Handle, LoadContext};
use bevy::asset::{Asset, AssetApp, AssetLoader, AsyncReadExt, Handle, LoadContext};
use bevy::prelude::TypePath;
use std::marker::PhantomData;
use thiserror::Error;
Expand Down Expand Up @@ -99,26 +99,23 @@ where
type Settings = ();
type Error = CsvLoaderError;

fn load<'a>(
async fn load<'a>(
&'a self,
reader: &'a mut Reader,
reader: &'a mut Reader<'_>,
_settings: &'a (),
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
Box::pin(async move {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let mut reader = csv::ReaderBuilder::new()
.delimiter(self.delimiter)
.from_reader(bytes.as_slice());
let mut handles = vec![];
for (index, result) in reader.deserialize().enumerate() {
let asset: A = result?;
handles
.push(load_context.add_loaded_labeled_asset(index.to_string(), asset.into()));
}
Ok(LoadedCsv { rows: handles })
})
load_context: &'a mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let mut reader = csv::ReaderBuilder::new()
.delimiter(self.delimiter)
.from_reader(bytes.as_slice());
let mut handles = vec![];
for (index, result) in reader.deserialize().enumerate() {
let asset: A = result?;
handles.push(load_context.add_loaded_labeled_asset(index.to_string(), asset.into()));
}
Ok(LoadedCsv { rows: handles })
}

fn extensions(&self) -> &[&str] {
Expand Down
20 changes: 9 additions & 11 deletions src/json.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, BoxedFuture, LoadContext};
use bevy::asset::{Asset, AssetApp, AssetLoader, AsyncReadExt, LoadContext};
use serde_json::from_slice;
use std::marker::PhantomData;
use thiserror::Error;
Expand Down Expand Up @@ -63,18 +63,16 @@ where
type Settings = ();
type Error = JsonLoaderError;

fn load<'a>(
async fn load<'a>(
&'a self,
reader: &'a mut Reader,
reader: &'a mut Reader<'_>,
_settings: &'a (),
_load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
Box::pin(async move {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let asset = from_slice::<A>(&bytes)?;
Ok(asset)
})
_load_context: &'a mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let asset = from_slice::<A>(&bytes)?;
Ok(asset)
}

fn extensions(&self) -> &[&str] {
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//! # .init_asset::<Level>()
//! .add_systems(Startup, load_level)
//! # .add_systems(Update, stop)
//! .run()
//! .run();
//! }
//!
//! fn load_level(mut commands: Commands, asset_server: Res<AssetServer>) {
Expand All @@ -40,7 +40,7 @@
//! struct LevelAsset(Handle<Level>);
//!
//! # fn stop(mut events: EventWriter<AppExit>) {
//! # events.send(AppExit);
//! # events.send(AppExit::Success);
//! # }
//! ```

Expand Down
20 changes: 9 additions & 11 deletions src/msgpack.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, BoxedFuture, LoadContext};
use bevy::asset::{Asset, AssetApp, AssetLoader, AsyncReadExt, LoadContext};
use rmp_serde::from_slice;
use std::marker::PhantomData;
use thiserror::Error;
Expand Down Expand Up @@ -63,18 +63,16 @@ where
type Settings = ();
type Error = MsgPackLoaderError;

fn load<'a>(
async fn load<'a>(
&'a self,
reader: &'a mut Reader,
reader: &'a mut Reader<'_>,
_settings: &'a (),
_load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
Box::pin(async move {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let asset = from_slice::<A>(&bytes)?;
Ok(asset)
})
_load_context: &'a mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let asset = from_slice::<A>(&bytes)?;
Ok(asset)
}

fn extensions(&self) -> &[&str] {
Expand Down
31 changes: 13 additions & 18 deletions src/postcard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use bevy::{
LoadContext,
},
prelude::*,
utils::{thiserror, BoxedFuture},
};
use postcard::{from_bytes, to_stdvec};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -70,18 +69,16 @@ where
type Settings = ();
type Error = PostcardAssetError;

fn load<'a>(
async fn load<'a>(
&'a self,
reader: &'a mut Reader,
reader: &'a mut Reader<'_>,
_settings: &'a (),
_load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
Box::pin(async move {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let asset = from_bytes::<A>(&bytes)?;
Ok(asset)
})
_load_context: &'a mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let asset = from_bytes::<A>(&bytes)?;
Ok(asset)
}

fn extensions(&self) -> &[&str] {
Expand All @@ -108,16 +105,14 @@ impl<A: Asset + for<'de> Deserialize<'de> + Serialize> AssetSaver for PostcardAs
type OutputLoader = PostcardAssetLoader<A>;
type Error = PostcardAssetError;

fn save<'a>(
async fn save<'a>(
&'a self,
writer: &'a mut bevy::asset::io::Writer,
asset: bevy::asset::saver::SavedAsset<'a, Self::Asset>,
_settings: &'a Self::Settings,
) -> BoxedFuture<'a, Result<<Self::OutputLoader as AssetLoader>::Settings, Self::Error>> {
Box::pin(async move {
let bytes = to_stdvec(&asset.get())?;
writer.write_all(&bytes).await?;
Ok(())
})
) -> Result<<Self::OutputLoader as AssetLoader>::Settings, Self::Error> {
let bytes = to_stdvec(&asset.get())?;
writer.write_all(&bytes).await?;
Ok(())
}
}
20 changes: 9 additions & 11 deletions src/ron.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, BoxedFuture, LoadContext};
use bevy::asset::{Asset, AssetApp, AssetLoader, AsyncReadExt, LoadContext};
use serde_ron::de::from_bytes;
use std::marker::PhantomData;
use thiserror::Error;
Expand Down Expand Up @@ -63,18 +63,16 @@ where
type Settings = ();
type Error = RonLoaderError;

fn load<'a>(
async fn load<'a>(
&'a self,
reader: &'a mut Reader,
reader: &'a mut Reader<'_>,
_settings: &'a (),
_load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
Box::pin(async move {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let asset = from_bytes::<A>(&bytes)?;
Ok(asset)
})
_load_context: &'a mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let asset = from_bytes::<A>(&bytes)?;
Ok(asset)
}

fn extensions(&self) -> &[&str] {
Expand Down
20 changes: 9 additions & 11 deletions src/toml.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, BoxedFuture, LoadContext};
use bevy::asset::{Asset, AssetApp, AssetLoader, AsyncReadExt, LoadContext};
use std::marker::PhantomData;
use std::str::from_utf8;
use thiserror::Error;
Expand Down Expand Up @@ -66,18 +66,16 @@ where
type Settings = ();
type Error = TomlLoaderError;

fn load<'a>(
async fn load<'a>(
&'a self,
reader: &'a mut Reader,
reader: &'a mut Reader<'_>,
_settings: &'a (),
_load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
Box::pin(async move {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let asset = serde_toml::from_str::<A>(from_utf8(&bytes)?)?;
Ok(asset)
})
_load_context: &'a mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let asset = serde_toml::from_str::<A>(from_utf8(&bytes)?)?;
Ok(asset)
}

fn extensions(&self) -> &[&str] {
Expand Down
Loading

0 comments on commit 090fe83

Please sign in to comment.