Skip to content

Commit

Permalink
fix(sounds): listen for settings changes in StartMenu
Browse files Browse the repository at this point in the history
  • Loading branch information
iamludal committed Jan 1, 2022
1 parent 797fe09 commit 08e0582
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/components/Game.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
});
</script>

{#if state == 'IDLE'}
Expand Down

0 comments on commit 08e0582

Please sign in to comment.