Preserve player's ink colour in deck test after leaving a game

This commit is contained in:
Andrio Celos
2023-12-01 10:55:37 +11:00
parent 1e3525663f
commit 22405f5770
4 changed files with 28 additions and 4 deletions

View File

@@ -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[]) {

View File

@@ -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';
}
}

View File

@@ -6,7 +6,7 @@ interface Player {
colour: Colour;
specialColour: Colour;
specialAccentColour: Colour;
uiBaseColourIsSpecialColour?: boolean;
uiBaseColourIsSpecialColour: boolean;
sleeves: number;
totalSpecialPoints: number;
passes: number;

View File

@@ -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();