mirror of
https://github.com/AlecM33/Werewolf.git
synced 2026-01-01 16:59:29 +01:00
fix bug with restoring moderator when restarting game
This commit is contained in:
@@ -1,16 +1,20 @@
|
||||
import { toast } from './Toast.js';
|
||||
|
||||
export const Confirmation = (message, onYes) => {
|
||||
export const Confirmation = (message, onYes = null) => {
|
||||
document.querySelector('#confirmation')?.remove();
|
||||
document.querySelector('#confirmation-background')?.remove();
|
||||
|
||||
let confirmation = document.createElement('div');
|
||||
confirmation.setAttribute('id', 'confirmation');
|
||||
confirmation.innerHTML =
|
||||
`<div id="confirmation-message"></div>
|
||||
confirmation.innerHTML = onYes
|
||||
? `<div id="confirmation-message"></div>
|
||||
<div class="confirmation-buttons">
|
||||
<button id="confirmation-cancel-button" class="app-button cancel">Cancel</button>
|
||||
<button id="confirmation-yes-button" class="app-button">Yes</button>
|
||||
</div>`
|
||||
: `<div id="confirmation-message"></div>
|
||||
<div class="confirmation-buttons-centered">
|
||||
<button id="confirmation-yes-button" class="app-button">OK</button>
|
||||
</div>`;
|
||||
|
||||
confirmation.querySelector('#confirmation-message').innerText = message;
|
||||
@@ -54,8 +58,13 @@ export const Confirmation = (message, onYes) => {
|
||||
});
|
||||
};
|
||||
|
||||
confirmation.querySelector('#confirmation-cancel-button').addEventListener('click', cancelHandler);
|
||||
confirmation.querySelector('#confirmation-yes-button').addEventListener('click', confirmHandler);
|
||||
if (onYes) {
|
||||
confirmation.querySelector('#confirmation-cancel-button').addEventListener('click', cancelHandler);
|
||||
confirmation.querySelector('#confirmation-yes-button').addEventListener('click', confirmHandler);
|
||||
} else { // we are only displaying a message for them to acknowledge, so the yes button should dispel the confirmation
|
||||
confirmation.querySelector('#confirmation-yes-button').addEventListener('click', cancelHandler);
|
||||
}
|
||||
|
||||
background.addEventListener('click', cancelHandler);
|
||||
|
||||
document.body.appendChild(background);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { globals } from '../../config/globals.js';
|
||||
import { Confirmation } from '../front_end_components/Confirmation.js';
|
||||
|
||||
export class GameTimerManager {
|
||||
constructor (stateBucket, socket) {
|
||||
@@ -88,11 +89,18 @@ export class GameTimerManager {
|
||||
}
|
||||
|
||||
displayExpiredTime () {
|
||||
const currentBtn = document.querySelector('#play-pause img');
|
||||
const currentBtn = document.querySelector('#timer-container-moderator #play-pause img');
|
||||
if (currentBtn) {
|
||||
currentBtn.removeEventListener('click', this.pauseListener);
|
||||
currentBtn.removeEventListener('click', this.playListener);
|
||||
currentBtn.remove();
|
||||
currentBtn.classList.add('disabled');
|
||||
currentBtn.setAttribute('src', '/images/play-pause-placeholder.svg');
|
||||
} else {
|
||||
document.querySelector('#play-pause-placeholder')?.remove();
|
||||
const placeholderBtn = document.createElement('img');
|
||||
placeholderBtn.setAttribute('src', '../images/play-pause-placeholder.svg');
|
||||
placeholderBtn.classList.add('disabled');
|
||||
document.getElementById('play-pause').appendChild(placeholderBtn);
|
||||
}
|
||||
|
||||
const timer = document.getElementById('game-timer');
|
||||
@@ -123,6 +131,12 @@ export class GameTimerManager {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (!socket.hasListeners(globals.COMMANDS.END_TIMER)) {
|
||||
socket.on(globals.COMMANDS.END_TIMER, () => {
|
||||
Confirmation('The timer has expired!');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
swapToPlayButton () {
|
||||
|
||||
Reference in New Issue
Block a user