WIP
This commit is contained in:
@@ -2,6 +2,7 @@ import { GameConfig } from "../types";
|
||||
import Board from "../board/Board";
|
||||
import Game from "../game/Game";
|
||||
import { setState } from "../state";
|
||||
import sfx from "./sfx";
|
||||
|
||||
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
@@ -99,7 +100,24 @@ class Player {
|
||||
|
||||
this.ply = ply;
|
||||
|
||||
await this.board.frame(this.getPosition(), this.game.header);
|
||||
const position = this.getPosition();
|
||||
|
||||
if (this.ply > 0) {
|
||||
if (/[ce]/.test(position.move?.flags as string)) {
|
||||
sfx.take.play();
|
||||
sfx.move.play();
|
||||
} else if (/[kqp]/.test(position.move?.flags as string)) {
|
||||
sfx.swap.play();
|
||||
sfx.move.play();
|
||||
} else if (position.mate) {
|
||||
sfx.snap.play();
|
||||
sfx.move.play();
|
||||
} else {
|
||||
sfx.move.play();
|
||||
}
|
||||
}
|
||||
|
||||
await this.board.frame(position, this.game.header);
|
||||
this.board.render();
|
||||
}
|
||||
|
||||
|
||||
22
src/player/sfx.ts
Normal file
22
src/player/sfx.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Howl } from "howler";
|
||||
|
||||
const sfx = {
|
||||
move: new Howl({
|
||||
src: ["/sfx/move.wav"],
|
||||
volume: 0.4,
|
||||
}),
|
||||
take: new Howl({
|
||||
src: ["/sfx/take.wav"],
|
||||
volume: 0.5,
|
||||
}),
|
||||
swap: new Howl({
|
||||
src: ["/sfx/swap.wav"],
|
||||
volume: 0.5,
|
||||
}),
|
||||
snap: new Howl({
|
||||
src: ["/sfx/snap.wav"],
|
||||
volume: 0.5,
|
||||
}),
|
||||
};
|
||||
|
||||
export default sfx;
|
||||
Reference in New Issue
Block a user