mirror of
https://github.com/AndrioCelos/TableturfBattleApp.git
synced 2026-08-21 18:34:00 -05:00
Preserve player's ink colour in deck test after leaving a game
This commit is contained in:
@@ -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[]) {
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ interface Player {
|
||||
colour: Colour;
|
||||
specialColour: Colour;
|
||||
specialAccentColour: Colour;
|
||||
uiBaseColourIsSpecialColour?: boolean;
|
||||
uiBaseColourIsSpecialColour: boolean;
|
||||
sleeves: number;
|
||||
totalSpecialPoints: number;
|
||||
passes: number;
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user