From 22405f577086bec663821949aaa7aef5a81efbe2 Mon Sep 17 00:00:00 2001 From: Andrio Celos Date: Fri, 1 Dec 2023 10:55:37 +1100 Subject: [PATCH] Preserve player's ink colour in deck test after leaving a game --- TableturfBattleClient/src/Pages/GamePage.ts | 27 ++++++++++++++++--- .../src/Pages/PreGamePage.ts | 1 + TableturfBattleClient/src/Player.ts | 2 +- TableturfBattleClient/src/app.ts | 2 ++ 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/TableturfBattleClient/src/Pages/GamePage.ts b/TableturfBattleClient/src/Pages/GamePage.ts index 1d684e4..9c10e98 100644 --- a/TableturfBattleClient/src/Pages/GamePage.ts +++ b/TableturfBattleClient/src/Pages/GamePage.ts @@ -174,8 +174,7 @@ function initTest(stage: Stage) { testPlacements.splice(0); testUndoButton.enabled = false; clearChildren(testPlacementList); - gamePage.dataset.myPlayerIndex = '0'; - gamePage.dataset.uiBaseColourIsSpecialColour = uiBaseColourIsSpecialColourOutOfGame.toString(); + gameButtonsContainer.hidden = false; testControls.hidden = false; clearPlayContainers(); @@ -191,6 +190,27 @@ function initTest(stage: Stage) { button.enabled = true; } +function swapColours() { + // Swap colours to preserve the player's ink colour. + const oldPlayerIndex = parseInt(gamePage.dataset.myPlayerIndex ?? '0'); + if (oldPlayerIndex) { + swapColour('primary', oldPlayerIndex); + swapColour('special', oldPlayerIndex); + swapColour('special-accent', oldPlayerIndex); + const temp = uiBaseColourIsSpecialColourPerPlayer[0]; + uiBaseColourIsSpecialColourPerPlayer[0] = uiBaseColourIsSpecialColourPerPlayer[oldPlayerIndex]; + uiBaseColourIsSpecialColourPerPlayer[oldPlayerIndex] = temp; + } + gamePage.dataset.myPlayerIndex = '0'; + uiBaseColourIsSpecialColourOutOfGame = uiBaseColourIsSpecialColourPerPlayer[0]; + gamePage.dataset.uiBaseColourIsSpecialColour = uiBaseColourIsSpecialColourOutOfGame.toString(); +} +function swapColour(prefix: string, oldPlayerIndex: number) { + const temp = document.body.style.getPropertyValue(`--${prefix}-colour-1`); + document.body.style.setProperty(`--${prefix}-colour-1`, document.body.style.getPropertyValue(`--${prefix}-colour-${oldPlayerIndex + 1}`)); + document.body.style.setProperty(`--${prefix}-colour-${oldPlayerIndex + 1}`, temp); +} + replayNextButton.buttonElement.addEventListener('click', _ => { if (currentGame == null || currentReplay == null || currentGame.game.state == GameState.GameEnded || currentGame.game.state == GameState.SetEnded) return; @@ -549,9 +569,10 @@ function updateColours() { updateHSL(i, j); updateRGB(i, j); } + uiBaseColourIsSpecialColourPerPlayer[i] = currentGame.game.players[i].uiBaseColourIsSpecialColour; } } - uiBaseColourIsSpecialColourOutOfGame = currentGame.game.players[0].uiBaseColourIsSpecialColour ?? true; + uiBaseColourIsSpecialColourOutOfGame = uiBaseColourIsSpecialColourPerPlayer[currentGame?.me?.playerIndex ?? 0]; } function updateStats(playerIndex: number, scores: number[]) { diff --git a/TableturfBattleClient/src/Pages/PreGamePage.ts b/TableturfBattleClient/src/Pages/PreGamePage.ts index cba5dea..bc5d793 100644 --- a/TableturfBattleClient/src/Pages/PreGamePage.ts +++ b/TableturfBattleClient/src/Pages/PreGamePage.ts @@ -335,6 +335,7 @@ optionsColourLock.addEventListener('change', () => { document.body.style.removeProperty(`--special-colour-${i}`); document.body.style.removeProperty(`--special-accent-colour-${i}`); uiBaseColourIsSpecialColourOutOfGame = true; + uiBaseColourIsSpecialColourPerPlayer = [ true, false, true, true ]; gamePage.dataset.uiBaseColourIsSpecialColour = 'true'; } } diff --git a/TableturfBattleClient/src/Player.ts b/TableturfBattleClient/src/Player.ts index 2a12102..f377738 100644 --- a/TableturfBattleClient/src/Player.ts +++ b/TableturfBattleClient/src/Player.ts @@ -6,7 +6,7 @@ interface Player { colour: Colour; specialColour: Colour; specialAccentColour: Colour; - uiBaseColourIsSpecialColour?: boolean; + uiBaseColourIsSpecialColour: boolean; sleeves: number; totalSpecialPoints: number; passes: number; diff --git a/TableturfBattleClient/src/app.ts b/TableturfBattleClient/src/app.ts index ea92573..615c6ec 100644 --- a/TableturfBattleClient/src/app.ts +++ b/TableturfBattleClient/src/app.ts @@ -7,6 +7,7 @@ const defaultColours = [ [ { r: 6, g: 249, b: 148 }, { r: 6, g: 249, b: 6 }, { r: 180, g: 253, b: 199 } ] ]; let uiBaseColourIsSpecialColourOutOfGame = true; +let uiBaseColourIsSpecialColourPerPlayer = [ true, false, true, true ]; const errorDialog = document.getElementById('errorDialog') as HTMLDialogElement; const errorMessage = document.getElementById('errorMessage')!; @@ -477,6 +478,7 @@ function processUrl() { return false; } } + swapColours(); stopEditingDeck(); errorDialog.close(); clearGame();