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]
name = "micro_ldtk"
version = "0.9.1"
version = "0.10.0"
edition = "2021"
authors = [
......@@ -34,7 +34,7 @@ _optional_tile_list = []
no_panic = []
[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"
thiserror = "1.0"
......
......@@ -38,6 +38,7 @@ corresponding version of LDTK and save it again.
| 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_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) |
......
use bevy::ecs::query::ReadOnlyWorldQuery;
use bevy::ecs::query::QueryFilter;
use bevy::ecs::system::SystemParam;
use bevy::prelude::*;
use crate::MapQuery;
pub fn lock_camera_to_level<CameraSelector: ReadOnlyWorldQuery>(
pub fn lock_camera_to_level<CameraSelector: QueryFilter>(
map_query: MapQuery,
mut camera_query: Query<(&mut Transform, &OrthographicProjection), CameraSelector>,
) {
......@@ -30,11 +30,11 @@ pub fn lock_camera_to_level<CameraSelector: ReadOnlyWorldQuery>(
}
#[derive(SystemParam)]
pub struct CameraBounder<'w, 's, Filter: ReadOnlyWorldQuery + 'static> {
pub struct CameraBounder<'w, 's, Filter: QueryFilter + 'static> {
map_query: MapQuery<'w>,
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> {
if let Some(bounds) = self.map_query.get_camera_bounds() {
if let Ok(proj) = self.query.get_single() {
......
......@@ -24,7 +24,7 @@ use bevy::asset::{
AssetLoader, AsyncReadExt, BoxedFuture, LoadContext, UntypedAssetId, VisitAssetDependencies,
};
use bevy::prelude::{Asset, Handle};
use bevy::reflect::{TypePath, TypeUuid, Uuid};
use bevy::reflect::TypePath;
use crate::ldtk;
#[cfg(feature = "ldtk_1_0_0")]
......@@ -91,9 +91,6 @@ impl<'a> LdtkFromBytes<'a> for Project {}
impl_from_bytes!(Level);
impl_from_bytes!(Project);
impl TypeUuid for Project {
const TYPE_UUID: Uuid = Uuid::from_u128(87988914102923589138720617793417023455);
}
impl TypePath for Project {
fn type_path() -> &'static str {
"micro_ldtk::ldtk::Project"
......@@ -110,10 +107,6 @@ impl VisitAssetDependencies for Project {
impl Asset for Project {}
impl TypeUuid for Level {
const TYPE_UUID: Uuid = Uuid::from_u128(18486863672600588966868281477384349187);
}
impl TypePath for Level {
fn type_path() -> &'static str {
"micro_ld0tk::ldtk::Level"
......@@ -182,8 +175,7 @@ pub enum LdtkLoadError {
pub type LdtkProject = Project;
#[derive(Asset, TypePath, TypeUuid)]
#[uuid = "905609d0-8687-11ee-9e30-4705d421a1e2"]
#[derive(Asset, TypePath)]
pub(crate) struct LevelSet(pub Vec<Handle<Level>>);
#[derive(Default)]
......
......@@ -24,9 +24,9 @@ pub fn set_ldtk_tile_scale_f32(scale: f32) {
}
mod __plugin {
use bevy::ecs::query::QueryFilter;
use std::marker::PhantomData;
use bevy::ecs::query::ReadOnlyWorldQuery;
use bevy::prelude::*;
pub struct MicroLDTKPlugin;
......@@ -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 {
Self {
_p: PhantomData::default(),
}
}
}
impl<CameraFilter: ReadOnlyWorldQuery + Send + Sync + 'static> Default
impl<CameraFilter: QueryFilter + Send + Sync + 'static> Default
for MicroLDTKCameraPlugin<CameraFilter>
{
fn default() -> Self {
......@@ -69,10 +69,10 @@ mod __plugin {
}
}
pub struct MicroLDTKCameraPlugin<CameraFilter: ReadOnlyWorldQuery> {
pub struct MicroLDTKCameraPlugin<CameraFilter: QueryFilter> {
_p: PhantomData<CameraFilter>,
}
impl<CameraFilter: ReadOnlyWorldQuery + Send + Sync + 'static> Plugin
impl<CameraFilter: QueryFilter + Send + Sync + 'static> Plugin
for MicroLDTKCameraPlugin<CameraFilter>
{
fn build(&self, app: &mut App) {
......
use bevy::prelude::{Image, TextureAtlas};
use bevy::render::render_resource::TextureFormat;
use bevy::render::texture::TextureFormatPixelInfo;
use bevy::sprite::TextureAtlasLayout;
use crate::{
get_ldtk_tile_scale, Indexer, LdtkLayer, LdtkLevel, SuppliesImage, SuppliesTextureAtlas,
......@@ -11,7 +12,7 @@ pub fn write_layer_to_texture(
buffer: &mut [u8],
format: &TextureFormat,
image: &Image,
atlas: &TextureAtlas,
atlas: &TextureAtlasLayout,
) {
if !layer.has_tiles() {
return;
......@@ -65,7 +66,7 @@ pub fn write_map_to_texture(
buffer: &mut [u8],
format: &TextureFormat,
image: &Image,
atlas: &TextureAtlas,
atlas: &TextureAtlasLayout,
) {
for layer in level.layers() {
write_layer_to_texture(layer, buffer, format, image, atlas);
......@@ -121,12 +122,15 @@ impl Rasterise for LdtkLayer {
images: &impl SuppliesImage,
atlas: &impl SuppliesTextureAtlas,
) {
if let Some(atlas) = self
.infer_tileset_name()
.and_then(|tn| atlas.get_atlas_handle(tn))
.and_then(|hn| atlas.get_atlas(hn))
{
if let Some(image) = images.get_image(&atlas.texture) {
if let Some(tileset_name) = self.infer_tileset_name() {
let maybe_atlas = atlas
.get_atlas_handle(&tileset_name)
.and_then(|hn| atlas.get_atlas(hn));
let maybe_image = images
.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);
}
}
......
use bevy::prelude::{Handle, Image, TextureAtlas};
use bevy::prelude::{Handle, Image};
use bevy::sprite::TextureAtlasLayout;
pub trait SuppliesTextureAtlas {
fn get_atlas_handle(&self, name: impl ToString) -> Option<&Handle<TextureAtlas>>;
fn get_atlas(&self, name: &Handle<TextureAtlas>) -> Option<&TextureAtlas>;
fn get_atlas_handle(&self, name: impl ToString) -> Option<&Handle<TextureAtlasLayout>>;
fn get_atlas(&self, name: &Handle<TextureAtlasLayout>) -> Option<&TextureAtlasLayout>;
}
pub trait SuppliesImage {
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