From 6935fdc5d71a9f08af5c79aeb48b65c2e129c895 Mon Sep 17 00:00:00 2001
From: Louis Capitanchik <contact@louiscap.co>
Date: Fri, 14 Apr 2023 03:09:38 +0100
Subject: [PATCH] Update ecs_tilemap dep, re-enable ecs_tilemap

---
 CHANGELOG.md   |  7 ++++++
 Cargo.toml     |  6 ++---
 README.md      |  2 +-
 src/query.rs   |  4 +--
 src/systems.rs | 66 ++++++++++++++++++++++++++------------------------
 5 files changed, 46 insertions(+), 39 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index dd4fa22..6d97984 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,13 @@ 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).
 
+## [Unreleased]
+
+### Changed
+
+- Required bevy version is now 0.10
+- Optional bevy_ecs_tilemap version is now 0.10
+
 ## [0.3.1]
 
 ### Fixed
diff --git a/Cargo.toml b/Cargo.toml
index 04f4a1a..3b76ff1 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "micro_banimate"
-version = "0.5.0-beta.1"
+version = "0.5.0-beta.2"
 edition = "2021"
 license = "Apache-2.0"
 description = "Easily manage complex Bevy 2D sprite animations"
@@ -15,7 +15,7 @@ json_loader = ["serde", "dep:serde_json"]
 toml_loader = ["serde", "dep:toml"]
 serde = ["dep:serde"]
 
-#ecs_tilemap = ["dep:bevy_ecs_tilemap"]
+ecs_tilemap = ["dep:bevy_ecs_tilemap"]
 
 [dependencies]
 anyhow = "^1.0.65"
@@ -24,4 +24,4 @@ serde_json = { version = "^1.0.85", optional = true }
 toml = { version = "^0.5.9", optional = true }
 bevy = { version = "^0.10.0", default-features = false, features = ["bevy_asset", "bevy_sprite"] }
 
-#bevy_ecs_tilemap = { version = "^0.9.0", optional = true }
+bevy_ecs_tilemap = { version = "0.10.0", optional = true }
diff --git a/README.md b/README.md
index 142ba3d..d6881a5 100644
--- a/README.md
+++ b/README.md
@@ -122,6 +122,6 @@ frame_time = 100
 
 | banimate version    | bevy version | tilemap version |
 |---------------------|--------------|-----------------|
-| 0.5.x               | 0.10         | --              |
+| 0.5.x               | 0.10         | 0.10            |
 | 0.2.x, 0.3.x, 0.4.x | 0.9          | 0.9             |
 | 0.1.x               | 0.8          | 0.8             |
diff --git a/src/query.rs b/src/query.rs
index 05a2bf7..dbfd5d3 100644
--- a/src/query.rs
+++ b/src/query.rs
@@ -52,7 +52,7 @@ pub struct AnimationQuery<'w, 's> {
 	direction: Query<'w, 's, &'static mut Directionality>,
 	action_animation: Query<'w, 's, &'static mut AnimationOverride>,
 	tile_sprite: Query<'w, 's, &'static mut TextureAtlasSprite>,
-	paused: Query<'w, 's, Entity, With<AnimationPaused>>,
+	paused: Query<'w, 's, (), With<AnimationPaused>>,
 	events: EventWriter<'w, AnimationCompleted>,
 }
 
@@ -408,8 +408,6 @@ impl<'w, 's> AnimationQuery<'w, 's> {
 
 		let directed = format!("{}_{}", &fallback, direction);
 
-		// log::info!("Directed - {}", directed);
-
 		if set.contains_key(&directed) {
 			status.start_or_continue(directed);
 		} else {
diff --git a/src/systems.rs b/src/systems.rs
index 4d74de9..dc36189 100644
--- a/src/systems.rs
+++ b/src/systems.rs
@@ -52,42 +52,42 @@ pub fn sync_parent_animations(mut query: AnimationQuery) {
 	query.sync_parent_animations();
 }
 
-// #[cfg(feature = "ecs_tilemap")]
-// pub fn tick_simple_tilemap_animation(
-// 	time: Res<Time>,
-// 	mut query: Query<
-// 		(
-// 			&SimpleLoopedAnimation,
-// 			&mut SimpleLoopedAnimationStatus,
-// 			&mut bevy_ecs_tilemap::tiles::TileTextureIndex,
-// 		),
-// 		With<HasSimpleAnimations>,
-// 	>,
-// ) {
-// 	let seconds = time.delta_seconds();
-// 	for (animation, mut state, mut tile) in &mut query {
-// 		state.frame_time += seconds;
-// 		while state.frame_time >= animation.frame_secs {
-// 			state.frame_time -= animation.frame_secs;
-// 			state.active_step += 1;
-// 			if state.active_step >= animation.frames.len() {
-// 				state.active_step = 0;
-// 			}
-// 		}
-//
-// 		*tile =
-// 			bevy_ecs_tilemap::tiles::TileTextureIndex(animation.frames[state.active_step] as u32);
-// 	}
-// }
+#[cfg(feature = "ecs_tilemap")]
+pub fn tick_simple_tilemap_animation(
+	time: Res<Time>,
+	mut query: Query<
+		(
+			&SimpleLoopedAnimation,
+			&mut SimpleLoopedAnimationStatus,
+			&mut bevy_ecs_tilemap::tiles::TileTextureIndex,
+		),
+		With<HasSimpleAnimations>,
+	>,
+) {
+	let seconds = time.delta_seconds();
+	for (animation, mut state, mut tile) in &mut query {
+		state.frame_time += seconds;
+		while state.frame_time >= animation.frame_secs {
+			state.frame_time -= animation.frame_secs;
+			state.active_step += 1;
+			if state.active_step >= animation.frames.len() {
+				state.active_step = 0;
+			}
+		}
+
+		*tile =
+			bevy_ecs_tilemap::tiles::TileTextureIndex(animation.frames[state.active_step] as u32);
+	}
+}
 
 pub struct AnimationSystemsPlugin;
 
 impl Plugin for AnimationSystemsPlugin {
 	fn build(&self, app: &mut App) {
 		app.configure_sets((
-			CoreSet::PostUpdate,
 			AnimationSystems::TickAnimations,
 			AnimationSystems::SyncAnimations,
+			CoreSet::PostUpdate,
 		));
 
 		app.add_event::<AnimationCompleted>()
@@ -97,9 +97,11 @@ impl Plugin for AnimationSystemsPlugin {
 			)
 			.add_system(sync_parent_animations.in_base_set(AnimationSystems::SyncAnimations));
 
-		// #[cfg(feature = "ecs_tilemap")]
-		// {
-		// 		app.add_system(tick_simple_tilemap_animation.in_set(AnimationSystems::TickAnimations));
-		// }
+		#[cfg(feature = "ecs_tilemap")]
+		{
+			app.add_system(
+				tick_simple_tilemap_animation.in_base_set(AnimationSystems::TickAnimations),
+			);
+		}
 	}
 }
-- 
GitLab