zeroed-some/bashamole / 7bc818d

Browse files

actually fix anim firing late

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
7bc818d3c7e60e772c508816f9d5295c6d3930da
Parents
26c8702
Tree
13914b8

1 changed file

StatusFile+-
M frontend/src/hooks/useCommandExecution.ts 10 10
frontend/src/hooks/useCommandExecution.tsmodified
@@ -52,18 +52,13 @@ export const useCommandExecution = (
5252
         onLocationChange(response.current_path);
5353
       }
5454
 
55
-      // Handle mole killed
55
+      // IMPORTANT: Handle mole killed BEFORE updating tree
56
+      // This ensures the animation plays at the correct location
5657
       if (response.mole_spawned) {
5758
         onMoleKilled(response);
58
-      }
59
-
60
-      // Handle game completion
61
-      if (response.game_completed && response.final_stats && onGameComplete) {
62
-        onGameComplete(response.final_stats);
63
-      }
64
-
65
-      // Handle mole location updates in tree
66
-      if (response.new_mole_location) {
59
+        // Don't update tree here - let onMoleKilled handle it after animation
60
+      } else if (response.new_mole_location) {
61
+        // Only update tree if it's NOT a mole kill (e.g., mole escape)
6762
         onTreeUpdate((tree) => {
6863
           const updateMoleInTree = (node: TreeNode, molePath: string): TreeNode => {
6964
             return {
@@ -75,6 +70,11 @@ export const useCommandExecution = (
7570
           return updateMoleInTree(tree, response.new_mole_location!);
7671
         });
7772
       }
73
+
74
+      // Handle game completion
75
+      if (response.game_completed && response.final_stats && onGameComplete) {
76
+        onGameComplete(response.final_stats);
77
+      }
7878
     } catch (error) {
7979
       console.error('Command execution failed:', error);
8080
       addToHistory({