enable replays

This commit is contained in:
Zutatensuppe 2021-05-29 11:44:55 +02:00
parent eabe338971
commit 7a7d6580fc
7 changed files with 129 additions and 36 deletions

View file

@ -170,8 +170,11 @@ function getPlayerIdByIndex(gameId: string, playerIndex: number): string|null {
return null
}
function getPlayer(gameId: string, playerId: string): Player {
function getPlayer(gameId: string, playerId: string): Player|null {
const idx = getPlayerIndexById(gameId, playerId)
if (idx === -1) {
return null
}
return Util.decodePlayer(GAMES[gameId].players[idx])
}
@ -299,6 +302,10 @@ function changePlayer(
change: any
): void {
const player = getPlayer(gameId, playerId)
if (player === null) {
return
}
for (let k of Object.keys(change)) {
// @ts-ignore
player[k] = change[k]
@ -647,9 +654,13 @@ function handleInput(
}
const _playerChange = (): void => {
const player = getPlayer(gameId, playerId)
if (!player) {
return
}
changes.push([
Protocol.CHANGE_PLAYER,
Util.encodePlayer(getPlayer(gameId, playerId)),
Util.encodePlayer(player),
])
}

View file

@ -40,10 +40,10 @@ EV_SERVER_INIT: event sent to one client after that client
*/
const EV_SERVER_EVENT = 1
const EV_SERVER_INIT = 4
const EV_SERVER_INIT_REPLAY = 5
const EV_SERVER_REPLAY_DATA = 5
const EV_CLIENT_EVENT = 2
const EV_CLIENT_INIT = 3
const EV_CLIENT_INIT_REPLAY = 6
const EV_CLIENT_REPLAY_DATA = 6
const LOG_HEADER = 1
const LOG_ADD_PLAYER = 2
@ -68,10 +68,10 @@ const CHANGE_PLAYER = 3
export default {
EV_SERVER_EVENT,
EV_SERVER_INIT,
EV_SERVER_INIT_REPLAY,
EV_SERVER_REPLAY_DATA,
EV_CLIENT_EVENT,
EV_CLIENT_INIT,
EV_CLIENT_INIT_REPLAY,
EV_CLIENT_REPLAY_DATA,
LOG_HEADER,
LOG_ADD_PLAYER,