mirror of
https://github.com/cliffe/BreakEscape.git
synced 2026-02-20 13:50:46 +00:00
fix: enhance inventory and interaction systems with immediate proximity ghost removal on item collection
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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') {
|
||||
|
||||
Reference in New Issue
Block a user