actually fix anim firing late
Authored by
mfwolffe <wolffemf@dukes.jmu.edu>
- SHA
7bc818d3c7e60e772c508816f9d5295c6d3930da- Parents
-
26c8702 - Tree
13914b8
7bc818d
7bc818d3c7e60e772c508816f9d5295c6d3930da26c8702
13914b8| Status | File | + | - |
|---|---|---|---|
| M |
frontend/src/hooks/useCommandExecution.ts
|
10 | 10 |
frontend/src/hooks/useCommandExecution.tsmodified@@ -52,18 +52,13 @@ export const useCommandExecution = ( | ||
| 52 | 52 | onLocationChange(response.current_path); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - // Handle mole killed | |
| 55 | + // IMPORTANT: Handle mole killed BEFORE updating tree | |
| 56 | + // This ensures the animation plays at the correct location | |
| 56 | 57 | if (response.mole_spawned) { |
| 57 | 58 | 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) | |
| 67 | 62 | onTreeUpdate((tree) => { |
| 68 | 63 | const updateMoleInTree = (node: TreeNode, molePath: string): TreeNode => { |
| 69 | 64 | return { |
@@ -75,6 +70,11 @@ export const useCommandExecution = ( | ||
| 75 | 70 | return updateMoleInTree(tree, response.new_mole_location!); |
| 76 | 71 | }); |
| 77 | 72 | } |
| 73 | + | |
| 74 | + // Handle game completion | |
| 75 | + if (response.game_completed && response.final_stats && onGameComplete) { | |
| 76 | + onGameComplete(response.final_stats); | |
| 77 | + } | |
| 78 | 78 | } catch (error) { |
| 79 | 79 | console.error('Command execution failed:', error); |
| 80 | 80 | addToHistory({ |