diff --git a/public/break_escape/js/core/game.js b/public/break_escape/js/core/game.js index d34966b..9a955e0 100644 --- a/public/break_escape/js/core/game.js +++ b/public/break_escape/js/core/game.js @@ -1,8 +1,8 @@ import { initializeRooms, calculateWorldBounds, calculateRoomPositions, createRoom, revealRoom, updatePlayerRoom, rooms } from './rooms.js?v=16'; import { createPlayer, updatePlayerMovement, movePlayerToPoint, facePlayerToward, player } from './player.js?v=8'; import { initializePathfinder } from './pathfinding.js?v=7'; -import { initializeInventory, processInitialInventoryItems } from '../systems/inventory.js?v=8'; -import { checkObjectInteractions, setGameInstance, isObjectInInteractionRange } from '../systems/interactions.js?v=28'; +import { initializeInventory, processInitialInventoryItems } from '../systems/inventory.js?v=9'; +import { checkObjectInteractions, setGameInstance, isObjectInInteractionRange } from '../systems/interactions.js?v=30'; import { introduceScenario } from '../utils/helpers.js?v=19'; import '../minigames/index.js?v=2'; import SoundManager from '../systems/sound-manager.js?v=1'; diff --git a/public/break_escape/js/systems/interactions.js b/public/break_escape/js/systems/interactions.js index edad16a..9be73a7 100644 --- a/public/break_escape/js/systems/interactions.js +++ b/public/break_escape/js/systems/interactions.js @@ -4,13 +4,21 @@ import { rooms } from '../core/rooms.js?v=16'; import { handleUnlock } from './unlock-system.js'; import { handleDoorInteraction } from './doors.js'; import { collectFingerprint, handleBiometricScan } from './biometrics.js'; -import { addToInventory, removeFromInventory, createItemIdentifier } from './inventory.js'; +import { addToInventory, removeFromInventory, createItemIdentifier } from './inventory.js?v=9'; import { playUISound, playGameSound } from './ui-sounds.js?v=1'; let gameRef = null; export function setGameInstance(gameInstance) { gameRef = gameInstance; + + // Immediately destroy any proximity ghost when an item is collected, + // regardless of whether the interaction check interval has fired yet. + if (window.eventDispatcher) { + window.eventDispatcher.on('item_removed_from_scene', ({ sprite }) => { + if (sprite) removeProximityGhost(sprite); + }); + } } // Helper function to calculate interaction distance with direction-based offset @@ -431,6 +439,17 @@ function addProximityGhost(obj) { }); obj.proximityGhost = ghost; + + // Self-cleaning: patch setVisible so the ghost is destroyed the instant + // the sprite is hidden (collection, any code path, async or not). + // We store the original so removeProximityGhost can restore it. + if (obj.setVisible && !obj._preGhostSetVisible) { + obj._preGhostSetVisible = obj.setVisible.bind(obj); + obj.setVisible = function(visible) { + obj._preGhostSetVisible(visible); + if (!visible) removeProximityGhost(obj); + }; + } } catch (error) { console.warn('Failed to add proximity ghost:', error); } @@ -441,6 +460,11 @@ function removeProximityGhost(obj) { obj.proximityGhost.destroy(); delete obj.proximityGhost; } + // Restore the original setVisible so the patch doesn't linger + if (obj._preGhostSetVisible) { + obj.setVisible = obj._preGhostSetVisible; + delete obj._preGhostSetVisible; + } } function addInteractionIndicator(obj) { diff --git a/public/break_escape/js/systems/inventory.js b/public/break_escape/js/systems/inventory.js index d45a793..9b7e5dc 100644 --- a/public/break_escape/js/systems/inventory.js +++ b/public/break_escape/js/systems/inventory.js @@ -358,6 +358,9 @@ export async function addToInventory(sprite) { sprite.proximityGhost.destroy(); delete sprite.proximityGhost; } + if (window.eventDispatcher) { + window.eventDispatcher.emit('item_removed_from_scene', { sprite }); + } // Show notification to player if (window.gameAlert) { @@ -445,6 +448,9 @@ export async function addToInventory(sprite) { sprite.proximityGhost.destroy(); delete sprite.proximityGhost; } + if (window.eventDispatcher) { + window.eventDispatcher.emit('item_removed_from_scene', { sprite }); + } // Special handling for keys - group them together if (sprite.scenarioData.type === 'key') {