From 422f234106affa54ef60201d6ab8aa761a2c0893 Mon Sep 17 00:00:00 2001 From: "Z. Cliffe Schreuders" Date: Fri, 10 Oct 2025 23:59:01 +0100 Subject: [PATCH] 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. --- js/systems/doors.js | 29 +++++++++++------------------ js/systems/interactions.js | 4 ++-- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/js/systems/doors.js b/js/systems/doors.js index 28937ea..bb6fe06 100644 --- a/js/systems/doors.js +++ b/js/systems/doors.js @@ -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'); diff --git a/js/systems/interactions.js b/js/systems/interactions.js index 1d3593a..a727b21 100644 --- a/js/systems/interactions.js +++ b/js/systems/interactions.js @@ -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