This commit is contained in:
Maciej Caderek
2022-04-15 02:50:57 +02:00
parent 85d5d01cb0
commit 8362ebb2a4
19 changed files with 93 additions and 43 deletions

View File

@@ -119,12 +119,43 @@ class Player {
if (this.ply > 0 && state.siteConfig.sounds) {
if (position.mate) {
sfx.snap.play();
if (position.move?.flags && position.move.flags.includes("e")) {
sfx.fanfare.play();
} else if (position.move?.piece === "r") {
position.move.flags.includes("c")
? sfx.brickTake.play()
: sfx.brickMove.play();
}
} else if (/[ce]/.test(position.move?.flags as string)) {
sfx.take.play();
if (position.move?.piece === "r") {
sfx.brickTake.play();
} else {
sfx.take.play();
}
if (
position.move?.piece === "n" &&
state.boardConfig.piecesStyle === "anarchy"
) {
sfx.neigh.play();
} else if (position.move?.flags && position.move.flags.includes("e")) {
sfx.fanfare.play();
}
} else if (/[kqp]/.test(position.move?.flags as string)) {
sfx.swap.play();
} else {
sfx.move.play();
if (position.move?.piece === "r") {
sfx.brickMove.play();
} else {
sfx.move.play();
}
if (
position.move?.piece === "n" &&
state.boardConfig.piecesStyle === "anarchy"
) {
sfx.snort.play();
}
}
}

View File

@@ -21,6 +21,26 @@ const sfx = {
src: ["/sfx/rewind.wav"],
volume: 0.2,
}),
snort: new Howl({
src: ["/sfx/snort.wav"],
volume: 0.5,
}),
neigh: new Howl({
src: ["/sfx/neigh.wav"],
volume: 0.5,
}),
fanfare: new Howl({
src: ["/sfx/fanfare.wav"],
volume: 0.5,
}),
brickMove: new Howl({
src: ["/sfx/brick-move.wav"],
volume: 0.5,
}),
brickTake: new Howl({
src: ["/sfx/brick-take.wav"],
volume: 0.5,
}),
};
export default sfx;