diff --git a/assets/scripts/lobby/buttonEventListeners2.js b/assets/scripts/lobby/buttonEventListeners2.js index 9a48530e4..2491d26ea 100644 --- a/assets/scripts/lobby/buttonEventListeners2.js +++ b/assets/scripts/lobby/buttonEventListeners2.js @@ -1,93 +1,79 @@ -function redButtonFunction() { - console.log('red'); - // if the button isn't disabled - if ( - document.querySelector('#red-button').classList.contains('disabled') === - false - ) { - if (isSpectator === true) { - } else if (gameStarted === false) { - // if we are spectating - if (document.querySelector('#red-button').innerText === 'Spectate') { - socket.emit('standUpFromGame'); - // remove claim status when a player sits down - // then stands up - socket.emit('setClaim', false); - - enableDisableButtons(); - } - // we are the host, open kick menu - else { - // host kicking - // Set the kick modal content - let str = '

Select the players you want to kick.

'; - - str += '
'; - - for (let i = 0; i < roomPlayersData.length; i++) { - if (ownUsername !== roomPlayersData[i].username) { - str += ''; - str += '
'; - } else { - str += ''; - str += '
'; - } + if (isSpectator === true) { + } else if (gameStarted === false) { + // non-host player standing up + if (document.querySelector('#red-button').innerText === 'Spectate') { + socket.emit('standUpFromGame'); + socket.emit('setClaim', false); + enableDisableButtons(); + } + // host opening kick menu + else { + let str = '

Select the players you want to kick.

'; + str += '
'; + for (let i = 0; i < roomPlayersData.length; i++) { + if (ownUsername !== roomPlayersData[i].username) { + str += ''; + str += '
'; + } else { + str += ''; + str += '
'; } - - str += '
'; - - $('#kickModalContent')[0].innerHTML = str; } - } else if ( - gameData.phase === 'VotingTeam' || - gameData.phase === 'VotingMission' - ) { - socket.emit('gameMove', ['no', []]); + str += '
'; + $('#kickModalContent')[0].innerHTML = str; } - $('#mainRoomBox div').removeClass('highlight-avatar'); + } else if ( + gameData.phase === 'VotingTeam' && + !(await preventMisclick('no')) + ) { + socket.emit('gameMove', ['no', []]); + } else if (gameData.phase === 'VotingMission') { + socket.emit('gameMove', ['no', []]); } + + $('#mainRoomBox div').removeClass('highlight-avatar'); } -function greenButtonFunction() { - // if button isn't disabled: - if ( - document.querySelector('#green-button').classList.contains('disabled') === - false - ) { - if (isSpectator === true) { - socket.emit('join-game', roomId); - } else if (gameStarted === false) { - const startGameData = { - options: getOptions(), - gameMode: $($('.gameModeSelect')[1]).val(), - timeouts: { - default: ((parseInt($('#startGameOptionsDefaultPhaseTimeoutMin').val()) * 60 + parseInt($('#startGameOptionsDefaultPhaseTimeoutSec').val())) * 1000).toString(), - critMission: ((parseInt($('#startGameOptionsCritMissionTimeoutMin').val()) * 60 + parseInt($('#startGameOptionsCritMissionTimeoutSec').val())) * 1000).toString(), - assassination: ((parseInt($('#startGameOptionsAssassinationPhaseTimeoutMin').val()) * 60 + parseInt($('#startGameOptionsAssassinationPhaseTimeoutSec').val())) * 1000).toString(), - }, - anonymousMode: $('#startGameOptionsAnonymousMode')[0].checked, - }; - - socket.emit('startGame', startGameData); - } else if ( - gameData.phase === 'VotingTeam' || - gameData.phase === 'VotingMission' - ) { - socket.emit('gameMove', ['yes', []]); - } else { - socket.emit('gameMove', ['yes', getHighlightedAvatars()]); - } +async function greenButtonFunction() { + if (document.querySelector('#green-button').classList.contains('disabled') === true) { + return; + } - $('#mainRoomBox div').removeClass('highlight-avatar'); + if (isSpectator === true) { + socket.emit('join-game', roomId); + } else if (gameStarted === false) { + const startGameData = { + options: getOptions(), + gameMode: $($('.gameModeSelect')[1]).val(), + timeouts: { + default: ((parseInt($('#startGameOptionsDefaultPhaseTimeoutMin').val()) * 60 + parseInt($('#startGameOptionsDefaultPhaseTimeoutSec').val())) * 1000).toString(), + critMission: ((parseInt($('#startGameOptionsCritMissionTimeoutMin').val()) * 60 + parseInt($('#startGameOptionsCritMissionTimeoutSec').val())) * 1000).toString(), + assassination: ((parseInt($('#startGameOptionsAssassinationPhaseTimeoutMin').val()) * 60 + parseInt($('#startGameOptionsAssassinationPhaseTimeoutSec').val())) * 1000).toString(), + }, + anonymousMode: $('#startGameOptionsAnonymousMode')[0].checked, + }; + socket.emit('startGame', startGameData); + } else if ( + gameData.phase === 'VotingTeam' && + !(await preventMisclick('yes')) + ) { + socket.emit('gameMove', ['yes', []]); + } else if (gameData.phase === 'VotingMission') { + socket.emit('gameMove', ['yes', []]); + } else if (gameData.phase === 'PickingTeam') { + socket.emit('gameMove', ['yes', getHighlightedAvatars()]); } + + $('#mainRoomBox div').removeClass('highlight-avatar'); } //= ===================================== @@ -259,3 +245,48 @@ function handleTimeoutInput(inputId) { input.value = 60; } } + +async function preventMisclick(button) { + if ( + $('#optionGameplayPreventMisclicks')[0].checked === false || + // only applies to 6 player + gameData.playerUsernamesOrdered.length !== 6 + ) { + return false; + } + + const isPlayerOnTeam = gameData.proposedTeam.includes(gameData.username); + const missionsToCatchOnrej = [1, 2]; + const missionsToCatchOffapp = [1, 2, 3, 5]; + let isVoteExpected = true; + let str = ''; + if (gameData.pickNum === 5) { + isVoteExpected = button === 'yes'; + str = 'Really reject hammer?' + } else if ( + isPlayerOnTeam && + missionsToCatchOnrej.includes(gameData.missionNum) + ) { + isVoteExpected = button === 'yes'; + str = 'You\'re on the team!' + } else if ( + !isPlayerOnTeam && + missionsToCatchOffapp.includes(gameData.missionNum) + ) { + isVoteExpected = button === 'no'; + str = 'You\'re off the team!' + } + if (isVoteExpected) { + return false; + } + // launch sweetalert to confirm click + const input = await swal({ + title: str, + type: 'warning', + showCancelButton: true, + reverseButtons: true, + confirmButtonText: button === 'yes' ? 'Approve' : 'Reject', + confirmButtonColor: button === 'yes' ? '#5cb85c' : '#d9534f', + }); + return !input.value; +} diff --git a/assets/scripts/lobby/options.js b/assets/scripts/lobby/options.js index c8c71c497..9b8bea46c 100644 --- a/assets/scripts/lobby/options.js +++ b/assets/scripts/lobby/options.js @@ -1193,6 +1193,29 @@ var userOptions = { ); }, }, + + //--------------------------------------------- + // Gameplay + //--------------------------------------------- + + optionGameplayPreventMisclicks: { + defaultValue: 'false', + onLoad() { + if (docCookies.getItem('optionGameplayPreventMisclicks') === 'true') { + $('#optionGameplayPreventMisclicks')[0].checked = true; + } + }, + initialiseEventListener() { + $('#optionGameplayPreventMisclicks')[0].addEventListener('click', () => { + const { checked } = $('#optionGameplayPreventMisclicks')[0]; + docCookies.setItem( + 'optionGameplayPreventMisclicks', + checked.toString(), + Infinity + ); + }); + }, + }, }; // run through each userOption load and initialiseEventListener diff --git a/src/views/partials/header.ejs b/src/views/partials/header.ejs index 4040b01c0..227f02f16 100644 --- a/src/views/partials/header.ejs +++ b/src/views/partials/header.ejs @@ -300,6 +300,14 @@ + + + + Gameplay + + + + @@ -453,7 +461,21 @@ - +