Fix board flip sometimes not flipping

This commit is contained in:
Andrio Celos
2023-12-01 10:54:19 +11:00
parent df838f9c37
commit 1e3525663f
3 changed files with 6 additions and 6 deletions

View File

@@ -354,9 +354,6 @@ class Board {
resize(grid?: Space[][]) {
if (grid) this.grid = grid;
if (this.cells.length == this.grid.length && this.cells[0].length == this.grid[0].length)
return; // Reconnected and board size did not change.
clearChildren(this.table);
this.cells.splice(0);
this.highlightedCells.splice(0);
@@ -387,8 +384,8 @@ class Board {
if (e.pointerType != 'touch') {
if (this.autoHighlight && this.cardPlaying != null) {
const offset = this.rotatedMouseOffset;
const x = parseInt((e.target as HTMLTableCellElement).dataset.x!) - (this.flip ? Math.ceil(offset.x) : Math.floor(offset.x));
const y = parseInt((e.target as HTMLTableCellElement).dataset.y!) - (this.flip ? Math.ceil(offset.y) : Math.floor(offset.y));
const x = parseInt((e.currentTarget as HTMLTableCellElement).dataset.x!) - (this.flip ? Math.ceil(offset.x) : Math.floor(offset.x));
const y = parseInt((e.currentTarget as HTMLTableCellElement).dataset.y!) - (this.flip ? Math.ceil(offset.y) : Math.floor(offset.y));
if (x != this.highlightX || y != this.highlightY) {
this.highlightX = x;
this.highlightY = y;

View File

@@ -124,6 +124,7 @@ function initSpectator() {
flipButton.hidden = false;
gameButtonsContainer.hidden = false;
board.autoHighlight = false;
board.flip = false;
showPage('game');
}
@@ -141,6 +142,7 @@ function initReplay() {
flipButton.hidden = false;
gameButtonsContainer.hidden = false;
gamePage.dataset.myPlayerIndex = '0';
board.flip = false;
updateColours();
gamePage.dataset.uiBaseColourIsSpecialColour = (userConfig.colourLock || (currentGame!.game.players[0].uiBaseColourIsSpecialColour ?? true)).toString();
canPlay = false;
@@ -157,6 +159,7 @@ function initTest(stage: Stage) {
testMode = true;
gamePage.classList.add('deckTest');
currentGame = { id: 'test', game: { state: GameState.Ongoing, maxPlayers: 2, players: [ ], turnNumber: 1, turnTimeLimit: null, turnTimeLeft: null, goalWinCount: null, allowUpcomingCards: true }, me: { playerIndex: 0, move: null, deck: null, hand: null, cardsUsed: [ ], stageSelectionPrompt: null }, isHost: false, webSocket: null };
board.flip = false;
board.resize(stage.copyGrid());
const startSpaces = stage.getStartSpaces(2);
board.startSpaces = startSpaces;

View File

@@ -128,7 +128,7 @@ function onGameStateChange(game: any, playerData: PlayerData | null) {
board.flip = playerData != null && playerData.playerIndex % 2 != 0;
if (board.flip) gamePage.classList.add('boardFlipped');
else gamePage.classList.remove('boardFlipped');
board.resize(game.board);
if (!isSameTurnReconnect) board.resize(game.board);
board.startSpaces = game.startSpaces;
if (!isSameTurnReconnect) board.refresh();
}