@@ -52,18 +52,13 @@ export const useCommandExecution = ( |
| 52 | onLocationChange(response.current_path); | 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 | if (response.mole_spawned) { | 57 | if (response.mole_spawned) { |
| 57 | onMoleKilled(response); | 58 | onMoleKilled(response); |
| 58 | - } | 59 | + // Don't update tree here - let onMoleKilled handle it after animation |
| 59 | - | 60 | + } else if (response.new_mole_location) { |
| 60 | - // Handle game completion | 61 | + // Only update tree if it's NOT a mole kill (e.g., mole escape) |
| 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) { | | |
| 67 | onTreeUpdate((tree) => { | 62 | onTreeUpdate((tree) => { |
| 68 | const updateMoleInTree = (node: TreeNode, molePath: string): TreeNode => { | 63 | const updateMoleInTree = (node: TreeNode, molePath: string): TreeNode => { |
| 69 | return { | 64 | return { |
@@ -75,6 +70,11 @@ export const useCommandExecution = ( |
| 75 | return updateMoleInTree(tree, response.new_mole_location!); | 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 | } catch (error) { | 78 | } catch (error) { |
| 79 | console.error('Command execution failed:', error); | 79 | console.error('Command execution failed:', error); |
| 80 | addToHistory({ | 80 | addToHistory({ |