mirror of
https://github.com/AlecM33/Werewolf.git
synced 2026-01-01 08:49:44 +01:00
first draft restarting of games
This commit is contained in:
@@ -2,6 +2,8 @@ import { globals } from '../config/globals.js';
|
||||
import { toast } from './Toast.js';
|
||||
import { HTMLFragments } from './HTMLFragments.js';
|
||||
import { ModalManager } from './ModalManager.js';
|
||||
import {XHRUtility} from "./XHRUtility";
|
||||
import {UserUtility} from "./UserUtility";
|
||||
|
||||
export class GameStateRenderer {
|
||||
constructor (stateBucket, socket) {
|
||||
@@ -256,7 +258,33 @@ export class GameStateRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
renderEndOfGame () {
|
||||
renderEndOfGame (gameState) {
|
||||
if (
|
||||
gameState.client.userType === globals.USER_TYPES.MODERATOR
|
||||
|| gameState.client.userType === globals.USER_TYPES.TEMPORARY_MODERATOR
|
||||
) {
|
||||
let div = document.createElement('div');
|
||||
div.innerHTML = HTMLFragments.RESTART_GAME_BUTTON;
|
||||
div.querySelector('#restart-game').addEventListener('click', () => {
|
||||
XHRUtility.xhr(
|
||||
'/api/games/' + gameState.accessCode + '/restart',
|
||||
'PATCH',
|
||||
null,
|
||||
JSON.stringify({
|
||||
playerName: gameState.client.name,
|
||||
accessCode: gameState.accessCode,
|
||||
sessionCookie: UserUtility.validateAnonUserSignature(globals.ENVIRONMENT.LOCAL),
|
||||
localCookie: UserUtility.validateAnonUserSignature(globals.ENVIRONMENT.PRODUCTION)
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
|
||||
}).catch((res) => {
|
||||
|
||||
});
|
||||
})
|
||||
document.getElementById('end-of-game-buttons').appendChild(div);
|
||||
}
|
||||
this.renderPlayersWithNoRoleInformationUnlessRevealed();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,6 +135,7 @@ export class GameTimerManager {
|
||||
const playBtn = document.createElement('img');
|
||||
playBtn.setAttribute('src', '../images/play-button.svg');
|
||||
playBtn.addEventListener('click', this.playListener);
|
||||
document.querySelector('#play-pause-placeholder')?.remove();
|
||||
document.getElementById('play-pause').appendChild(playBtn);
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,9 @@ export const HTMLFragments = {
|
||||
<label for='game-timer'>Time Remaining</label>
|
||||
<div id='game-timer'></div>
|
||||
</div>
|
||||
<div id='play-pause'> </div>
|
||||
<div id='play-pause'>
|
||||
<div id="play-pause-placeholder"></div>
|
||||
</div>
|
||||
</div>
|
||||
<button id='mod-transfer-button' class='moderator-player-button make-mod-button'>Transfer Mod Powers \uD83D\uDD00</button>
|
||||
<div>
|
||||
@@ -216,21 +218,27 @@ export const HTMLFragments = {
|
||||
</div>
|
||||
</div>`,
|
||||
END_OF_GAME_VIEW:
|
||||
`<h2>The moderator has ended the game. Roles are revealed.</h2>
|
||||
<div id='end-of-game-header'>
|
||||
<div>
|
||||
<button id='role-info-button' class='app-button'>View Role Info <img src='/images/info.svg'/></button>
|
||||
</div>
|
||||
<div>
|
||||
<a href='/'>
|
||||
<button class='app-button'>Go Home \uD83C\uDFE0</button>
|
||||
</a>
|
||||
`<div id='end-of-game-header'>
|
||||
<h2>The moderator has ended the game. Roles are revealed.</h2>
|
||||
<div id="end-of-game-buttons">
|
||||
<div>
|
||||
<button id='role-info-button' class='app-button'>View Role Info <img src='/images/info.svg'/></button>
|
||||
</div>
|
||||
<div>
|
||||
<a href='/'>
|
||||
<button class='app-button'>Go Home \uD83C\uDFE0</button>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id='game-people-container'>
|
||||
<label id='players-alive-label'></label>
|
||||
<div id='game-player-list'></div>
|
||||
</div>`,
|
||||
RESTART_GAME_BUTTON:
|
||||
`<div>
|
||||
<button id='restart-game' class='app-button'>Run it back 🔄</button>
|
||||
</div>`,
|
||||
CREATE_GAME_DECK:
|
||||
`<div id='deck-container'>
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user