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

Update to bevy 0.13

parent 47c68544
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
[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"
......@@ -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 |
......
......@@ -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");
}
}
......
......@@ -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)]
......
......@@ -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) {
......
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