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,6 +222,9 @@ class LiveSession {
|
||||||
? { roleId: player.role.id }
|
? { roleId: player.role.id }
|
||||||
: {})
|
: {})
|
||||||
}));
|
}));
|
||||||
|
if (isLightweight) {
|
||||||
|
this._send("gs", { gamestate: this._gamestate, isLightweight });
|
||||||
|
} else {
|
||||||
const { session, grimoire } = this._store.state;
|
const { session, grimoire } = this._store.state;
|
||||||
const { fabled } = this._store.state.players;
|
const { fabled } = this._store.state.players;
|
||||||
this.sendEdition();
|
this.sendEdition();
|
||||||
|
@ -234,6 +239,7 @@ class LiveSession {
|
||||||
...(session.nomination ? { votes: session.votes } : {})
|
...(session.nomination ? { votes: session.votes } : {})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the gamestate based on incoming data.
|
* Update the gamestate based on incoming data.
|
||||||
|
@ -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