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:
Z. Cliffe Schreuders
2025-10-10 23:59:01 +01:00
parent 9cc382e61d
commit 422f234106
2 changed files with 13 additions and 20 deletions

View File

@@ -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');

View File

@@ -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