also assign effects to unlinked Tokens and fix calculation
Sonarqube Scanner / Build and analyze (push) Successful in 48s

This commit is contained in:
ChatGPT
2026-06-05 00:13:33 +02:00
parent dd1b08ee21
commit eb43af49b2
5 changed files with 111 additions and 29 deletions
+12 -3
View File
@@ -1,18 +1,27 @@
export function getBestTokenDocumentForActor(actor) {
if (!actor) return null;
const syntheticToken = getSyntheticTokenDocument(actor);
if (syntheticToken) return syntheticToken;
const controlled = canvas?.tokens?.controlled?.find(token => token.actor?.uuid === actor.uuid || token.actor?.id === actor.id);
if (controlled) return controlled.document;
const activeTokens = actor.getActiveTokens?.(true, true) ?? [];
if (activeTokens.length === 1) return activeTokens[0].document;
const combatant = game.combat?.combatants?.find(c => c.actor?.uuid === actor.uuid || c.actor?.id === actor.id);
if (combatant?.token) return combatant.token;
const activeTokens = actor.getActiveTokens?.(true, true) ?? [];
if (activeTokens.length === 1) return activeTokens[0].document;
return activeTokens[0]?.document ?? null;
}
function getSyntheticTokenDocument(actor) {
const tokenDocument = actor.token ?? actor.prototypeToken ?? null;
if (tokenDocument?.documentName === "Token") return tokenDocument;
return null;
}
export function getPrimaryOwner(actor) {
if (!actor) return null;
return game.users.find(user => user.active && !user.isGM && actor.testUserPermission(user, "OWNER")) ?? null;