From 646f72059550f535cb6fad371a72f5af91f5d1b3 Mon Sep 17 00:00:00 2001 From: Louis Capitanchik <contact@louiscap.co> Date: Tue, 17 Jan 2023 15:19:20 +0000 Subject: [PATCH] Fix child animation desync with override --- CHANGELOG.md | 5 +++++ Cargo.toml | 2 +- src/query.rs | 36 ++++++++++++++++++++++++++++++------ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ef9b88..dd4fa22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ 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.3.1] + +### Fixed +- Child animations would not play correct animation when parent has an override + ## [0.2.1] ### Fixed diff --git a/Cargo.toml b/Cargo.toml index f2b55b8..5c780ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "micro_banimate" -version = "0.3.0" +version = "0.4.0" edition = "2021" license = "Apache-2.0" description = "Easily manage complex Bevy 2D sprite animations" diff --git a/src/query.rs b/src/query.rs index c619e63..01436f0 100644 --- a/src/query.rs +++ b/src/query.rs @@ -354,12 +354,36 @@ impl<'w, 's> AnimationQuery<'w, 's> { } if let Ok(mut sprite) = self.tile_sprite.get_mut(entity) { - if let Some(current) = self - .animations - .get(handle) - .and_then(|sheet| sheet.get(&status.active_name)) - { - sprite.index = current.frames[status.active_step]; + let (directional_name, active_name, frame) = + match self.action_animation.get_mut(**parent) { + Ok(override_status) => match self.direction.get(**parent) { + Ok(dir) => { + let directional = format!("{}_{}", override_status.name, dir); + ( + directional, + override_status.name.clone(), + override_status.frame_step, + ) + } + Err(_) => ( + override_status.name.clone(), + override_status.name.clone(), + override_status.frame_step, + ), + }, + Err(_) => ( + status.active_name.clone(), + status.active_name.clone(), + status.active_step, + ), + }; + + if let Some(current) = self.animations.get(handle).and_then(|sheet| { + sheet + .get(&directional_name) + .or_else(|| sheet.get(&active_name)) + }) { + sprite.index = current.frames[frame]; } } } -- GitLab