Prod hardening: one-game-per-player, selectable music, bargevasat.ir config
- One running game per player: server rejects a 2nd matchmake while in a live room (re-syncs the existing game); client guards Home vs-computer + Lobby random/create — resumes the running match + notifies instead of starting another (game-store hasActiveMatch()). - Background music is now selectable: santoor (سنتی, calm Persian loop) and playful (bouncy UNO-like) — sound.ts TRACKS + setMusicTrack (persisted), sound-store musicTrack, picker in Profile → Audio. i18n added. - Production config for bargevasat.ir (prepare-only; no live deploy): appsettings.Production.example (CORS + ZarinPal + IAB to the domain), docker-compose.caddy.yml + Caddyfile (auto-HTTPS reverse proxy bargevasat.ir→web, api.bargevasat.ir→server), ENV_FILE PRODUCTION block, PRODUCTION.md go-live + Cafe Bazaar publish/IAB checklist. Fixed IAB package name to match Capacitor appId (com.bargevasat.app). Verified: tsc + next build + dotnet build all pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+42
-10
@@ -18,6 +18,9 @@ export type Sfx =
|
||||
|
||||
const LS_SFX = "hokm.sfx";
|
||||
const LS_MUSIC = "hokm.music";
|
||||
const LS_TRACK = "hokm.musicTrack";
|
||||
|
||||
export type MusicTrack = "santoor" | "playful";
|
||||
|
||||
function loadBool(key: string, def = true): boolean {
|
||||
if (typeof window === "undefined") return def;
|
||||
@@ -34,6 +37,8 @@ class SoundManager {
|
||||
|
||||
sfxEnabled = loadBool(LS_SFX);
|
||||
musicEnabled = loadBool(LS_MUSIC);
|
||||
musicTrack: MusicTrack =
|
||||
(typeof window !== "undefined" && (localStorage.getItem(LS_TRACK) as MusicTrack)) || "santoor";
|
||||
|
||||
/** Must be called from a user gesture to unlock audio. */
|
||||
init() {
|
||||
@@ -70,6 +75,18 @@ class SoundManager {
|
||||
}
|
||||
}
|
||||
|
||||
/** Switch the background music style; restarts the loop if playing. */
|
||||
setMusicTrack(track: MusicTrack) {
|
||||
this.musicTrack = track;
|
||||
if (typeof window !== "undefined") localStorage.setItem(LS_TRACK, track);
|
||||
this.step = 0;
|
||||
if (this.musicEnabled) {
|
||||
this.stopMusic();
|
||||
this.init();
|
||||
this.startMusic();
|
||||
}
|
||||
}
|
||||
|
||||
private tone(
|
||||
freq: number,
|
||||
start: number,
|
||||
@@ -147,29 +164,44 @@ class SoundManager {
|
||||
}
|
||||
}
|
||||
|
||||
// Gentle ambient loop on a Persian-flavored scale (Dastgah-ish).
|
||||
private MUSIC = [293.66, 311.13, 392, 440, 466.16, 392, 311.13, 293.66];
|
||||
// Two selectable loops:
|
||||
// • santoor — calm Persian-flavored (Dastgah-ish) legato loop with fifth harmony.
|
||||
// • playful — bouncy major-pentatonic staccato loop (UNO-like).
|
||||
private TRACKS: Record<
|
||||
MusicTrack,
|
||||
{ notes: number[]; gap: number; type: OscillatorType; attack: number; dur: number; peak: number; fifth: boolean }
|
||||
> = {
|
||||
santoor: {
|
||||
notes: [293.66, 311.13, 392, 440, 466.16, 392, 311.13, 293.66],
|
||||
gap: 900, type: "sine", attack: 0.3, dur: 1.6, peak: 0.5, fifth: true,
|
||||
},
|
||||
playful: {
|
||||
notes: [523.25, 659.25, 784, 659.25, 587.33, 698.46, 880, 698.46, 587.33, 523.25],
|
||||
gap: 360, type: "triangle", attack: 0.02, dur: 0.34, peak: 0.4, fifth: false,
|
||||
},
|
||||
};
|
||||
|
||||
startMusic() {
|
||||
if (!this.musicEnabled || this.musicTimer || !this.ctx || !this.musicGain) return;
|
||||
const playNote = () => {
|
||||
if (!this.ctx || !this.musicGain) return;
|
||||
const freq = this.MUSIC[this.step % this.MUSIC.length];
|
||||
const cfg = this.TRACKS[this.musicTrack];
|
||||
const freq = cfg.notes[this.step % cfg.notes.length];
|
||||
this.step++;
|
||||
const osc = this.ctx.createOscillator();
|
||||
const g = this.ctx.createGain();
|
||||
const t = this.ctx.currentTime;
|
||||
osc.type = "sine";
|
||||
osc.type = cfg.type;
|
||||
osc.frequency.value = freq;
|
||||
g.gain.setValueAtTime(0.0001, t);
|
||||
g.gain.exponentialRampToValueAtTime(0.5, t + 0.3);
|
||||
g.gain.exponentialRampToValueAtTime(0.0001, t + 1.6);
|
||||
g.gain.exponentialRampToValueAtTime(cfg.peak, t + cfg.attack);
|
||||
g.gain.exponentialRampToValueAtTime(0.0001, t + cfg.dur);
|
||||
osc.connect(g);
|
||||
g.connect(this.musicGain);
|
||||
osc.start(t);
|
||||
osc.stop(t + 1.7);
|
||||
// soft fifth harmony every other note
|
||||
if (this.step % 2 === 0) {
|
||||
osc.stop(t + cfg.dur + 0.1);
|
||||
// soft fifth harmony (santoor) every other note
|
||||
if (cfg.fifth && this.step % 2 === 0) {
|
||||
const o2 = this.ctx.createOscillator();
|
||||
const g2 = this.ctx.createGain();
|
||||
o2.type = "sine";
|
||||
@@ -184,7 +216,7 @@ class SoundManager {
|
||||
}
|
||||
};
|
||||
playNote();
|
||||
this.musicTimer = setInterval(playNote, 900);
|
||||
this.musicTimer = setInterval(playNote, this.TRACKS[this.musicTrack].gap);
|
||||
}
|
||||
|
||||
stopMusic() {
|
||||
|
||||
Reference in New Issue
Block a user