diff --git a/CHANGELOG.md b/CHANGELOG.md index 6333526..97a5ea0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Upcoming version +- Unique night order bubble for each player with the same role - Adding some special votes - Automatic Djinn and Bootlegger - Updating night order diff --git a/src/store/modules/players.js b/src/store/modules/players.js index 1d84613..236b2b2 100644 --- a/src/store/modules/players.js +++ b/src/store/modules/players.js @@ -29,27 +29,37 @@ const getters = { const firstNight = [0]; const otherNight = [0]; fabled.forEach((role) => { - if (role.firstNight && !firstNight.includes(role)) { + if (role.firstNight) { firstNight.push(role); } - if (role.otherNight && !otherNight.includes(role)) { + if (role.otherNight) { otherNight.push(role); } }); - players.forEach(({ role }) => { - if (role.firstNight && !firstNight.includes(role)) { - firstNight.push(role); + players.forEach((player) => { + if (player.role.firstNight) { + firstNight.push(player); } - if (role.otherNight && !otherNight.includes(role)) { - otherNight.push(role); + if (player.role.otherNight) { + otherNight.push(player); } }); - firstNight.sort((a, b) => a.firstNight - b.firstNight); - otherNight.sort((a, b) => a.otherNight - b.otherNight); + // If x has an attribute 'role' (meaning x is a player), then, to know their night order, we look at x.role.firstNight or x.role.otherNight + // Else, (meaning x is instead a Fabled), to know their night order we look at x.firstNight or x.otherNight + firstNight.sort( + (a, b) => + (a.role ? a.role.firstNight : a.firstNight) - + (b.role ? b.role.firstNight : b.firstNight), + ); + otherNight.sort( + (a, b) => + (a.role ? a.role.otherNight : a.otherNight) - + (b.role ? b.role.otherNight : b.otherNight), + ); const nightOrder = new Map(); players.forEach((player) => { - const first = Math.max(firstNight.indexOf(player.role), 0); - const other = Math.max(otherNight.indexOf(player.role), 0); + const first = Math.max(firstNight.indexOf(player), 0); + const other = Math.max(otherNight.indexOf(player), 0); nightOrder.set(player, { first, other }); }); fabled.forEach((role) => {