mirror of
https://github.com/AlecM33/Werewolf.git
synced 2025-12-29 09:17:51 +01:00
restart functionality
This commit is contained in:
@@ -75,7 +75,7 @@ function processGameState (
|
||||
gameTimerManager,
|
||||
timerWorker,
|
||||
refreshPrompt = true,
|
||||
animateContainer= false
|
||||
animateContainer = false
|
||||
) {
|
||||
const containerAnimation = document.getElementById('game-state-container').animate(
|
||||
[
|
||||
@@ -123,10 +123,12 @@ function processGameState (
|
||||
gameStateRenderer.renderPlayerView(true);
|
||||
break;
|
||||
case globals.USER_TYPES.MODERATOR:
|
||||
document.getElementById('transfer-mod-prompt').innerHTML = HTMLFragments.TRANSFER_MOD_MODAL;
|
||||
document.getElementById('game-state-container').innerHTML = HTMLFragments.MODERATOR_GAME_VIEW;
|
||||
gameStateRenderer.renderModeratorView();
|
||||
break;
|
||||
case globals.USER_TYPES.TEMPORARY_MODERATOR:
|
||||
document.getElementById('transfer-mod-prompt').innerHTML = HTMLFragments.TRANSFER_MOD_MODAL;
|
||||
document.getElementById('game-state-container').innerHTML = HTMLFragments.TEMP_MOD_GAME_VIEW;
|
||||
gameStateRenderer.renderTempModView();
|
||||
break;
|
||||
@@ -141,6 +143,7 @@ function processGameState (
|
||||
socket.emit(globals.COMMANDS.GET_TIME_REMAINING, currentGameState.accessCode);
|
||||
} else {
|
||||
document.querySelector('#game-timer')?.remove();
|
||||
document.querySelector('#timer-container-moderator')?.remove();
|
||||
document.querySelector('label[for="game-timer"]')?.remove();
|
||||
}
|
||||
break;
|
||||
@@ -384,7 +387,7 @@ function activateRoleInfoButton (deck) {
|
||||
});
|
||||
document.getElementById('role-info-button').addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
document.getElementById('prompt').innerHTML = HTMLFragments.ROLE_INFO_MODAL;
|
||||
document.getElementById('role-info-prompt').innerHTML = HTMLFragments.ROLE_INFO_MODAL;
|
||||
const modalContent = document.getElementById('game-role-info-container');
|
||||
for (const card of deck) {
|
||||
const roleDiv = document.createElement('div');
|
||||
|
||||
@@ -4,45 +4,50 @@ import { injectNavbar } from '../modules/Navbar.js';
|
||||
|
||||
const home = () => {
|
||||
injectNavbar();
|
||||
document.getElementById('join-form').onsubmit = (e) => {
|
||||
e.preventDefault();
|
||||
const userCode = document.getElementById('room-code').value;
|
||||
if (roomCodeIsValid(userCode)) {
|
||||
attemptToJoinGame(userCode);
|
||||
} else {
|
||||
toast('Invalid code. Codes are 4 numbers or letters.', 'error', true, true);
|
||||
}
|
||||
};
|
||||
document.getElementById('join-form').addEventListener('submit', attemptToJoinGame);
|
||||
};
|
||||
|
||||
function roomCodeIsValid (code) {
|
||||
return typeof code === 'string' && /^[A-Z0-9]{4}$/.test(code.toUpperCase().trim());
|
||||
}
|
||||
|
||||
function attemptToJoinGame (code) {
|
||||
XHRUtility.xhr(
|
||||
'/api/games/' + code.toUpperCase().trim() + '/availability',
|
||||
'GET',
|
||||
null,
|
||||
null
|
||||
)
|
||||
.then((res) => {
|
||||
if (res.status === 200) {
|
||||
const json = JSON.parse(res.content);
|
||||
window.location = window.location.protocol + '//' + window.location.host +
|
||||
'/join/' + encodeURIComponent(json.accessCode) +
|
||||
'?playerCount=' + encodeURIComponent(json.playerCount) +
|
||||
'&timer=' + encodeURIComponent(getTimeString(json.timerParams));
|
||||
}
|
||||
}).catch((res) => {
|
||||
if (res.status === 404) {
|
||||
toast('Game not found', 'error', true);
|
||||
} else if (res.status === 400) {
|
||||
toast(res.content, 'error', true);
|
||||
} else {
|
||||
toast('An unknown error occurred. Please try again later.', 'error', true);
|
||||
}
|
||||
});
|
||||
function attemptToJoinGame (event) {
|
||||
event.preventDefault();
|
||||
const userCode = document.getElementById('room-code').value;
|
||||
if (roomCodeIsValid(userCode)) {
|
||||
const form = document.getElementById('join-form');
|
||||
form.removeEventListener('submit', attemptToJoinGame);
|
||||
form.classList.add('submitted');
|
||||
document.getElementById('join-button')?.setAttribute('value', 'Joining...');
|
||||
XHRUtility.xhr(
|
||||
'/api/games/' + userCode.toUpperCase().trim() + '/availability',
|
||||
'GET',
|
||||
null,
|
||||
null
|
||||
)
|
||||
.then((res) => {
|
||||
if (res.status === 200) {
|
||||
const json = JSON.parse(res.content);
|
||||
window.location = window.location.protocol + '//' + window.location.host +
|
||||
'/join/' + encodeURIComponent(json.accessCode) +
|
||||
'?playerCount=' + encodeURIComponent(json.playerCount) +
|
||||
'&timer=' + encodeURIComponent(getTimeString(json.timerParams));
|
||||
}
|
||||
}).catch((res) => {
|
||||
form.addEventListener('submit', attemptToJoinGame);
|
||||
form.classList.remove('submitted');
|
||||
document.getElementById('join-button')?.setAttribute('value', 'Join');
|
||||
if (res.status === 404) {
|
||||
toast('Game not found', 'error', true);
|
||||
} else if (res.status === 400) {
|
||||
toast(res.content, 'error', true);
|
||||
} else {
|
||||
toast('An unknown error occurred. Please try again later.', 'error', true);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
toast('Invalid code. Codes are 4 numbers or letters.', 'error', true, true);
|
||||
}
|
||||
}
|
||||
|
||||
function getTimeString (timerParams) {
|
||||
|
||||
Reference in New Issue
Block a user