Update players.js

This commit is contained in:
MRegnard 2023-07-31 12:09:17 +02:00 committed by GitHub
parent b94e279101
commit 3e7ec64c24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -28,33 +28,33 @@ const getters = {
nightOrder({ players, fabled }) { nightOrder({ players, fabled }) {
const firstNight = [0]; const firstNight = [0];
const otherNight = [0]; const otherNight = [0];
players.forEach(({ role }) => {
if (role.firstNight && !firstNight.includes(role.firstNight)) {
firstNight.push(role.firstNight);
}
if (role.otherNight && !otherNight.includes(role.otherNight)) {
otherNight.push(role.otherNight);
}
});
fabled.forEach(role => { fabled.forEach(role => {
if (role.firstNight && !firstNight.includes(role.firstNight)) { if (role.firstNight && !firstNight.includes(role.firstNight)) {
firstNight.push(role.firstNight); firstNight.push(role);
} }
if (role.otherNight && !otherNight.includes(role.otherNight)) { if (role.otherNight && !otherNight.includes(role.otherNight)) {
otherNight.push(role.otherNight); otherNight.push(role);
} }
}); });
firstNight.sort((a, b) => a - b); players.forEach(({ role }) => {
otherNight.sort((a, b) => a - b); if (role.firstNight && !firstNight.includes(role.firstNight)) {
firstNight.push(role);
}
if (role.otherNight && !otherNight.includes(role.otherNight)) {
otherNight.push(role);
}
});
firstNight.sort((a, b) => a.firstNight - b.firstNight);
otherNight.sort((a, b) => a.otherNight - b.otherNight);
const nightOrder = new Map(); const nightOrder = new Map();
players.forEach(player => { players.forEach(player => {
const first = Math.max(firstNight.indexOf(player.role.firstNight), 0); const first = Math.max(firstNight.indexOf(player.role), 0);
const other = Math.max(otherNight.indexOf(player.role.otherNight), 0); const other = Math.max(otherNight.indexOf(player.role), 0);
nightOrder.set(player, { first, other }); nightOrder.set(player, { first, other });
}); });
fabled.forEach(role => { fabled.forEach(role => {
const first = Math.max(firstNight.indexOf(role.firstNight), 0); const first = Math.max(firstNight.indexOf(role), 0);
const other = Math.max(otherNight.indexOf(role.otherNight), 0); const other = Math.max(otherNight.indexOf(role), 0);
nightOrder.set(role, { first, other }); nightOrder.set(role, { first, other });
}); });
return nightOrder; return nightOrder;