reduce data sent to clients
This commit is contained in:
parent
cac1f02557
commit
1025d42ea2
4 changed files with 63 additions and 46 deletions
|
|
@ -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,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue