Skip to content
Snippets Groups Projects
Verified Commit aec837fd authored by Louis's avatar Louis :fire:
Browse files

Update to Bevy 0.13

parent dec7660f
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
[package] [package]
name = "micro_ldtk" name = "micro_ldtk"
version = "0.9.1" version = "0.10.0"
edition = "2021" edition = "2021"
authors = [ authors = [
...@@ -34,7 +34,7 @@ _optional_tile_list = [] ...@@ -34,7 +34,7 @@ _optional_tile_list = []
no_panic = [] no_panic = []
[dependencies] [dependencies]
bevy = { version = "0.12", default-features = false, features = ["bevy_render", "bevy_sprite", "bevy_asset"] } bevy = { version = "0.13", default-features = false, features = ["bevy_render", "bevy_sprite", "bevy_asset"] }
anyhow = "1.0" anyhow = "1.0"
thiserror = "1.0" thiserror = "1.0"
......
...@@ -38,6 +38,7 @@ corresponding version of LDTK and save it again. ...@@ -38,6 +38,7 @@ corresponding version of LDTK and save it again.
| Feature Flag | Uses Schema Version | | Feature Flag | Uses Schema Version |
|----------------------------|-------------------------------------------------------------------------------| |----------------------------|-------------------------------------------------------------------------------|
| `ldtk_1_5_3` | [v1.5.3](https://github.com/deepnight/ldtk/blob/v1.5.3/docs/JSON_SCHEMA.json) |
| `ldtk_1_4_0`, `ldtk_1_4_1` | [v1.4.0](https://github.com/deepnight/ldtk/blob/v1.4.0/docs/JSON_SCHEMA.json) | | `ldtk_1_4_0`, `ldtk_1_4_1` | [v1.4.0](https://github.com/deepnight/ldtk/blob/v1.4.0/docs/JSON_SCHEMA.json) |
| `ldtk_1_3_0` | [v1.3.0](https://github.com/deepnight/ldtk/blob/v1.3.0/docs/JSON_SCHEMA.json) | | `ldtk_1_3_0` | [v1.3.0](https://github.com/deepnight/ldtk/blob/v1.3.0/docs/JSON_SCHEMA.json) |
| `ldtk_1_2_5` | [v1.2.5](https://github.com/deepnight/ldtk/blob/v1.2.5/docs/JSON_SCHEMA.json) | | `ldtk_1_2_5` | [v1.2.5](https://github.com/deepnight/ldtk/blob/v1.2.5/docs/JSON_SCHEMA.json) |
......
use bevy::ecs::query::ReadOnlyWorldQuery; use bevy::ecs::query::QueryFilter;
use bevy::ecs::system::SystemParam; use bevy::ecs::system::SystemParam;
use bevy::prelude::*; use bevy::prelude::*;
use crate::MapQuery; use crate::MapQuery;
pub fn lock_camera_to_level<CameraSelector: ReadOnlyWorldQuery>( pub fn lock_camera_to_level<CameraSelector: QueryFilter>(
map_query: MapQuery, map_query: MapQuery,
mut camera_query: Query<(&mut Transform, &OrthographicProjection), CameraSelector>, mut camera_query: Query<(&mut Transform, &OrthographicProjection), CameraSelector>,
) { ) {
...@@ -30,11 +30,11 @@ pub fn lock_camera_to_level<CameraSelector: ReadOnlyWorldQuery>( ...@@ -30,11 +30,11 @@ pub fn lock_camera_to_level<CameraSelector: ReadOnlyWorldQuery>(
} }
#[derive(SystemParam)] #[derive(SystemParam)]
pub struct CameraBounder<'w, 's, Filter: ReadOnlyWorldQuery + 'static> { pub struct CameraBounder<'w, 's, Filter: QueryFilter + 'static> {
map_query: MapQuery<'w>, map_query: MapQuery<'w>,
query: Query<'w, 's, &'static OrthographicProjection, Filter>, query: Query<'w, 's, &'static OrthographicProjection, Filter>,
} }
impl<'w, 's, Filter: ReadOnlyWorldQuery + 'static> CameraBounder<'w, 's, Filter> { impl<'w, 's, Filter: QueryFilter + 'static> CameraBounder<'w, 's, Filter> {
pub fn get_extremeties(&self) -> Option<Rect> { pub fn get_extremeties(&self) -> Option<Rect> {
if let Some(bounds) = self.map_query.get_camera_bounds() { if let Some(bounds) = self.map_query.get_camera_bounds() {
if let Ok(proj) = self.query.get_single() { if let Ok(proj) = self.query.get_single() {
......
...@@ -24,7 +24,7 @@ use bevy::asset::{ ...@@ -24,7 +24,7 @@ use bevy::asset::{
AssetLoader, AsyncReadExt, BoxedFuture, LoadContext, UntypedAssetId, VisitAssetDependencies, AssetLoader, AsyncReadExt, BoxedFuture, LoadContext, UntypedAssetId, VisitAssetDependencies,
}; };
use bevy::prelude::{Asset, Handle}; use bevy::prelude::{Asset, Handle};
use bevy::reflect::{TypePath, TypeUuid, Uuid}; use bevy::reflect::TypePath;
use crate::ldtk; use crate::ldtk;
#[cfg(feature = "ldtk_1_0_0")] #[cfg(feature = "ldtk_1_0_0")]
...@@ -91,9 +91,6 @@ impl<'a> LdtkFromBytes<'a> for Project {} ...@@ -91,9 +91,6 @@ impl<'a> LdtkFromBytes<'a> for Project {}
impl_from_bytes!(Level); impl_from_bytes!(Level);
impl_from_bytes!(Project); impl_from_bytes!(Project);
impl TypeUuid for Project {
const TYPE_UUID: Uuid = Uuid::from_u128(87988914102923589138720617793417023455);
}
impl TypePath for Project { impl TypePath for Project {
fn type_path() -> &'static str { fn type_path() -> &'static str {
"micro_ldtk::ldtk::Project" "micro_ldtk::ldtk::Project"
...@@ -110,10 +107,6 @@ impl VisitAssetDependencies for Project { ...@@ -110,10 +107,6 @@ impl VisitAssetDependencies for Project {
impl Asset for Project {} impl Asset for Project {}
impl TypeUuid for Level {
const TYPE_UUID: Uuid = Uuid::from_u128(18486863672600588966868281477384349187);
}
impl TypePath for Level { impl TypePath for Level {
fn type_path() -> &'static str { fn type_path() -> &'static str {
"micro_ld0tk::ldtk::Level" "micro_ld0tk::ldtk::Level"
...@@ -182,8 +175,7 @@ pub enum LdtkLoadError { ...@@ -182,8 +175,7 @@ pub enum LdtkLoadError {
pub type LdtkProject = Project; pub type LdtkProject = Project;
#[derive(Asset, TypePath, TypeUuid)] #[derive(Asset, TypePath)]
#[uuid = "905609d0-8687-11ee-9e30-4705d421a1e2"]
pub(crate) struct LevelSet(pub Vec<Handle<Level>>); pub(crate) struct LevelSet(pub Vec<Handle<Level>>);
#[derive(Default)] #[derive(Default)]
......
...@@ -24,9 +24,9 @@ pub fn set_ldtk_tile_scale_f32(scale: f32) { ...@@ -24,9 +24,9 @@ pub fn set_ldtk_tile_scale_f32(scale: f32) {
} }
mod __plugin { mod __plugin {
use bevy::ecs::query::QueryFilter;
use std::marker::PhantomData; use std::marker::PhantomData;
use bevy::ecs::query::ReadOnlyWorldQuery;
use bevy::prelude::*; use bevy::prelude::*;
pub struct MicroLDTKPlugin; pub struct MicroLDTKPlugin;
...@@ -54,14 +54,14 @@ mod __plugin { ...@@ -54,14 +54,14 @@ mod __plugin {
} }
} }
impl<CameraFilter: ReadOnlyWorldQuery + Send + Sync + 'static> MicroLDTKCameraPlugin<CameraFilter> { impl<CameraFilter: QueryFilter + Send + Sync + 'static> MicroLDTKCameraPlugin<CameraFilter> {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
_p: PhantomData::default(), _p: PhantomData::default(),
} }
} }
} }
impl<CameraFilter: ReadOnlyWorldQuery + Send + Sync + 'static> Default impl<CameraFilter: QueryFilter + Send + Sync + 'static> Default
for MicroLDTKCameraPlugin<CameraFilter> for MicroLDTKCameraPlugin<CameraFilter>
{ {
fn default() -> Self { fn default() -> Self {
...@@ -69,10 +69,10 @@ mod __plugin { ...@@ -69,10 +69,10 @@ mod __plugin {
} }
} }
pub struct MicroLDTKCameraPlugin<CameraFilter: ReadOnlyWorldQuery> { pub struct MicroLDTKCameraPlugin<CameraFilter: QueryFilter> {
_p: PhantomData<CameraFilter>, _p: PhantomData<CameraFilter>,
} }
impl<CameraFilter: ReadOnlyWorldQuery + Send + Sync + 'static> Plugin impl<CameraFilter: QueryFilter + Send + Sync + 'static> Plugin
for MicroLDTKCameraPlugin<CameraFilter> for MicroLDTKCameraPlugin<CameraFilter>
{ {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
......
use bevy::prelude::{Image, TextureAtlas}; use bevy::prelude::{Image, TextureAtlas};
use bevy::render::render_resource::TextureFormat; use bevy::render::render_resource::TextureFormat;
use bevy::render::texture::TextureFormatPixelInfo; use bevy::render::texture::TextureFormatPixelInfo;
use bevy::sprite::TextureAtlasLayout;
use crate::{ use crate::{
get_ldtk_tile_scale, Indexer, LdtkLayer, LdtkLevel, SuppliesImage, SuppliesTextureAtlas, get_ldtk_tile_scale, Indexer, LdtkLayer, LdtkLevel, SuppliesImage, SuppliesTextureAtlas,
...@@ -11,7 +12,7 @@ pub fn write_layer_to_texture( ...@@ -11,7 +12,7 @@ pub fn write_layer_to_texture(
buffer: &mut [u8], buffer: &mut [u8],
format: &TextureFormat, format: &TextureFormat,
image: &Image, image: &Image,
atlas: &TextureAtlas, atlas: &TextureAtlasLayout,
) { ) {
if !layer.has_tiles() { if !layer.has_tiles() {
return; return;
...@@ -65,7 +66,7 @@ pub fn write_map_to_texture( ...@@ -65,7 +66,7 @@ pub fn write_map_to_texture(
buffer: &mut [u8], buffer: &mut [u8],
format: &TextureFormat, format: &TextureFormat,
image: &Image, image: &Image,
atlas: &TextureAtlas, atlas: &TextureAtlasLayout,
) { ) {
for layer in level.layers() { for layer in level.layers() {
write_layer_to_texture(layer, buffer, format, image, atlas); write_layer_to_texture(layer, buffer, format, image, atlas);
...@@ -121,12 +122,15 @@ impl Rasterise for LdtkLayer { ...@@ -121,12 +122,15 @@ impl Rasterise for LdtkLayer {
images: &impl SuppliesImage, images: &impl SuppliesImage,
atlas: &impl SuppliesTextureAtlas, atlas: &impl SuppliesTextureAtlas,
) { ) {
if let Some(atlas) = self if let Some(tileset_name) = self.infer_tileset_name() {
.infer_tileset_name() let maybe_atlas = atlas
.and_then(|tn| atlas.get_atlas_handle(tn)) .get_atlas_handle(&tileset_name)
.and_then(|hn| atlas.get_atlas(hn)) .and_then(|hn| atlas.get_atlas(hn));
{ let maybe_image = images
if let Some(image) = images.get_image(&atlas.texture) { .get_image_handle(&tileset_name)
.and_then(|hn| images.get_image(hn));
if let Some((atlas, image)) = maybe_atlas.zip(maybe_image) {
write_layer_to_texture(self, buffer, format, image, atlas); write_layer_to_texture(self, buffer, format, image, atlas);
} }
} }
......
use bevy::prelude::{Handle, Image, TextureAtlas}; use bevy::prelude::{Handle, Image};
use bevy::sprite::TextureAtlasLayout;
pub trait SuppliesTextureAtlas { pub trait SuppliesTextureAtlas {
fn get_atlas_handle(&self, name: impl ToString) -> Option<&Handle<TextureAtlas>>; fn get_atlas_handle(&self, name: impl ToString) -> Option<&Handle<TextureAtlasLayout>>;
fn get_atlas(&self, name: &Handle<TextureAtlas>) -> Option<&TextureAtlas>; fn get_atlas(&self, name: &Handle<TextureAtlasLayout>) -> Option<&TextureAtlasLayout>;
} }
pub trait SuppliesImage { pub trait SuppliesImage {
fn get_image_handle(&self, name: impl ToString) -> Option<&Handle<Image>>; fn get_image_handle(&self, name: impl ToString) -> Option<&Handle<Image>>;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment