From 08e0582cf14e9b462a248b3d08c0b01f9ea51b10 Mon Sep 17 00:00:00 2001 From: Ludal Date: Sat, 1 Jan 2022 01:43:01 +0100 Subject: [PATCH] fix(sounds): listen for settings changes in StartMenu --- src/components/Game.svelte | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/Game.svelte b/src/components/Game.svelte index 11d78d3..8ac28b8 100644 --- a/src/components/Game.svelte +++ b/src/components/Game.svelte @@ -5,13 +5,15 @@ import Game from '../ts/game'; import type { GameService, States, words } from '../ts/types'; import { getScores, loadSettings, saveScore } from '../ts/utils'; + import { onMount } from 'svelte'; + import { settings } from '../ts/store'; export let wordsList: words; let state: States = 'IDLE'; let game: Game; - const settings = loadSettings(); + let soundsEnabled: boolean = loadSettings().soundsEnabled; const handleStateChange = (gs: GameService) => { state = gs.machine.current; @@ -22,9 +24,13 @@ const setState = (newState: States) => (state = newState); const start = () => { - game = new Game(wordsList, handleStateChange, settings.soundsEnabled); + game = new Game(wordsList, handleStateChange, soundsEnabled); game.start(); }; + + onMount(() => { + settings.subscribe(settings => (soundsEnabled = settings.soundsEnabled)); + }); {#if state == 'IDLE'}