mirror of
https://github.com/cliffe/BreakEscape.git
synced 2026-02-21 11:18:08 +00:00
Enhance Door Interaction Logic: Refactor door unlocking functions to directly utilize the newly exported startLockpickingMinigame and startKeySelectionMinigame from interactions.js, improving code clarity and reducing reliance on window object checks. This change streamlines the minigame initiation process for better maintainability.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import { TILE_SIZE } from '../utils/constants.js';
|
||||
import { handleUnlock, getLockRequirementsForDoor } from './interactions.js';
|
||||
import { handleUnlock, getLockRequirementsForDoor, startLockpickingMinigame, startKeySelectionMinigame } from './interactions.js';
|
||||
|
||||
let gameRef = null;
|
||||
let rooms = null;
|
||||
@@ -342,12 +342,7 @@ function handleDoorUnlockDirect(doorSprite, props) {
|
||||
|
||||
if (playerKeys.length > 0) {
|
||||
// Show key selection interface
|
||||
if (window.startKeySelectionMinigame) {
|
||||
window.startKeySelectionMinigame(doorSprite, 'door', playerKeys, requiredKey);
|
||||
} else {
|
||||
console.log('Key selection minigame not available');
|
||||
window.gameAlert(`Requires key: ${requiredKey}`, 'error', 'Locked', 4000);
|
||||
}
|
||||
startKeySelectionMinigame(doorSprite, 'door', playerKeys, requiredKey);
|
||||
} else {
|
||||
// Check for lockpick kit
|
||||
const hasLockpick = window.inventory.items.some(item =>
|
||||
@@ -361,17 +356,15 @@ function handleDoorUnlockDirect(doorSprite, props) {
|
||||
let difficulty = 'medium';
|
||||
|
||||
console.log('STARTING LOCKPICK MINIGAME', { difficulty });
|
||||
if (window.startLockpickingMinigame) {
|
||||
window.startLockpickingMinigame(doorSprite, window.game, difficulty, (success) => {
|
||||
if (success) {
|
||||
unlockDoor(doorSprite);
|
||||
window.gameAlert(`Successfully picked the lock!`, 'success', 'Lock Picked', 4000);
|
||||
} else {
|
||||
console.log('LOCKPICK FAILED');
|
||||
window.gameAlert('Failed to pick the lock. Try again.', 'error', 'Pick Failed', 3000);
|
||||
}
|
||||
});
|
||||
}
|
||||
startLockpickingMinigame(doorSprite, window.game, difficulty, (success) => {
|
||||
if (success) {
|
||||
unlockDoor(doorSprite);
|
||||
window.gameAlert(`Successfully picked the lock!`, 'success', 'Lock Picked', 4000);
|
||||
} else {
|
||||
console.log('LOCKPICK FAILED');
|
||||
window.gameAlert('Failed to pick the lock. Try again.', 'error', 'Pick Failed', 3000);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
console.log('NO KEYS OR LOCKPICK AVAILABLE');
|
||||
|
||||
@@ -1109,7 +1109,7 @@ function openDoor(doorSprite, room) {
|
||||
console.log('DOOR OPENED SUCCESSFULLY');
|
||||
}
|
||||
|
||||
function startLockpickingMinigame(lockable, scene, difficulty = 'medium', callback) {
|
||||
export function startLockpickingMinigame(lockable, scene, difficulty = 'medium', callback) {
|
||||
console.log('Starting lockpicking minigame with difficulty:', difficulty);
|
||||
|
||||
// Initialize the minigame framework if not already done
|
||||
@@ -1253,7 +1253,7 @@ function generateKeyCutsForLock(key, lockable) {
|
||||
return cuts;
|
||||
}
|
||||
|
||||
function startKeySelectionMinigame(lockable, type, playerKeys, requiredKeyId) {
|
||||
export function startKeySelectionMinigame(lockable, type, playerKeys, requiredKeyId) {
|
||||
console.log('Starting key selection minigame', { playerKeys, requiredKeyId });
|
||||
|
||||
// Initialize the minigame framework if not already done
|
||||
|
||||
Reference in New Issue
Block a user