This commit is contained in:
@@ -4,24 +4,27 @@ export function getBestTokenDocumentForActor(actor) {
|
||||
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);
|
||||
const controlled = canvas?.tokens?.controlled?.find(token => sameActor(token.actor, actor));
|
||||
if (controlled) return controlled.document;
|
||||
|
||||
const combatant = game.combat?.combatants?.find(c => c.actor?.uuid === actor.uuid || c.actor?.id === actor.id);
|
||||
const combatant = game.combat?.combatants?.find(candidate => sameActor(candidate.actor, actor));
|
||||
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;
|
||||
const tokenDocument = actor.token ?? null;
|
||||
if (tokenDocument?.documentName === "Token") return tokenDocument;
|
||||
return null;
|
||||
}
|
||||
|
||||
function sameActor(candidate, actor) {
|
||||
return candidate?.uuid === actor.uuid || candidate?.id === actor.id;
|
||||
}
|
||||
|
||||
export function getPrimaryOwner(actor) {
|
||||
if (!actor) return null;
|
||||
return game.users.find(user => user.active && !user.isGM && actor.testUserPermission(user, "OWNER")) ?? null;
|
||||
|
||||
Reference in New Issue
Block a user