2020-06-16 08:58:36 +00:00
|
|
|
// helper functions
|
|
|
|
const set = key => (state, val) => {
|
|
|
|
state[key] = val;
|
|
|
|
};
|
|
|
|
|
2020-09-16 09:39:36 +00:00
|
|
|
/**
|
|
|
|
* Handle a vote request.
|
|
|
|
* If the vote is from a seat that is already locked, ignore it.
|
|
|
|
* @param state session state
|
|
|
|
* @param index seat of the player in the circle
|
|
|
|
* @param vote true or false
|
|
|
|
* @param indexAdjusted seat of the player counted from the nominated player
|
|
|
|
*/
|
2020-06-16 08:58:36 +00:00
|
|
|
const handleVote = (state, [index, vote]) => {
|
|
|
|
if (!state.nomination) return;
|
|
|
|
state.votes = [...state.votes];
|
|
|
|
state.votes[index] = vote === undefined ? !state.votes[index] : vote;
|
|
|
|
};
|
|
|
|
|
2020-05-30 20:47:42 +00:00
|
|
|
const state = () => ({
|
|
|
|
sessionId: "",
|
|
|
|
isSpectator: false,
|
2020-09-21 09:19:46 +00:00
|
|
|
isReconnecting: false,
|
2020-05-30 20:47:42 +00:00
|
|
|
playerCount: 0,
|
2020-09-16 09:39:36 +00:00
|
|
|
ping: 0,
|
2020-05-30 20:47:42 +00:00
|
|
|
playerId: "",
|
2020-05-31 21:42:08 +00:00
|
|
|
claimedSeat: -1,
|
2020-06-03 20:25:23 +00:00
|
|
|
nomination: false,
|
|
|
|
votes: [],
|
2020-06-18 08:00:32 +00:00
|
|
|
lockedVote: 0,
|
2020-12-03 20:09:06 +00:00
|
|
|
votingSpeed: 3000
|
2020-05-30 20:47:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const getters = {};
|
|
|
|
|
|
|
|
const actions = {};
|
|
|
|
|
|
|
|
const mutations = {
|
2020-06-16 08:58:36 +00:00
|
|
|
setSessionId: set("sessionId"),
|
|
|
|
setPlayerId: set("playerId"),
|
|
|
|
setSpectator: set("isSpectator"),
|
2020-09-21 09:19:46 +00:00
|
|
|
setReconnecting: set("isReconnecting"),
|
2020-06-16 08:58:36 +00:00
|
|
|
setPlayerCount: set("playerCount"),
|
2020-09-16 09:39:36 +00:00
|
|
|
setPing: set("ping"),
|
2020-06-18 08:00:32 +00:00
|
|
|
setVotingSpeed: set("votingSpeed"),
|
2020-06-16 08:58:36 +00:00
|
|
|
claimSeat: set("claimedSeat"),
|
2020-07-23 08:39:48 +00:00
|
|
|
nomination(state, { nomination, votes, votingSpeed, lockedVote } = {}) {
|
2020-06-30 08:16:56 +00:00
|
|
|
state.nomination = nomination || false;
|
|
|
|
state.votes = votes || [];
|
|
|
|
state.votingSpeed = votingSpeed || state.votingSpeed;
|
2020-07-23 08:39:48 +00:00
|
|
|
state.lockedVote = lockedVote || 0;
|
2020-06-03 20:25:23 +00:00
|
|
|
},
|
2020-06-16 08:58:36 +00:00
|
|
|
/**
|
|
|
|
* Store a vote with and without syncing it to the live session.
|
|
|
|
* This is necessary in order to prevent infinite voting loops.
|
|
|
|
* @param state
|
|
|
|
* @param vote
|
|
|
|
*/
|
|
|
|
vote: handleVote,
|
|
|
|
voteSync: handleVote,
|
2020-06-03 21:04:50 +00:00
|
|
|
lockVote(state, lock) {
|
|
|
|
state.lockedVote = lock !== undefined ? lock : state.lockedVote + 1;
|
2020-05-30 20:47:42 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
namespaced: true,
|
|
|
|
state,
|
|
|
|
getters,
|
|
|
|
actions,
|
|
|
|
mutations
|
|
|
|
};
|