only sync player data when changing player related things

This commit is contained in:
Steffen 2020-12-07 21:41:56 +01:00
parent 15ced66b42
commit faf378dca3
1 changed files with 35 additions and 26 deletions

View File

@ -208,8 +208,10 @@ class LiveSession {
/**
* Publish the current gamestate.
* Optional param to reduce traffic. (send only player data)
* @param isLightweight
*/
sendGamestate() {
sendGamestate(isLightweight = false) {
if (this._isSpectator) return;
this._gamestate = this._store.state.players.players.map(player => ({
name: player.name,
@ -220,6 +222,9 @@ class LiveSession {
? { roleId: player.role.id }
: {})
}));
if (isLightweight) {
this._send("gs", { gamestate: this._gamestate, isLightweight });
} else {
const { session, grimoire } = this._store.state;
const { fabled } = this._store.state.players;
this.sendEdition();
@ -234,6 +239,7 @@ class LiveSession {
...(session.nomination ? { votes: session.votes } : {})
});
}
}
/**
* Update the gamestate based on incoming data.
@ -244,6 +250,7 @@ class LiveSession {
if (!this._isSpectator) return;
const {
gamestate,
isLightweight,
isNight,
nomination,
votingSpeed,
@ -252,17 +259,6 @@ class LiveSession {
isVoteInProgress,
fabled
} = data;
this._store.commit("toggleNight", !!isNight);
this._store.commit("session/nomination", {
nomination,
votes,
votingSpeed,
lockedVote,
isVoteInProgress
});
this._store.commit("players/setFabled", {
fabled: fabled.map(id => this._store.state.fabled.get(id))
});
const players = this._store.state.players.players;
// adjust number of players
if (players.length < gamestate.length) {
@ -301,6 +297,19 @@ class LiveSession {
});
}
});
if (!isLightweight) {
this._store.commit("toggleNight", !!isNight);
this._store.commit("session/nomination", {
nomination,
votes,
votingSpeed,
lockedVote,
isVoteInProgress
});
this._store.commit("players/setFabled", {
fabled: fabled.map(id => this._store.state.fabled.get(id))
});
}
}
/**
@ -702,7 +711,7 @@ export default store => {
case "players/clear":
case "players/remove":
case "players/add":
session.sendGamestate();
session.sendGamestate(true);
break;
case "players/update":
session.sendPlayer(payload);