mirror of
https://github.com/AndrioCelos/TableturfBattleApp.git
synced 2026-08-28 13:53:59 -05:00
Allow the host to set the turn time limit in the lobby page
Suggested by Ljovynn. It can be set only before the first battle.
This commit is contained in:
@@ -101,6 +101,12 @@ function lobbyResetSlots() {
|
||||
playerListItems.push(el);
|
||||
playerList.appendChild(el);
|
||||
}
|
||||
|
||||
lobbyLockSettings(currentGame.me?.playerIndex != 0);
|
||||
}
|
||||
|
||||
function lobbyLockSettings(lock: boolean) {
|
||||
lobbyTimeLimitBox.readOnly = lock;
|
||||
}
|
||||
|
||||
function clearReady() {
|
||||
@@ -169,6 +175,15 @@ function initDeckSelection() {
|
||||
}
|
||||
}
|
||||
|
||||
lobbyTimeLimitBox.addEventListener('change', () => {
|
||||
let req = new XMLHttpRequest();
|
||||
req.open('POST', `${config.apiBaseUrl}/games/${currentGame!.id}/setTurnTimeLimit`);
|
||||
let data = new URLSearchParams();
|
||||
data.append('clientToken', clientToken);
|
||||
data.append('turnTimeLimit', lobbyTimeLimitBox.value || '');
|
||||
req.send(data.toString());
|
||||
});
|
||||
|
||||
deckSelectionForm.addEventListener('submit', e => {
|
||||
e.preventDefault();
|
||||
if (selectedDeck == null) return;
|
||||
|
||||
@@ -95,6 +95,12 @@ function clearUrlFromGame() {
|
||||
location.hash = '';
|
||||
}
|
||||
|
||||
function onGameSettingsChange() {
|
||||
if (currentGame == null) return;
|
||||
if (lobbyTimeLimitBox.value != currentGame.turnTimeLimit?.toString() ?? '')
|
||||
lobbyTimeLimitBox.value = currentGame.turnTimeLimit?.toString() ?? '';
|
||||
}
|
||||
|
||||
function onGameStateChange(game: any, playerData: PlayerData | null) {
|
||||
if (currentGame == null)
|
||||
throw new Error('currentGame is null');
|
||||
@@ -113,6 +119,9 @@ function onGameStateChange(game: any, playerData: PlayerData | null) {
|
||||
gamePage.dataset.myPlayerIndex = playerData ? playerData.playerIndex.toString() : '';
|
||||
gamePage.dataset.uiBaseColourIsSpecialColour = playerData && game.players[playerData.playerIndex].uiBaseColourIsSpecialColour ? 'true' : 'false';
|
||||
|
||||
if (game.stage != GameState.WaitingForPlayers)
|
||||
lobbyLockSettings(true);
|
||||
|
||||
redrawModal.hidden = true;
|
||||
gamePage.classList.remove('gameEnded');
|
||||
switch (game.state) {
|
||||
@@ -252,8 +261,7 @@ function setupWebSocket(gameID: string) {
|
||||
lobbyResetSlots();
|
||||
for (let i = 0; i < currentGame.players.length; i++)
|
||||
lobbyAddPlayer(i);
|
||||
lobbyTimeLimitBox.value = currentGame.turnTimeLimit?.toString() ?? '';
|
||||
lobbyTimeLimitUnit.hidden = currentGame.turnTimeLimit == null;
|
||||
onGameSettingsChange();
|
||||
|
||||
for (let i = 0; i < playerBars.length; i++) {
|
||||
playerBars[i].visible = i < currentGame.maxPlayers;
|
||||
@@ -298,6 +306,10 @@ function setupWebSocket(gameID: string) {
|
||||
return;
|
||||
}
|
||||
switch (payload.event) {
|
||||
case 'settingsChange':
|
||||
currentGame.turnTimeLimit = payload.data.turnTimeLimit;
|
||||
onGameSettingsChange();
|
||||
break;
|
||||
case 'join':
|
||||
if (payload.data.playerIndex == currentGame.players.length) {
|
||||
currentGame.players.push(payload.data.player);
|
||||
|
||||
Reference in New Issue
Block a user