mirror of https://github.com/bra1n/townsquare.git
only sync player data when changing player related things
This commit is contained in:
parent
15ced66b42
commit
faf378dca3
|
@ -208,8 +208,10 @@ class LiveSession {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Publish the current gamestate.
|
* Publish the current gamestate.
|
||||||
|
* Optional param to reduce traffic. (send only player data)
|
||||||
|
* @param isLightweight
|
||||||
*/
|
*/
|
||||||
sendGamestate() {
|
sendGamestate(isLightweight = false) {
|
||||||
if (this._isSpectator) return;
|
if (this._isSpectator) return;
|
||||||
this._gamestate = this._store.state.players.players.map(player => ({
|
this._gamestate = this._store.state.players.players.map(player => ({
|
||||||
name: player.name,
|
name: player.name,
|
||||||
|
@ -220,19 +222,23 @@ class LiveSession {
|
||||||
? { roleId: player.role.id }
|
? { roleId: player.role.id }
|
||||||
: {})
|
: {})
|
||||||
}));
|
}));
|
||||||
const { session, grimoire } = this._store.state;
|
if (isLightweight) {
|
||||||
const { fabled } = this._store.state.players;
|
this._send("gs", { gamestate: this._gamestate, isLightweight });
|
||||||
this.sendEdition();
|
} else {
|
||||||
this._send("gs", {
|
const { session, grimoire } = this._store.state;
|
||||||
gamestate: this._gamestate,
|
const { fabled } = this._store.state.players;
|
||||||
isNight: grimoire.isNight,
|
this.sendEdition();
|
||||||
nomination: session.nomination,
|
this._send("gs", {
|
||||||
votingSpeed: session.votingSpeed,
|
gamestate: this._gamestate,
|
||||||
lockedVote: session.lockedVote,
|
isNight: grimoire.isNight,
|
||||||
isVoteInProgress: session.isVoteInProgress,
|
nomination: session.nomination,
|
||||||
fabled: fabled.map(({ id }) => id),
|
votingSpeed: session.votingSpeed,
|
||||||
...(session.nomination ? { votes: session.votes } : {})
|
lockedVote: session.lockedVote,
|
||||||
});
|
isVoteInProgress: session.isVoteInProgress,
|
||||||
|
fabled: fabled.map(({ id }) => id),
|
||||||
|
...(session.nomination ? { votes: session.votes } : {})
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -244,6 +250,7 @@ class LiveSession {
|
||||||
if (!this._isSpectator) return;
|
if (!this._isSpectator) return;
|
||||||
const {
|
const {
|
||||||
gamestate,
|
gamestate,
|
||||||
|
isLightweight,
|
||||||
isNight,
|
isNight,
|
||||||
nomination,
|
nomination,
|
||||||
votingSpeed,
|
votingSpeed,
|
||||||
|
@ -252,17 +259,6 @@ class LiveSession {
|
||||||
isVoteInProgress,
|
isVoteInProgress,
|
||||||
fabled
|
fabled
|
||||||
} = data;
|
} = 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;
|
const players = this._store.state.players.players;
|
||||||
// adjust number of players
|
// adjust number of players
|
||||||
if (players.length < gamestate.length) {
|
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/clear":
|
||||||
case "players/remove":
|
case "players/remove":
|
||||||
case "players/add":
|
case "players/add":
|
||||||
session.sendGamestate();
|
session.sendGamestate(true);
|
||||||
break;
|
break;
|
||||||
case "players/update":
|
case "players/update":
|
||||||
session.sendPlayer(payload);
|
session.sendPlayer(payload);
|
||||||
|
|
Loading…
Reference in New Issue