Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 113 additions & 71 deletions assets/scripts/lobby/buttonEventListeners2.js
Original file line number Diff line number Diff line change
@@ -1,93 +1,78 @@
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 = '<h4>Select the players you want to kick.</h4>';

str += '<div class="btn-group-vertical" data-toggle="buttons">';

for (let i = 0; i < roomPlayersData.length; i++) {
if (ownUsername !== roomPlayersData[i].username) {
str += '<label class="btn btn-mine">';

str += `<input name="${roomPlayersData[i].username}" id="${roomPlayersData[i].username}" type="checkbox" autocomplete="off">${roomPlayersData[i].username}`;

str += '</label>';
str += '<br>';
} else {
str += '<label class="btn btn-mine" style="display: none;">';

str += `<input name="${roomPlayersData[i].username}" id="${roomPlayersData[i].username}" type="checkbox" autocomplete="off">${roomPlayersData[i].username}`;
async function redButtonFunction() {
if (document.querySelector('#red-button').classList.contains('disabled') === true) {
return;
}

str += '</label>';
str += '<br>';
}
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 = '<h4>Select the players you want to kick.</h4>';
str += '<div class="btn-group-vertical" data-toggle="buttons">';
for (let i = 0; i < roomPlayersData.length; i++) {
if (ownUsername !== roomPlayersData[i].username) {
str += '<label class="btn btn-mine">';
str += `<input name="${roomPlayersData[i].username}" id="${roomPlayersData[i].username}" type="checkbox" autocomplete="off">${roomPlayersData[i].username}`;
str += '</label>';
str += '<br>';
} else {
str += '<label class="btn btn-mine" style="display: none;">';
str += `<input name="${roomPlayersData[i].username}" id="${roomPlayersData[i].username}" type="checkbox" autocomplete="off">${roomPlayersData[i].username}`;
str += '</label>';
str += '<br>';
}

str += '</div>';

$('#kickModalContent')[0].innerHTML = str;
}
} else if (
str += '</div>';
$('#kickModalContent')[0].innerHTML = str;
}
} else if (await confirmUserClick('no')) {
if (
gameData.phase === 'VotingTeam' ||
gameData.phase === 'VotingMission'
) {
socket.emit('gameMove', ['no', []]);
}
$('#mainRoomBox div').removeClass('highlight-avatar');
}

$('#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 (
async function greenButtonFunction() {
if (document.querySelector('#green-button').classList.contains('disabled') === true) {
return;
}

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 (await confirmUserClick('yes')) {
if (
gameData.phase === 'VotingTeam' ||
gameData.phase === 'VotingMission'
) {
socket.emit('gameMove', ['yes', []]);
} else {
socket.emit('gameMove', ['yes', getHighlightedAvatars()]);
}

$('#mainRoomBox div').removeClass('highlight-avatar');
}

$('#mainRoomBox div').removeClass('highlight-avatar');
}

//= =====================================
Expand Down Expand Up @@ -259,3 +244,60 @@ function handleTimeoutInput(inputId) {
input.value = 60;
}
}

// Triggers swal on unexpected move if misclick prevention is enabled
async function confirmUserClick(button) {
if ($('#option_gameplay_prevent_misclicks')[0].checked !== true) {
return true;
}

let str = '';
if (gameData.phase === 'VotingTeam') {
const isPlayerOnTeam = gameData.proposedTeam.includes(gameData.username);

// catch hammerrej
if (gameData.pickNum === 5) {
if (
$('#option_gameplay_prevent_hammerrej')[0].checked === true &&
button === 'no'
) {
str = 'Really reject hammer?'
}
// catch onrej
} else if (
$('#option_gameplay_prevent_onrej_m' + gameData.missionNum)[0].checked === true &&
isPlayerOnTeam &&
button === 'no'
) {
str = "You're on the team!"
// catch offapp
} else if (
$('#option_gameplay_prevent_offapp_m' + gameData.missionNum)[0].checked === true &&
!isPlayerOnTeam &&
button === 'yes'
) {
str = "You're off the team!"
}
}

if (str === '') {
return true;
}

let timeout = 0;
if (gameData.dateTimerExpires) {
timeout = new Date(gameData.dateTimerExpires).getTime() - Date.now();
}

const input = await swal({
title: str,
type: 'warning',
showCancelButton: true,
reverseButtons: true,
confirmButtonText: button === 'yes' ? 'Approve' : 'Reject',
confirmButtonColor: button === 'yes' ? '#5cb85c' : '#d9534f',
timer: timeout
});

return Boolean(input.value);
}
Loading