Skip to content

Commit

Permalink
Update logic.js
Browse files Browse the repository at this point in the history
Fix #354
  • Loading branch information
mclemente committed Jan 28, 2024
1 parent 8d8792a commit f7fe9f1
Showing 1 changed file with 39 additions and 30 deletions.
69 changes: 39 additions & 30 deletions src/module/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,40 +239,49 @@ export class Polyglot {
continue;
}
const label = this.languageProvider.languages[lang]?.label || lang.capitalize();
if (game.user.isGM && ownedActors.length) {
const usersThatKnowLang = filteredUsers.filter((u) =>
ownedActors.some((actor) => actor.knownLanguages.has(lang) && actor.testUserPermission(u, "OWNER")),
);
const usersWithOwnedActors = usersThatKnowLang.map((u) => {
const actorsOwnedByUser = ownedActors
.filter((actor) => actor.knownLanguages.has(lang) && actor.testUserPermission(u, "OWNER"))
.map((a) => a.name);
return { ...u, actorsOwnedByUser };
});
if (usersWithOwnedActors.length) {
let users = [];
for (let user of usersWithOwnedActors) {
const { name, color, actorsOwnedByUser } = user;
users.push({ bgColor: color, userName: name, ownedActors: actorsOwnedByUser.join(", ") });
}
options[0].children.push({
id: lang,
text: label,
users,
if (game.user.isGM) {
if (ownedActors.length) {
const usersThatKnowLang = filteredUsers.filter((u) =>
ownedActors.some((actor) => actor.knownLanguages.has(lang) && actor.testUserPermission(u, "OWNER")),
);
const usersWithOwnedActors = usersThatKnowLang.map((u) => {
const actorsOwnedByUser = ownedActors
.filter((actor) => actor.knownLanguages.has(lang) && actor.testUserPermission(u, "OWNER"))
.map((a) => a.name);
return { ...u, actorsOwnedByUser };
});
continue;
if (usersWithOwnedActors.length) {
let users = [];
for (let user of usersWithOwnedActors) {
const { name, color, actorsOwnedByUser } = user;
users.push({ bgColor: color, userName: name, ownedActors: actorsOwnedByUser.join(", ") });
}
options[0].children.push({
id: lang,
text: label,
users,
});
continue;
}
}
options[1].children.push({
id: lang,
text: label,
});
} else {
options.push({
id: lang,
text: label,
});
}
options[1].children.push({
id: lang,
text: label,
});
}
if (!options[1].children.length) {
options.pop();
}
if (!options[0].children.length) {
options.shift();
if (game.user.isGM) {
if (!options[1].children.length) {
options.pop();
}
if (!options[0].children.length) {
options.shift();
}
}

const select = html.find(".polyglot-lang-select select");
Expand Down

0 comments on commit f7fe9f1

Please sign in to comment.