This commit is contained in:
Maciej Caderek
2022-03-24 03:25:52 +01:00
parent 83fe7b301e
commit e71b8198f9
5 changed files with 21 additions and 3 deletions

View File

@@ -221,6 +221,10 @@ const main = async () => {
download(data, name, state.gameConfig.format.toLowerCase()); download(data, name, state.gameConfig.format.toLowerCase());
}, },
toggleSound() {
setState("boardConfig", "sounds", !state.boardConfig.sounds);
saveConfig("board");
},
}; };
/* Render the page */ /* Render the page */

View File

@@ -1,7 +1,7 @@
import { GameConfig } from "../types"; import { GameConfig } from "../types";
import Board from "../board/Board"; import Board from "../board/Board";
import Game from "../game/Game"; import Game from "../game/Game";
import { setState } from "../state"; import { setState, state } from "../state";
import sfx from "./sfx"; import sfx from "./sfx";
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
@@ -102,7 +102,7 @@ class Player {
const position = this.getPosition(); const position = this.getPosition();
if (this.ply > 0) { if (this.ply > 0 && state.boardConfig.sounds) {
if (position.mate) { if (position.mate) {
sfx.snap.play(); sfx.snap.play();
} else if (/[ce]/.test(position.move?.flags as string)) { } else if (/[ce]/.test(position.move?.flags as string)) {

View File

@@ -20,6 +20,7 @@ const initialBoardConfig: BoardConfig = {
showChecks: true, showChecks: true,
showCoords: true, showCoords: true,
showShadows: false, showShadows: false,
sounds: true,
flipped: false, flipped: false,
}; };

View File

@@ -89,6 +89,7 @@ export type BoardConfig = {
showChecks: boolean; showChecks: boolean;
showCoords: boolean; showCoords: boolean;
showShadows: boolean; showShadows: boolean;
sounds: boolean;
flipped: boolean; flipped: boolean;
}; };
@@ -171,6 +172,7 @@ export type Handlers = {
load: (data: string) => Promise<boolean>; load: (data: string) => Promise<boolean>;
downloadImage: () => Promise<void>; downloadImage: () => Promise<void>;
downloadAnimation: () => Promise<void>; downloadAnimation: () => Promise<void>;
toggleSound(): void;
}; };
export type Header = { export type Header = {

View File

@@ -71,7 +71,7 @@ const Share: Component<{ handlers: Handlers; class?: string }> = (props) => {
<button <button
classList={{ classList={{
options__button: true, options__button: true,
"options__button--last": true, "options__button--last": false,
"options__button--active": state.boardConfig.showShadows, "options__button--active": state.boardConfig.showShadows,
}} }}
onClick={props.handlers.toggleShadows} onClick={props.handlers.toggleShadows}
@@ -81,6 +81,17 @@ const Share: Component<{ handlers: Handlers; class?: string }> = (props) => {
> >
<i class="las la-cloud"></i> <i class="las la-cloud"></i>
</button> </button>
<button
classList={{
options__button: true,
"options__button--last": true,
"options__button--active": state.boardConfig.sounds,
}}
onClick={props.handlers.toggleSound}
title={state.boardConfig.sounds ? "MUTE" : "SOUND ON"}
>
<i class="las la-volume-up"></i>
</button>
</div> </div>
<hr /> <hr />
<div className="share__fen"> <div className="share__fen">