diff --git a/js/core/player.js b/js/core/player.js index f70175b..8a2c042 100644 --- a/js/core/player.js +++ b/js/core/player.js @@ -27,6 +27,27 @@ const keyboardInput = { }; let isKeyboardMoving = false; +// Keyboard pause state (for when minigames need keyboard input) +let keyboardPaused = false; + +// Export functions to pause/resume keyboard interception +export function pauseKeyboardInput() { + keyboardPaused = true; + console.log('🔒 Keyboard input PAUSED for minigame (keyboardPaused = true)'); +} + +export function resumeKeyboardInput() { + keyboardPaused = false; + // Clear all keyboard state when resuming + keyboardInput.up = false; + keyboardInput.down = false; + keyboardInput.left = false; + keyboardInput.right = false; + keyboardInput.space = false; + isKeyboardMoving = false; + console.log('🔓 Keyboard input RESUMED (keyboardPaused = false)'); +} + // Create player sprite export function createPlayer(gameInstance) { gameRef = gameInstance; @@ -82,6 +103,12 @@ export function createPlayer(gameInstance) { function setupKeyboardInput() { // Handle keydown events document.addEventListener('keydown', (event) => { + // Skip if keyboard input is paused (for minigames that need keyboard input) + if (keyboardPaused) { + console.log('⏸️ Keydown blocked (paused):', event.key); + return; + } + const key = event.key.toLowerCase(); // Spacebar for jump @@ -144,6 +171,11 @@ function setupKeyboardInput() { // Handle keyup events document.addEventListener('keyup', (event) => { + // Skip if keyboard input is paused (for minigames that need keyboard input) + if (keyboardPaused) { + return; + } + const key = event.key.toLowerCase(); // Spacebar @@ -572,4 +604,12 @@ function getStartingRoomCenter(startRoomId) { } // Export for global access -window.createPlayer = createPlayer; \ No newline at end of file +window.createPlayer = createPlayer; +window.pauseKeyboardInput = pauseKeyboardInput; +window.resumeKeyboardInput = resumeKeyboardInput; + +console.log('✅ Player module loaded - keyboard control functions exported to window:', { + createPlayer: typeof window.createPlayer, + pauseKeyboardInput: typeof window.pauseKeyboardInput, + resumeKeyboardInput: typeof window.resumeKeyboardInput +}); \ No newline at end of file diff --git a/js/minigames/framework/minigame-manager.js b/js/minigames/framework/minigame-manager.js index b4c12bf..0bf4280 100644 --- a/js/minigames/framework/minigame-manager.js +++ b/js/minigames/framework/minigame-manager.js @@ -24,6 +24,31 @@ export const MinigameFramework = { this.endMinigame(false, null); } + // Check if this minigame requires keyboard input + const requiresKeyboardInput = params?.requiresKeyboardInput || false; + + console.log('🎮 Starting minigame:', sceneType, 'requiresKeyboardInput:', requiresKeyboardInput); + + // Pause keyboard input for game controls if minigame needs keyboard + if (requiresKeyboardInput) { + console.log('🔍 Checking for window.pauseKeyboardInput...'); + // Try to access player module functions from window first (already loaded) + if (window.pauseKeyboardInput) { + console.log('✅ Found window.pauseKeyboardInput, calling it now...'); + window.pauseKeyboardInput(); + console.log('✅ Paused keyboard input for minigame that requires text input'); + } else { + console.warn('⚠️ window.pauseKeyboardInput not found, trying dynamic import...'); + // Fallback to dynamic import if not available on window + import('../../../js/core/player.js').then(module => { + if (module.pauseKeyboardInput) { + module.pauseKeyboardInput(); + console.log('Paused keyboard input for minigame that requires text input (via import)'); + } + }); + } + } + // Disable main game input if we have a main game scene // (unless the minigame explicitly allows game input via disableGameInput: false) if (this.mainGameScene && this.mainGameScene.input) { @@ -83,6 +108,20 @@ export const MinigameFramework = { container.remove(); } + // Resume keyboard input for game controls + if (window.resumeKeyboardInput) { + window.resumeKeyboardInput(); + console.log('Resumed keyboard input after minigame ended'); + } else { + // Fallback to dynamic import if not available on window + import('../../../js/core/player.js').then(module => { + if (module.resumeKeyboardInput) { + module.resumeKeyboardInput(); + console.log('Resumed keyboard input after minigame ended (via import)'); + } + }); + } + // Re-enable main game input if we have a main game scene and we disabled it if (this.mainGameScene && this.mainGameScene.input && this.gameInputDisabled) { this.mainGameScene.input.mouse.enabled = true; diff --git a/js/minigames/notes/notes-minigame.js b/js/minigames/notes/notes-minigame.js index d460635..3a8cc87 100644 --- a/js/minigames/notes/notes-minigame.js +++ b/js/minigames/notes/notes-minigame.js @@ -712,6 +712,7 @@ export function startNotesMinigame(item, noteContent, observationText, navigateT autoAddToNotes: autoAddToNotes, // Automatically add notes to the notes system navigateToNote: navigateToNote, // Which note to navigate to hideNavigation: hideNavigation, // Whether to hide navigation buttons + requiresKeyboardInput: true, // Notes minigame has editable observations and search onComplete: (success, result) => { if (success && result && result.addedToInventory) { console.log('NOTES SUCCESS - Added to inventory', result); diff --git a/js/systems/minigame-starters.js b/js/systems/minigame-starters.js index 455db78..9dbb380 100644 --- a/js/systems/minigame-starters.js +++ b/js/systems/minigame-starters.js @@ -579,6 +579,7 @@ export function startPasswordMinigame(lockable, type, correctPassword, callback, postitNote: options.postitNote || '', showPostit: options.showPostit || false, lockable: lockable, + requiresKeyboardInput: true, // Password minigame needs keyboard for text input onComplete: (success, result) => { if (success) { console.log('PASSWORD MINIGAME SUCCESS'); diff --git a/test-keyboard-pause.html b/test-keyboard-pause.html new file mode 100644 index 0000000..e57bd25 --- /dev/null +++ b/test-keyboard-pause.html @@ -0,0 +1,133 @@ + + +
+ + +