From 6c87a1e4b64396065f05dbc7e28bc92da224caae Mon Sep 17 00:00:00 2001
From: Louis Capitanchik <contact@louiscap.co>
Date: Tue, 10 Jan 2023 03:46:53 +0000
Subject: [PATCH] Handle directional overrides correctly

---
 Cargo.toml   |  2 +-
 src/query.rs | 14 +++++++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index 0a4864c..f2b55b8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "micro_banimate"
-version = "0.2.1"
+version = "0.3.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 f9bce48..c619e63 100644
--- a/src/query.rs
+++ b/src/query.rs
@@ -265,10 +265,22 @@ impl<'w, 's> AnimationQuery<'w, 's> {
 			};
 
 			if let Ok(mut status) = self.action_animation.get_mut(entity) {
-				let current = match sheet.get(&status.name) {
+				let (a, b) = match self.direction.get(entity) {
+					Ok(dir) => {
+						let directional = format!("{}_{}", status.name, dir);
+						(directional, status.name.clone())
+					}
+					Err(_) => (status.name.clone(), status.name.clone()),
+				};
+
+				let current = match sheet.get(&a).or_else(|| sheet.get(&b)) {
 					Some(set) => set,
 					None => {
 						self.commands.entity(entity).remove::<AnimationOverride>();
+						self.events.send(AnimationCompleted {
+							entity,
+							user_data: status.user_data,
+						});
 						continue;
 					}
 				};
-- 
GitLab