feat(sound): wire sound hooks into game engine
Sound integration points: - writeCode() -> playClick() - buyBuilding() -> playBuild() - buyProject() -> playProject() - checkMilestones() -> playMilestone() - showPhaseTransition() -> playFanfare() + updateAmbientPhase() - renderDriftEnding() -> playDriftEnding() - renderBeaconEnding() -> playBeaconEnding() - Game init -> startAmbient() on first user interaction - toggleMute() -> onMuteChanged() for ambient gain control All hooks use typeof guard to avoid errors if sound.js fails to load.
This commit is contained in:
12
js/engine.js
12
js/engine.js
@@ -283,6 +283,7 @@ function checkMilestones() {
|
||||
G.milestones.push(m.flag);
|
||||
log(m.msg, true);
|
||||
showToast(m.msg, 'milestone', 5000);
|
||||
if (typeof Sound !== 'undefined') Sound.playMilestone();
|
||||
|
||||
// Check phase advancement
|
||||
if (m.at) {
|
||||
@@ -296,6 +297,10 @@ function checkMilestones() {
|
||||
if (pNum > _shownPhaseTransition) {
|
||||
_shownPhaseTransition = pNum;
|
||||
showPhaseTransition(pNum);
|
||||
if (typeof Sound !== 'undefined') {
|
||||
Sound.playFanfare();
|
||||
Sound.updateAmbientPhase(pNum);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -356,6 +361,7 @@ function buyBuilding(id) {
|
||||
log(`Built ${def.name} ${label} (total: ${totalBuilt})`);
|
||||
// Particle burst on purchase
|
||||
const btn = document.querySelector('[onclick="buyBuilding(\'' + id + '\')"]');
|
||||
if (typeof Sound !== 'undefined') Sound.playBuild();
|
||||
if (btn) {
|
||||
const rect = btn.getBoundingClientRect();
|
||||
const cx = rect.left + rect.width / 2;
|
||||
@@ -396,6 +402,7 @@ function buyProject(id) {
|
||||
|
||||
updateRates();
|
||||
// Gold particle burst on project completion
|
||||
if (typeof Sound !== 'undefined') Sound.playProject();
|
||||
const pBtn = document.querySelector('[onclick="buyProject(\'' + id + '\')"]');
|
||||
if (pBtn) {
|
||||
const rect = pBtn.getBoundingClientRect();
|
||||
@@ -437,6 +444,7 @@ function renderDriftEnding() {
|
||||
// Fade-in animation
|
||||
el.classList.add('fade-in');
|
||||
el.classList.add('active');
|
||||
if (typeof Sound !== 'undefined') Sound.playDriftEnding();
|
||||
|
||||
// Log the ending text with delays for dramatic effect
|
||||
const lines = [
|
||||
@@ -479,8 +487,7 @@ function renderBeaconEnding() {
|
||||
</button>
|
||||
`;
|
||||
document.body.appendChild(overlay);
|
||||
|
||||
// Create particle/light ray container
|
||||
if (typeof Sound !== 'undefined') Sound.playBeaconEnding();
|
||||
const particleContainer = document.createElement('div');
|
||||
particleContainer.id = 'beacon-ending-particles';
|
||||
document.body.appendChild(particleContainer);
|
||||
@@ -762,6 +769,7 @@ function writeCode() {
|
||||
}
|
||||
// Float a number at the click position
|
||||
showClickNumber(amount, comboMult);
|
||||
if (typeof Sound !== 'undefined') Sound.playClick();
|
||||
updateRates();
|
||||
checkMilestones();
|
||||
render();
|
||||
|
||||
Reference in New Issue
Block a user