diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a01ce5624ea76f3a6eec3f82df4e379a2b9553b..6e2a32b58a38b98fd5780129b6708040f25830a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.8.0] + +### Changed + +- Required Bevy version is not 0.13 + ## [0.7.0] ### Added diff --git a/Cargo.toml b/Cargo.toml index 4a38547a21ee818588e69c1fea7d96408be5b9de..0f2a73df538f1ea3abd0fcd06a6b9214ad00f8a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "micro_banimate" -version = "0.7.0" +version = "0.8.0" edition = "2021" license = "Apache-2.0" description = "Easily manage complex Bevy 2D sprite animations" @@ -21,12 +21,12 @@ toml_loader = ["serde", "dep:toml"] serde = ["dep:serde"] [dependencies] -anyhow = "^1.0.65" -serde = { version = "^1.0.145", optional = true } -serde_json = { version = "^1.0.85", optional = true } -toml = { version = "0.7.4", optional = true } -bevy = { version = "^0.12.0", default-features = false, features = ["bevy_asset", "bevy_sprite"] } +anyhow = "^1.0" +serde = { version = "^1.0", optional = true } +serde_json = { version = "^1.0", optional = true } +toml = { version = "0.8", optional = true } +bevy = { version = "^0.13.0", default-features = false, features = ["bevy_asset", "bevy_sprite"] } [dev_dependencies] -bevy = "0.12" +bevy = "0.13" log = "0.4" diff --git a/README.md b/README.md index 75381e463a72ec0f3aff423b262e3e3a3f88785c..decd95a238f73de5611a97dc73638f59a9792b05 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,7 @@ frame_time = 100 | banimate version | bevy version | tilemap version | |---------------------|--------------|------------------------------------------| +| 0.8.0 | 0.13 | n/a | | 0.7.0 | 0.12 | n/a | | 0.6.0-rc.1 | 0.11 | 55c15bfa43c7a9e2adef6b70007e92d699377454 | | 0.5.x | 0.10 | 0.10 | diff --git a/examples/basic.rs b/examples/basic.rs index 0cac19e0b3c70927fb0f25e8d17ddbf795b0500b..0b299fe5f5de3e184a521fbf5265fffab8d5041b 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -16,17 +16,18 @@ fn main() { #[derive(Default, Resource)] struct ExampleAssets { - spritesheet: Handle<TextureAtlas>, + atlas: Handle<TextureAtlasLayout>, + sprites: Handle<Image>, animations: Handle<AnimationSet>, } fn load_assets( mut commands: Commands, assets: Res<AssetServer>, - mut atlas: ResMut<Assets<TextureAtlas>>, + mut atlas: ResMut<Assets<TextureAtlasLayout>>, ) { - let atlas_handle = atlas.add(TextureAtlas::from_grid( - assets.load("character.png"), + let sprites = assets.load("character.png"); + let atlas = atlas.add(TextureAtlasLayout::from_grid( Vec2::new(48., 48.), 10, 6, @@ -36,7 +37,8 @@ fn load_assets( let anim_handle = assets.load("character.anim.json"); commands.insert_resource(ExampleAssets { - spritesheet: atlas_handle, + sprites, + atlas, animations: anim_handle, }); } @@ -47,7 +49,11 @@ fn spawn_assets(mut commands: Commands, assets: Res<ExampleAssets>) { commands.spawn(( SpriteSheetBundle { - texture_atlas: assets.spritesheet.clone_weak(), + texture: assets.sprites.clone_weak(), + atlas: TextureAtlas { + layout: assets.atlas.clone_weak(), + index: 0, + }, ..Default::default() }, DirectionalAnimationBundle::with_direction( @@ -73,23 +79,23 @@ fn spawn_assets(mut commands: Commands, assets: Res<ExampleAssets>) { } fn process_input( - input: Res<Input<KeyCode>>, + input: Res<ButtonInput<KeyCode>>, mut status_query: Query<(&mut AnimationStatus, &mut Directionality)>, ) { for (mut status, mut direction) in &mut status_query { - if input.just_released(KeyCode::Left) { + if input.just_released(KeyCode::ArrowLeft) { direction.with_horizontal(Horizontal::Left); } - if input.just_released(KeyCode::Right) { + if input.just_released(KeyCode::ArrowRight) { direction.with_horizontal(Horizontal::Right); } - if input.just_released(KeyCode::Key1) { + if input.just_released(KeyCode::Digit1) { status.start_or_continue("idle"); } - if input.just_released(KeyCode::Key2) { + if input.just_released(KeyCode::Digit2) { status.start_or_continue("run"); } } diff --git a/src/definitions.rs b/src/definitions.rs index 8ab40ab591db467d5630d621dce87569a50dced0..5a2b43b3cc8060d5353fcc3cbcc8d606068b9788 100644 --- a/src/definitions.rs +++ b/src/definitions.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use std::time::Duration; use bevy::prelude::*; -use bevy::reflect::TypeUuid; +use bevy::reflect::TypePath; use crate::directionality::Directionality; @@ -19,13 +19,12 @@ impl AnimationFrames { } } -#[derive(Clone, Debug, TypeUuid, TypePath, PartialEq, Default, Deref, DerefMut, Asset)] +#[derive(Clone, Debug, TypePath, PartialEq, Default, Deref, DerefMut, Asset)] #[cfg_attr( feature = "serde", derive(serde::Serialize, serde::Deserialize), serde(transparent) )] -#[uuid = "a2823f96-0f63-434e-9030-d8f762898a18"] pub struct AnimationSet(pub HashMap<String, AnimationFrames>); #[derive(Copy, Clone, Debug, Component, PartialEq, Eq, Default)] diff --git a/src/query.rs b/src/query.rs index 630b8cfbf9b2fed67849b20a99025981b2bde9c3..3898590359b774a0ddbc23a2f55ec51323a1e66b 100644 --- a/src/query.rs +++ b/src/query.rs @@ -5,70 +5,66 @@ use crate::definitions::{ use crate::directionality::Directionality; use crate::systems::AnimationCompleted; use bevy::asset::Assets; -use bevy::ecs::query::WorldQuery; +use bevy::ecs::query::{QueryData, QueryFilter}; use bevy::prelude::{ Commands, Entity, EventWriter, Handle, Parent, Query, Res, Time, With, Without, }; -use bevy::sprite::TextureAtlasSprite; +use bevy::sprite::TextureAtlas; -#[derive(WorldQuery)] -#[world_query(mutable)] +#[derive(QueryData)] +#[query_data(mutable)] pub struct AnimationComponents { handle: &'static Handle<AnimationSet>, status: &'static mut AnimationStatus, - sprite: &'static mut TextureAtlasSprite, + atlas: &'static mut TextureAtlas, } -#[derive(WorldQuery)] -#[world_query(mutable)] +#[derive(QueryData)] +#[query_data(mutable)] pub struct DirectionalAnimationComponents { handle: &'static Handle<AnimationSet>, direction: &'static Directionality, status: &'static mut AnimationStatus, - sprite: &'static mut TextureAtlasSprite, + atlas: &'static mut TextureAtlas, } -#[derive(WorldQuery)] -#[world_query(mutable)] +#[derive(QueryData)] +#[query_data(mutable)] pub struct OverrideAnimationComponents { handle: &'static Handle<AnimationSet>, data: Option<&'static OverrideData>, status: &'static mut AnimationOverride, - sprite: &'static mut TextureAtlasSprite, + atlas: &'static mut TextureAtlas, } -#[derive(WorldQuery)] -#[world_query(mutable)] +#[derive(QueryData)] +#[query_data(mutable)] pub struct SimpleAnimationComponents { anim: &'static SimpleAnimation, status: &'static mut SimpleAnimationStatus, - sprite: &'static mut TextureAtlasSprite, + atlas: &'static mut TextureAtlas, } - -#[derive(WorldQuery)] +#[derive(QueryFilter)] pub struct OnlyAnimations { _status: With<AnimationStatus>, _override: Without<AnimationOverride>, _direction: Without<Directionality>, _paused: Without<AnimationPaused>, } - -#[derive(WorldQuery)] +#[derive(QueryFilter)] pub struct OnlyDirectionalAnimations { _status: With<AnimationStatus>, _direction: With<Directionality>, _override: Without<AnimationOverride>, _paused: Without<AnimationPaused>, } - -#[derive(WorldQuery)] +#[derive(QueryFilter)] pub struct OnlyOverrideAnimations { _override: With<AnimationOverride>, _direction: Without<Directionality>, _paused: Without<AnimationPaused>, } - -#[derive(WorldQuery)] +#[derive(QueryFilter)] pub struct OnlyDirectionalOverrideAnimations { _override: With<AnimationOverride>, _direction: With<Directionality>, @@ -97,8 +93,8 @@ macro_rules! get_current_anim { } macro_rules! tick_animation { - ($delta: expr, $anim: expr, $status: expr, $sprite: expr) => {{ - let current_frame = $sprite.index; + ($delta: expr, $anim: expr, $status: expr, $atlas: expr) => {{ + let current_frame = $atlas.index; let mut has_looped = false; $status.frame_time += $delta.as_secs_f32(); @@ -114,7 +110,7 @@ macro_rules! tick_animation { } if current_frame != $anim.frames[$status.active_step] { - $sprite.index = $anim.frames[$status.active_step]; + $atlas.index = $anim.frames[$status.active_step]; } has_looped @@ -130,11 +126,11 @@ pub fn play_animations( for AnimationComponentsItem { mut status, handle, - mut sprite, + mut atlas, } in &mut anim_query { let anim = get_current_anim!(animations, handle, status.active_name); - tick_animation!(delta, anim, status, sprite); + tick_animation!(delta, anim, status, atlas); } } @@ -147,7 +143,7 @@ pub fn play_directional_animations( for DirectionalAnimationComponentsItem { mut status, handle, - mut sprite, + mut atlas, direction, } in &mut anim_query { @@ -158,7 +154,7 @@ pub fn play_directional_animations( status.active_name ); - tick_animation!(delta, anim, status, sprite); + tick_animation!(delta, anim, status, atlas); } } @@ -175,13 +171,13 @@ pub fn play_override_animation( OverrideAnimationComponentsItem { mut status, handle, - mut sprite, + mut atlas, data, }, ) in &mut anim_query { let anim = get_current_anim!(animations, handle, status.active_name); - let looped = tick_animation!(delta, anim, status, sprite); + let looped = tick_animation!(delta, anim, status, atlas); if looped { commands .entity(entity) @@ -204,17 +200,17 @@ pub fn play_simple_animation( let delta = time.delta(); for SimpleAnimationComponentsItem { mut status, - mut sprite, + mut atlas, anim, } in &mut anim_query { - tick_animation!(delta, *anim, status, sprite); + tick_animation!(delta, *anim, status, atlas); } } pub fn sync_child_animation( - mut children: Query<(&Parent, &mut TextureAtlasSprite), With<SyncToParent>>, - parents: Query<&TextureAtlasSprite, Without<SyncToParent>>, + mut children: Query<(&Parent, &mut TextureAtlas), With<SyncToParent>>, + parents: Query<&TextureAtlas, Without<SyncToParent>>, ) { for (parent, mut child_sprite) in &mut children { if let Ok(parent_sprite) = parents.get(**parent) {