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

Update bevy version, support AnimationOverride correctly

parent 0717a9dd
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file. ...@@ -4,6 +4,20 @@ 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/), 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). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.2.0]
### Added
- Constructor functions for `AnimationOverride`
### Changed
- `bevy` version `0.9`
- `bevy_ecs_tilemap` version `0.9`
- `AnimationOverride` now contains its own state
### Fixed
- `AnimationOverride` will play animation without needing to be driven by `apply_direction_animation`
## [0.1.1] ## [0.1.1]
### Fixed ### Fixed
......
[package] [package]
name = "micro_banimate" name = "micro_banimate"
version = "0.1.1" version = "0.2.0"
edition = "2021" edition = "2021"
license = "Apache-2.0" license = "Apache-2.0"
description = "Easily manage complex Bevy 2D sprite animations" description = "Easily manage complex Bevy 2D sprite animations"
...@@ -17,9 +17,9 @@ ecs_tilemap = ["dep:bevy_ecs_tilemap"] ...@@ -17,9 +17,9 @@ ecs_tilemap = ["dep:bevy_ecs_tilemap"]
serde = ["dep:serde"] serde = ["dep:serde"]
[dependencies] [dependencies]
anyhow = "1.0.65" anyhow = "^1.0.65"
serde = { version = "1.0.145", optional = true } serde = { version = "^1.0.145", optional = true }
serde_json = { version = "1.0.85", optional = true } serde_json = { version = "^1.0.85", optional = true }
toml = { version = "0.5.9", optional = true } toml = { version = "^0.5.9", optional = true }
bevy = { version = "0.8.1", default-features = false, features = ["bevy_asset", "render"] } bevy = { version = "^0.9.0", default-features = false, features = ["bevy_asset", "render"] }
bevy_ecs_tilemap = { version = "0.7.0", optional = true } bevy_ecs_tilemap = { version = "^0.9.0", optional = true }
...@@ -116,4 +116,11 @@ frame_time = 250 ...@@ -116,4 +116,11 @@ frame_time = 250
[shoot_right] [shoot_right]
frames = [34, 34, 34, 35, 36] frames = [34, 34, 34, 35, 36]
frame_time = 100 frame_time = 100
``` ```
\ No newline at end of file
## Compatibility
| banimate version | bevy version | tilemap version |
|------------------|--------------|-----------------|
| 0.2.x | 0.9 | 0.9 |
| 0.1.x | 0.8 | 0.8 |
...@@ -194,13 +194,54 @@ impl SimpleAnimationBundle { ...@@ -194,13 +194,54 @@ impl SimpleAnimationBundle {
} }
} }
#[derive(Clone, Debug, Component, PartialEq, Eq, PartialOrd, Ord, Default)] #[derive(Clone, Debug, Component, PartialEq, PartialOrd, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AnimationOverride { pub struct AnimationOverride {
pub name: String, pub name: String,
pub frame_step: usize,
pub frame_time: f32,
pub user_data: u128, pub user_data: u128,
} }
impl AnimationOverride {
pub fn new(name: String) -> Self {
Self {
name,
frame_time: 0.0,
frame_step: 0,
user_data: 0,
}
}
pub fn new_with_user_data(name: String, user_data: u128) -> Self {
Self {
name,
user_data,
frame_step: 0,
frame_time: 0.0,
}
}
}
pub struct OverrideStatus(pub AnimationStatus);
impl From<AnimationStatus> for OverrideStatus {
fn from(other: AnimationStatus) -> Self {
Self(other)
}
}
impl Deref for OverrideStatus {
type Target = AnimationStatus;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for OverrideStatus {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
#[derive(Clone, Debug, Bundle, PartialEq, PartialOrd, Default)] #[derive(Clone, Debug, Bundle, PartialEq, PartialOrd, Default)]
pub struct ChildAnimationBundle { pub struct ChildAnimationBundle {
pub animation_handle: Handle<AnimationSet>, pub animation_handle: Handle<AnimationSet>,
......
...@@ -11,10 +11,16 @@ mod plugin { ...@@ -11,10 +11,16 @@ mod plugin {
pub struct BanimatePluginGroup; pub struct BanimatePluginGroup;
impl PluginGroup for BanimatePluginGroup { impl PluginGroup for BanimatePluginGroup {
fn build(&mut self, group: &mut PluginGroupBuilder) { fn build(self) -> PluginGroupBuilder {
group.add(super::systems::AnimationSystemsPlugin); let mut group =
PluginGroupBuilder::start::<Self>().add(super::systems::AnimationSystemsPlugin);
#[cfg(any(feature = "json_loader", feature = "toml_loader"))] #[cfg(any(feature = "json_loader", feature = "toml_loader"))]
group.add(loader::AnimationLoadersPlugin); {
group = group.add(loader::AnimationLoadersPlugin);
}
group
} }
} }
} }
......
...@@ -50,7 +50,7 @@ pub struct AnimationQuery<'w, 's> { ...@@ -50,7 +50,7 @@ pub struct AnimationQuery<'w, 's> {
), ),
>, >,
direction: Query<'w, 's, &'static mut Directionality>, direction: Query<'w, 's, &'static mut Directionality>,
action_animation: Query<'w, 's, &'static AnimationOverride>, action_animation: Query<'w, 's, &'static mut AnimationOverride>,
tile_sprite: Query<'w, 's, &'static mut TextureAtlasSprite>, tile_sprite: Query<'w, 's, &'static mut TextureAtlasSprite>,
paused: Query<'w, 's, Entity, With<AnimationPaused>>, paused: Query<'w, 's, Entity, With<AnimationPaused>>,
events: EventWriter<'w, 's, AnimationCompleted>, events: EventWriter<'w, 's, AnimationCompleted>,
...@@ -259,55 +259,74 @@ impl<'w, 's> AnimationQuery<'w, 's> { ...@@ -259,55 +259,74 @@ impl<'w, 's> AnimationQuery<'w, 's> {
if self.paused.get(entity).is_ok() { if self.paused.get(entity).is_ok() {
continue; continue;
} }
let sheet = match self.animations.get(handle) { let sheet = match self.animations.get(handle) {
Some(sheet) => sheet, Some(sheet) => sheet,
None => continue, None => continue,
}; };
let mut current = match sheet.get(&status.active_name) { if let Ok(mut status) = self.action_animation.get_mut(entity) {
Some(set) => set, let current = match sheet.get(&status.name) {
None => continue, Some(set) => set,
}; None => {
self.commands.entity(entity).remove::<AnimationOverride>();
status.frame_time += dt; continue;
while status.frame_time >= current.frame_secs {
status.frame_time -= current.frame_secs;
status.active_step += 1;
}
if status.active_step >= current.frames.len() {
match mode.clone() {
AnimationMode::Loop => {
status.active_step = 0;
}
AnimationMode::Once => {
status.active_step = current.frames.len() - 1;
}
AnimationMode::OnceThenPlay(next) => {
*mode = AnimationMode::Loop;
status.active_name = next.clone();
status.frame_time = 0.0;
status.active_step = 0;
current = match sheet.get(&status.active_name) {
Some(set) => set,
None => continue,
};
} }
};
status.frame_time += dt;
while status.frame_time >= current.frame_secs {
status.frame_time -= current.frame_secs;
status.frame_step += 1;
} }
if let Ok(action_anim) = self.action_animation.get(entity) { if status.frame_step >= current.frames.len() {
self.commands.entity(entity).remove::<AnimationOverride>(); self.commands.entity(entity).remove::<AnimationOverride>();
self.events.send(AnimationCompleted { self.events.send(AnimationCompleted {
entity, entity,
user_data: action_anim.user_data, user_data: status.user_data,
}); });
} }
}
if let Ok(mut sprite) = self.tile_sprite.get_mut(entity) { if let Ok(mut sprite) = self.tile_sprite.get_mut(entity) {
sprite.index = current.frames[status.active_step]; sprite.index = current.frames[status.frame_step];
}
} else {
let mut current = match sheet.get(&status.active_name) {
Some(set) => set,
None => continue,
};
status.frame_time += dt;
while status.frame_time >= current.frame_secs {
status.frame_time -= current.frame_secs;
status.active_step += 1;
}
if status.active_step >= current.frames.len() {
match mode.clone() {
AnimationMode::Loop => {
status.active_step = 0;
}
AnimationMode::Once => {
status.active_step = current.frames.len() - 1;
}
AnimationMode::OnceThenPlay(next) => {
*mode = AnimationMode::Loop;
status.active_name = next.clone();
status.frame_time = 0.0;
status.active_step = 0;
current = match sheet.get(&status.active_name) {
Some(set) => set,
None => continue,
};
}
}
}
if let Ok(mut sprite) = self.tile_sprite.get_mut(entity) {
sprite.index = current.frames[status.active_step];
}
} }
} }
......
...@@ -58,7 +58,7 @@ pub fn tick_simple_tilemap_animation( ...@@ -58,7 +58,7 @@ pub fn tick_simple_tilemap_animation(
( (
&SimpleLoopedAnimation, &SimpleLoopedAnimation,
&mut SimpleLoopedAnimationStatus, &mut SimpleLoopedAnimationStatus,
&mut bevy_ecs_tilemap::tiles::TileTexture, &mut bevy_ecs_tilemap::tiles::TileTextureIndex,
), ),
With<HasSimpleAnimations>, With<HasSimpleAnimations>,
>, >,
...@@ -74,7 +74,8 @@ pub fn tick_simple_tilemap_animation( ...@@ -74,7 +74,8 @@ pub fn tick_simple_tilemap_animation(
} }
} }
*tile = bevy_ecs_tilemap::tiles::TileTexture(animation.frames[state.active_step] as u32); *tile =
bevy_ecs_tilemap::tiles::TileTextureIndex(animation.frames[state.active_step] as u32);
} }
} }
......
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