Don't unload soundSet-independent sounds on soundSet change (#10126)

* Don't unload soundSet-independent sounds on soundSet change

* Fix lint

* Fix lint 2
deepcrayonfish^2
Benedikt Werner 2021-11-17 08:05:55 +01:00 committed by GitHub
parent d4f87c1575
commit 1108c4b843
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 12 deletions

View File

@ -102,7 +102,7 @@ interface UserCompleteOpts {
}
interface SoundI {
loadOggOrMp3(name: string, path: string): void;
loadOggOrMp3(name: string, path: string, noSoundSet?: boolean): void;
loadStandard(name: string, soundSet?: string): void;
play(name: string, volume?: number): void;
playOnce(name: string): void;

View File

@ -15,8 +15,8 @@ export default function (root: AnalyseCtrl, studyData: StudyData, data: StudyPra
analysisUrl = prop(''),
autoNext = storedProp('practice-auto-next', true);
lichess.sound.loadOggOrMp3('practiceSuccess', `${lichess.sound.baseUrl}/other/energy3`);
lichess.sound.loadOggOrMp3('practiceFailure', `${lichess.sound.baseUrl}/other/failure2`);
lichess.sound.loadOggOrMp3('practiceSuccess', `${lichess.sound.baseUrl}/other/energy3`, true);
lichess.sound.loadOggOrMp3('practiceFailure', `${lichess.sound.baseUrl}/other/failure2`, true);
function onLoad() {
root.showAutoShapes = readOnlyProp(true);

View File

@ -1,5 +1,5 @@
const make = (file: string, volume?: number) => {
lichess.sound.loadOggOrMp3(file, `${lichess.sound.baseUrl}/${file}`);
lichess.sound.loadOggOrMp3(file, `${lichess.sound.baseUrl}/${file}`, true);
return () => lichess.sound.play(file, volume);
};

View File

@ -10,7 +10,7 @@ export const uciToLastMove = (uci: string | undefined): [Key, Key] | undefined =
export const puzzlePov = (puzzle: Puzzle) => opposite(parseFen(puzzle.fen).unwrap().turn);
export const loadSound = (file: string, volume?: number, delay?: number) => {
setTimeout(() => lichess.sound.loadOggOrMp3(file, `${lichess.sound.baseUrl}/${file}`), delay || 1000);
setTimeout(() => lichess.sound.loadOggOrMp3(file, `${lichess.sound.baseUrl}/${file}`, true), delay || 1000);
return () => lichess.sound.play(file, volume);
};

View File

@ -50,7 +50,7 @@ export default function (opts: PuzzleOpts, redraw: Redraw): Controller {
const throttleSound = (name: string) => throttle(100, () => lichess.sound.play(name));
const loadSound = (file: string, volume?: number, delay?: number) => {
setTimeout(() => lichess.sound.loadOggOrMp3(file, `${lichess.sound.baseUrl}/${file}`), delay || 1000);
setTimeout(() => lichess.sound.loadOggOrMp3(file, `${lichess.sound.baseUrl}/${file}`, true), delay || 1000);
return () => lichess.sound.play(file, volume);
};
const sound = {

View File

@ -18,7 +18,8 @@ type Name = string;
type Path = string;
const sound: SoundI = new (class {
sounds = new Map<Name, Howl>(); // The loaded sounds and their instances
soundSetSounds = new Map<Name, Howl>(); // The loaded sounds and their instances
standaloneSounds = new Map<Name, Howl>(); // Sounds that are independent of the sound set
soundSet = $('body').data('sound-set');
speechStorage = storage.makeBoolean('speech.enabled');
volumeStorage = storage.make('sound-volume');
@ -30,8 +31,8 @@ const sound: SoundI = new (class {
if (this.soundSet == 'music') setTimeout(this.publish, 500);
}
loadOggOrMp3 = (name: Name, path: Path) =>
this.sounds.set(
loadOggOrMp3 = (name: Name, path: Path, noSoundSet = false) =>
(noSoundSet ? this.standaloneSounds : this.soundSetSounds).set(
name,
new Howl({
src: ['ogg', 'mp3'].map(ext => `${path}.${ext}`),
@ -49,10 +50,10 @@ const sound: SoundI = new (class {
}
private getOrLoadSound = (name: string, set: string): Howl => {
let s = this.sounds.get(name);
let s = this.soundSetSounds.get(name) ?? this.standaloneSounds.get(name);
if (!s) {
this.loadStandard(name, set);
s = this.sounds.get(name)!;
s = this.soundSetSounds.get(name)!;
}
return s;
};
@ -115,7 +116,7 @@ const sound: SoundI = new (class {
changeSet = (s: string) => {
this.soundSet = s;
this.sounds.clear();
this.soundSetSounds.clear();
this.publish();
};