diff options
| author | Maksymilian Jopek <maks@jopek.eu> | 2023-04-03 22:12:41 +0200 |
|---|---|---|
| committer | Maksymilian Jopek <maks@jopek.eu> | 2023-04-03 22:12:41 +0200 |
| commit | 1df1ff6f074528a4ad6d4015c794a1555c1c942f (patch) | |
| tree | ad3b16291748c60441967996706006555919ef73 /frontend/ts/startGame.ts | |
| parent | c813dfadd4b673080695ef3ade37a44e37036c07 (diff) | |
| download | fia-1df1ff6f074528a4ad6d4015c794a1555c1c942f.tar.gz fia-1df1ff6f074528a4ad6d4015c794a1555c1c942f.tar.zst fia-1df1ff6f074528a4ad6d4015c794a1555c1c942f.zip | |
Polishing up
Add all files to repo
Add sql database
Correct urls
Add PHP code to repo
Update README.md with instructions how to start
Move from yarn to pnpm
Fix all issues with starting
Fix possibility of player changing their dice roll with refreshing the game
Diffstat (limited to 'frontend/ts/startGame.ts')
| -rw-r--r-- | frontend/ts/startGame.ts | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/frontend/ts/startGame.ts b/frontend/ts/startGame.ts index 7da81d4..4f83567 100644 --- a/frontend/ts/startGame.ts +++ b/frontend/ts/startGame.ts @@ -40,7 +40,7 @@ export default class StartGame { } async init(data: { data: Data, uid: string }) { - document.body.innerHTML = await (await fetch("/fia/map.html")).text(); + document.body.innerHTML = await (await fetch("map.html")).text(); if (speechSynthesis.onvoiceschanged !== undefined) speechSynthesis.onvoiceschanged = () => this.voices = speechSynthesis.getVoices(); @@ -99,7 +99,7 @@ export default class StartGame { return; } this.toggleStop = true; - let res = await Helpers.mFetch("/fia/readyStateToggle", { + let res = await Helpers.mFetch("readyStateToggle", { state: this.inpStateToggle.checked }); if (res.started === true) @@ -117,7 +117,9 @@ export default class StartGame { } rollDice = async (e: MouseEvent): Promise<void> => { this.btnRollDice.style.display = "none"; - let number = Helpers.getRandomInt(1, 7); + const oldNumber = localStorage.getItem("number"); + let number = oldNumber ? parseInt(oldNumber) : Helpers.getRandomInt(1, 7); + localStorage.setItem("number", number.toString()); this.say(number.toString()); this.diceHash; @@ -212,8 +214,8 @@ export default class StartGame { this.btnRollDice.style.display = "none"; this.timer.stop(); await this.sendGameBoard(false); - await Helpers.mFetch("/fia/won", { index: this.index }); - await Helpers.mFetch("/fia/reset", {}); + await Helpers.mFetch("won", { index: this.index }); + await Helpers.mFetch("reset", {}); alert("Du vann spelet !!!"); return; } @@ -242,7 +244,8 @@ export default class StartGame { this.timer.stop(); this.gameWasStopped = true; this.hideDice(diceWait); - await Helpers.mFetch("/fia/saveGameBoard", { gameBoard: this.gameBoard }); + localStorage.removeItem("number"); + await Helpers.mFetch("saveGameBoard", { gameBoard: this.gameBoard }); } drawChequer = (coords: Coordinates, color: tColors, chequer: Chequer | HoBSquare): void => { @@ -271,7 +274,7 @@ export default class StartGame { async getData() { let data: { gameBoard: GameBoard, currentPlayer: number, started: number, data: Data, timeTillTurnEnd: number, winner: null | number } - = await Helpers.mFetch("/fia/getCurrentGameState", {}); + = await Helpers.mFetch("getCurrentGameState", {}); console.log("Data fetched"); if (data.started === 1 && data.winner !== null) { @@ -281,7 +284,7 @@ export default class StartGame { let winnerName = this.data.filter(el => el.index === data.winner)[0].name; gameBoardClass.drawGameBoard(data.gameBoard, this.drawChequer); alert(`Spelaren ${winnerName} vann spelet!!!`); - await Helpers.mFetch("/fia/reset", {}); + await Helpers.mFetch("reset", {}); return; } |
