mirror of
https://github.com/cliffe/BreakEscape.git
synced 2026-02-20 13:50:46 +00:00
- Created SoundManager class for handling audio playback using Phaser's sound system. - Added methods for preloading, initializing, and playing sounds with volume control. - Integrated UI sound helpers for easier sound attachment to DOM elements. - Updated game.js to initialize sound manager and preload sounds. - Modified interactions.js, unlock-system.js, and panels.js to play appropriate sounds on interactions. - Created SOUND_SYSTEM_QUICK_REFERENCE.md for documentation on sound system usage. - Optimized NPCBarkSystem and NPCManager with caching and event listener cleanup.
151 lines
3.5 KiB
JavaScript
151 lines
3.5 KiB
JavaScript
/**
|
|
* UI Sound Integration Helper
|
|
* Provides convenience methods to attach sound effects to DOM elements and game interactions
|
|
*/
|
|
|
|
/**
|
|
* Attach click sound to a DOM element
|
|
* @param {HTMLElement} element - The element to add sound to
|
|
* @param {string} soundType - Type: 'click', 'confirm', 'alert', 'reject', or specific sound name
|
|
*/
|
|
export function attachUISound(element, soundType = 'click') {
|
|
if (!element) return;
|
|
|
|
element.addEventListener('click', () => {
|
|
playUISound(soundType);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Attach sounds to all buttons with a specific class
|
|
* @param {string} className - The CSS class to target
|
|
* @param {string} soundType - Type of sound to play
|
|
*/
|
|
export function attachUISoundsToClass(className, soundType = 'click') {
|
|
const elements = document.querySelectorAll(`.${className}`);
|
|
elements.forEach(element => {
|
|
attachUISound(element, soundType);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Play a UI sound
|
|
* @param {string} soundType - Type: 'click', 'confirm', 'alert', 'reject', 'notification', 'interaction', etc.
|
|
*/
|
|
export function playUISound(soundType = 'click') {
|
|
const soundManager = window.soundManager;
|
|
if (!soundManager) {
|
|
console.warn('Sound Manager not initialized');
|
|
return;
|
|
}
|
|
|
|
switch (soundType) {
|
|
case 'click':
|
|
soundManager.playUIClick();
|
|
break;
|
|
case 'confirm':
|
|
soundManager.play('ui_confirm');
|
|
break;
|
|
case 'alert':
|
|
soundManager.play('ui_alert_1');
|
|
break;
|
|
case 'reject':
|
|
soundManager.play('ui_reject');
|
|
break;
|
|
case 'notification':
|
|
soundManager.playUINotification();
|
|
break;
|
|
case 'item':
|
|
soundManager.playItemInteract();
|
|
break;
|
|
case 'lock':
|
|
soundManager.playLockInteract();
|
|
break;
|
|
default:
|
|
// Try to play as-is
|
|
soundManager.play(soundType);
|
|
break;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Attach notification sound to an element
|
|
*/
|
|
export function attachNotificationSound(element) {
|
|
if (!element) return;
|
|
element.addEventListener('click', () => {
|
|
playUISound('notification');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Attach item interaction sound
|
|
*/
|
|
export function attachItemSound(element) {
|
|
if (!element) return;
|
|
element.addEventListener('click', () => {
|
|
playUISound('item');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Attach lock interaction sound
|
|
*/
|
|
export function attachLockSound(element) {
|
|
if (!element) return;
|
|
element.addEventListener('click', () => {
|
|
playUISound('lock');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Attach confirm sound
|
|
*/
|
|
export function attachConfirmSound(element) {
|
|
if (!element) return;
|
|
element.addEventListener('click', () => {
|
|
playUISound('confirm');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Attach reject/error sound
|
|
*/
|
|
export function attachRejectSound(element) {
|
|
if (!element) return;
|
|
element.addEventListener('click', () => {
|
|
playUISound('reject');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Play special game sounds
|
|
*/
|
|
export function playGameSound(soundName) {
|
|
const soundManager = window.soundManager;
|
|
if (soundManager) {
|
|
soundManager.play(soundName);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Play door knock sound
|
|
*/
|
|
export function playDoorKnock() {
|
|
playGameSound('door_knock');
|
|
}
|
|
|
|
/**
|
|
* Play chair roll sound
|
|
*/
|
|
export function playChairRoll() {
|
|
playGameSound('chair_roll');
|
|
}
|
|
|
|
/**
|
|
* Play message received sound
|
|
*/
|
|
export function playMessageReceived() {
|
|
playGameSound('message_received');
|
|
}
|