reduce data sent to clients

This commit is contained in:
Zutatensuppe 2020-12-24 15:29:32 +01:00
parent cac1f02557
commit 1025d42ea2
4 changed files with 63 additions and 46 deletions

View file

@ -144,6 +144,36 @@ function decodePlayer(data) {
}
}
function encodeGame(data) {
if (Array.isArray(data)) {
return data
}
return [
data.id,
data.rng.type,
Rng.serialize(data.rng.obj),
data.puzzle,
data.players,
data.evtInfos,
]
}
function decodeGame(data) {
if (!Array.isArray(data)) {
return data
}
return {
id: data[0],
rng: {
type: data[1],
obj: Rng.unserialize(data[2]),
},
puzzle: data[3],
players: data[4],
evtInfos: data[5],
}
}
function coordByTileIdx(info, tileIdx) {
const wTiles = info.width / info.tileSize
return {
@ -181,5 +211,8 @@ export default {
encodePlayer,
decodePlayer,
encodeGame,
decodeGame,
coordByTileIdx,
}