Skip to content

Commit 12ce124

Browse files
committed
Fix Player order with final Vote
1 parent 00e35fd commit 12ce124

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

app.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ app.use(function(req, res, next){
1818
if (typeof(game) == 'undefined') {
1919
game = {
2020
players: [
21-
{name: 'Manu', role: '', vote1: null, vote2: null, nbVote2: 0, isGhost: false, permission: 'admin'},
2221
{name: 'Hélène', role: '', vote1: null, vote2: null, nbVote2: 0, isGhost: false, permission: null},
22+
{name: 'Manu', role: '', vote1: null, vote2: null, nbVote2: 0, isGhost: false, permission: 'admin'},
2323
],
2424
online: 0,
2525
settings: { traitorOptional: true },
@@ -117,11 +117,21 @@ function randomRoles(players) {
117117

118118
setRole(traitorRole);
119119

120-
players.sort((a,b) => a.isGhost ? 1 : -1 );
120+
players.sort(comparePlayer);
121121

122122
return players;
123123
}
124124

125+
function comparePlayer(a, b) {
126+
if (a.isGhost) {
127+
return 1;
128+
} else if (a > b) {
129+
return 0;
130+
};
131+
132+
return -1;
133+
}
134+
125135
function setRole(role) {
126136
game.players.some(function(player) {
127137
if(player.role === defaultRole) {

0 commit comments

Comments
 (0)