diff --git a/ChangeLog.md b/ChangeLog.md index 4f0e3dc..68afb7f 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,6 @@ +# v1.16.0 +* Add a keybinding to make selected tokens observerable by removing `hidden`, `undetected`, or `unnoticed` condition items. Will also clear out any `PF2E Perception` flags on those tokens. + # v1.15.1 * Mark module as not yet compatible with v13 diff --git a/esmodules/main.js b/esmodules/main.js index a2ff3c1..a94dad1 100644 --- a/esmodules/main.js +++ b/esmodules/main.js @@ -34,6 +34,18 @@ function getPerceptiveApi() { export { MODULE_ID, PF2E_PERCEPTION_ID, PERCEPTIVE_ID, log, getPerceptionApi, getPerceptiveApi }; +async function clearPerceptionData(token) { + // Remove any ids that perception is tracking + const perceptionData = token.flags?.[PF2E_PERCEPTION_ID]?.data; + if (!perceptionData || !Object.keys(perceptionData).length) return; + let tokenUpdate = {}; + for (let id in perceptionData) { + tokenUpdate[`flags.${PF2E_PERCEPTION_ID}.data.-=${id}`] = true; + } + const updates = [{ _id: token.id, ...tokenUpdate }]; + await canvas.scene.updateEmbeddedDocuments("Token", updates); +} + Hooks.once('init', () => { Hooks.on('createChatMessage', async (message, options, id) => { if (game.userId != id) return; @@ -50,6 +62,28 @@ Hooks.once('init', () => { // Roll the damage! origin?.rollDamage({ target: message.token }); }); + + game.keybindings.register(MODULE_ID, "observable", { + name: `${MODULE_ID}.observable.name`, + hint: `${MODULE_ID}.observable.hint`, + editable: [ + { key: "B" } + ], + onDown: async () => { + const conditionHandler = game.settings.get(MODULE_ID, 'conditionHandler'); + const perceptionApi = (conditionHandler === 'perception') ? getPerceptionApi() : null; + const selectedTokens = canvas.tokens.controlled; + for (const token of selectedTokens) { + if (perceptionApi) await clearPerceptionData(token.document); + const conditions = token.actor.items + .filter((i) => ['hidden', 'undetected', 'unnoticed'].includes(i.system.slug)) + .map((i) => i.id); + if (conditions.length > 0) { + await token.actor.deleteEmbeddedDocuments("Item", conditions); + } + } + } + }); }); function migrate(moduleVersion, oldVersion) { @@ -80,16 +114,7 @@ Hooks.once('ready', () => { // Get the token on the current scene const token = options.parent?.parent ?? canvas.scene.tokens.find((t) => t.actorId === options.parent.id); if (!token) return; - - // Remove any ids that perception is tracking - const perceptionData = token.flags?.[PF2E_PERCEPTION_ID]?.data; - if (!perceptionData || !Object.keys(perceptionData).length) return; - let tokenUpdate = {}; - for (let id in perceptionData) { - tokenUpdate[`flags.${PF2E_PERCEPTION_ID}.data.-=${id}`] = true; - } - const updates = [{ _id: token.id, ...tokenUpdate }]; - await canvas.scene.updateEmbeddedDocuments("Token", updates); + await clearPerceptionData(token); } if (game.modules.get(PF2E_PERCEPTION_ID)?.active) { diff --git a/languages/en.json b/languages/en.json index 2ebc0fb..25e8022 100644 --- a/languages/en.json +++ b/languages/en.json @@ -47,6 +47,10 @@ "name": "Compute Cover at Combat Start", "hint": "Use 'PF2e Perception' to automatically compute cover between tokens using stealth for initiative and non-allied Tokens. It is only used for this check, and will not utilize greater cover" }, + "observable": { + "name": "Make selected tokens observable", + "hint": "Remove hidden, undetected, and unnoticed statuses from selected tokens." + }, "schema": { "name": "Schema Version", "hint": "Set this to a previous version to force a data migration from the specified version to the current version" diff --git a/languages/pl.json b/languages/pl.json index 3b7a5f3..3af8e44 100644 --- a/languages/pl.json +++ b/languages/pl.json @@ -47,6 +47,10 @@ "name": "Oblicz osłony na początku walki", "hint": "Użyj „PF2e Perception”, aby automatycznie obliczyć osłonę między tokenami używającymi Ukrycia dla inicjatywy i niesprzymierzonych tokenów. Jest on używany tylko do tego sprawdzenia i nie będzie wykorzystywał większej osłony" }, + "observable": { + "name": "Make selected tokens observable", + "hint": "Remove hidden, undetected, and unnoticed statuses from selected tokens." + }, "schema": { "name": "Wersja schematu", "hint": "Ustaw to na poprzednią wersję, aby wymusić migrację danych z określonej wersji do wersji bieżącej."