Skip to content

Commit

Permalink
Merge pull request #21 from xdy-forks/hide-token-names
Browse files Browse the repository at this point in the history
Hides token name in flat check chat card if the pf2e setting 'Tokens …
  • Loading branch information
jessev14 committed Jan 22, 2023
2 parents 3194d71 + d0a4df8 commit 3af3d7c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions scripts/main.js
Expand Up @@ -52,12 +52,14 @@ Hooks.on('createChatMessage', async (message, data, userID) => {
templateData.targets = [];
const targets = Array.from(game.users.get(userID).targets);
let anyTargetUndetected = false;
let targetCount = 1;
for (const target of targets) {
const { conditionName, DC } = getCondition(token, target, item.type === 'spell');
if (!conditionName) continue;

const visibility = game.settings.get("pf2e", "metagame_tokenSetsNameVisibility");
templateData.targets.push({
name: target.name,
name: visibility && [0, 20, 40].includes(target.document.displayName) ? "Target " + targetCount++ : target.name,
condition: conditionName
});

Expand Down Expand Up @@ -87,7 +89,7 @@ Hooks.on('createChatMessage', async (message, data, userID) => {
speaker: ChatMessage.getSpeaker({ token, actor, user: game.users.get(userID) }),
whisper: anyTargetUndetected ? ChatMessage.getWhisperRecipients("GM").map((u) => u.id) : null,
blind: anyTargetUndetected,
flags: {"pf2-flat-check": true}
flags: { "pf2-flat-check": true }
});
});

Expand Down Expand Up @@ -186,5 +188,8 @@ function getCondition(token, target, isSpell) {
if (condition === 'hidden') DC = 5;
}

return { conditionName: condition && condition.length > 0 ? condition.charAt(0).toUpperCase() + condition.slice(1) : condition, DC };
return {
conditionName: condition && condition.length > 0 ? condition.charAt(0).toUpperCase() + condition.slice(1) : condition,
DC
};
}

0 comments on commit 3af3d7c

Please sign in to comment.