diff --git a/daggerheart.mjs b/daggerheart.mjs index 5a6d8193..6d5c8274 100644 --- a/daggerheart.mjs +++ b/daggerheart.mjs @@ -5,7 +5,7 @@ import * as documents from './module/documents/_module.mjs'; import RegisterHandlebarsHelpers from './module/helpers/handlebarsHelper.mjs'; import { DhDualityRollEnricher, DhTemplateEnricher } from './module/enrichers/_module.mjs'; import { getCommandTarget, rollCommandToJSON } from './module/helpers/utils.mjs'; -import { NarrativeCountdowns, registerCountdownApplicationHooks } from './module/applications/ui/countdowns.mjs'; +import { NarrativeCountdowns } from './module/applications/ui/countdowns.mjs'; import { DualityRollColor } from './module/data/settings/Appearance.mjs'; import { DHRoll, DualityRoll, D20Roll, DamageRoll, DualityDie } from './module/dice/_module.mjs'; import { renderDualityButton } from './module/enrichers/DualityRollEnricher.mjs'; @@ -160,7 +160,6 @@ Hooks.on('ready', () => { registerCountdownHooks(); socketRegistration.registerSocketHooks(); - registerCountdownApplicationHooks(); registerRollDiceHooks(); registerDHActorHooks(); }); diff --git a/module/applications/hud/tokenHUD.mjs b/module/applications/hud/tokenHUD.mjs index 9a58bab2..572b03f9 100644 --- a/module/applications/hud/tokenHUD.mjs +++ b/module/applications/hud/tokenHUD.mjs @@ -1,4 +1,4 @@ -export default class DHTokenHUD extends TokenHUD { +export default class DHTokenHUD extends foundry.applications.hud.TokenHUD { static DEFAULT_OPTIONS = { classes: ['daggerheart'] }; diff --git a/module/applications/sheets/actors/character.mjs b/module/applications/sheets/actors/character.mjs index eae7a223..a9b36b75 100644 --- a/module/applications/sheets/actors/character.mjs +++ b/module/applications/sheets/actors/character.mjs @@ -654,10 +654,7 @@ export default class CharacterSheet extends DHBaseActorSheet { } else if (item instanceof ActiveEffect) { item.toChat(this); } else { - const wasUsed = await item.use(event); - if (wasUsed && item.type === 'weapon') { - Hooks.callAll(CONFIG.DH.HOOKS.characterAttack, {}); - } + item.use(event); } } diff --git a/module/applications/ui/chatLog.mjs b/module/applications/ui/chatLog.mjs index f295d2a6..aa604dda 100644 --- a/module/applications/ui/chatLog.mjs +++ b/module/applications/ui/chatLog.mjs @@ -14,8 +14,6 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo } addChatListeners = async (app, html, data) => { - super.addChatListeners(app, html, data); - html.querySelectorAll('.duality-action-damage').forEach(element => element.addEventListener('click', event => this.onRollDamage(event, data.message)) ); diff --git a/module/applications/ui/combatTracker.mjs b/module/applications/ui/combatTracker.mjs index f9f49ad1..f9f8d5a3 100644 --- a/module/applications/ui/combatTracker.mjs +++ b/module/applications/ui/combatTracker.mjs @@ -73,7 +73,10 @@ export default class DhCombatTracker extends foundry.applications.sidebar.tabs.C .map(x => x.id) .indexOf(combatantId); - if (this.viewed.turn !== toggleTurn) Hooks.callAll(CONFIG.DH.HOOKS.spotlight, {}); + if (this.viewed.turn !== toggleTurn) { + const { updateCountdowns } = game.system.api.applications.ui.DhCountdowns; + await updateCountdowns(CONFIG.DH.GENERAL.countdownTypes.spotlight.id); + } await this.viewed.update({ turn: this.viewed.turn === toggleTurn ? null : toggleTurn }); await combatant.update({ 'system.spotlight.requesting': false }); diff --git a/module/applications/ui/countdowns.mjs b/module/applications/ui/countdowns.mjs index c229cda1..5e3ad1ab 100644 --- a/module/applications/ui/countdowns.mjs +++ b/module/applications/ui/countdowns.mjs @@ -1,4 +1,3 @@ -import { countdownTypes } from '../../config/generalConfig.mjs'; import { GMUpdateEvent, RefreshType, socketEvent } from '../../systemRegistration/socket.mjs'; import constructHTMLButton from '../../helpers/utils.mjs'; import OwnershipSelection from '../dialogs/ownershipSelection.mjs'; @@ -328,43 +327,29 @@ export class EncounterCountdowns extends Countdowns { }; } -export const registerCountdownApplicationHooks = () => { - const updateCountdowns = async shouldProgress => { - if (game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation).countdowns) { - const countdownSetting = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns); - for (let countdownCategoryKey in countdownSetting) { - const countdownCategory = countdownSetting[countdownCategoryKey]; - for (let countdownKey in countdownCategory.countdowns) { - const countdown = countdownCategory.countdowns[countdownKey]; - - if (shouldProgress(countdown)) { - await countdownSetting.updateSource({ - [`${countdownCategoryKey}.countdowns.${countdownKey}.progress.current`]: - countdown.progress.current - 1 - }); - await game.settings.set( - CONFIG.DH.id, - CONFIG.DH.SETTINGS.gameSettings.Countdowns, - countdownSetting - ); - foundry.applications.instances.get(`${countdownCategoryKey}-countdowns`)?.render(); - } +export async function updateCountdowns(progressType) { + const countdownSetting = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns); + const update = Object.keys(countdownSetting).reduce((update, typeKey) => { + return foundry.utils.mergeObject( + update, + Object.keys(countdownSetting[typeKey].countdowns).reduce((acc, countdownKey) => { + const countdown = countdownSetting[typeKey].countdowns[countdownKey]; + if (countdown.progress.current > 0 && countdown.progress.type.value === progressType) { + acc[`${typeKey}.countdowns.${countdownKey}.progress.current`] = countdown.progress.current - 1; } - } - } - }; - Hooks.on(CONFIG.DH.HOOKS.characterAttack, async () => { - updateCountdowns(countdown => { - return ( - countdown.progress.type.value === countdownTypes.characterAttack.id && countdown.progress.current > 0 - ); - }); - }); + return acc; + }, {}) + ); + }, {}); - Hooks.on(CONFIG.DH.HOOKS.spotlight, async () => { - updateCountdowns(countdown => { - return countdown.progress.type.value === countdownTypes.spotlight.id && countdown.progress.current > 0; - }); + await countdownSetting.updateSource(update); + await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns, countdownSetting); + + const data = { refreshType: RefreshType.Countdown }; + await game.socket.emit(`system.${CONFIG.DH.id}`, { + action: socketEvent.Refresh, + data }); -}; + Hooks.callAll(socketEvent.Refresh, data); +} diff --git a/module/config/_module.mjs b/module/config/_module.mjs index 88003595..99069dda 100644 --- a/module/config/_module.mjs +++ b/module/config/_module.mjs @@ -4,7 +4,6 @@ export * as domainConfig from './domainConfig.mjs'; export * as effectConfig from './effectConfig.mjs'; export * as flagsConfig from './flagsConfig.mjs'; export * as generalConfig from './generalConfig.mjs'; -export * as hooksConfig from './hooksConfig.mjs'; export * as itemConfig from './itemConfig.mjs'; export * as settingsConfig from './settingsConfig.mjs'; export * as systemConfig from './system.mjs'; diff --git a/module/config/generalConfig.mjs b/module/config/generalConfig.mjs index 4216f631..efbbbf73 100644 --- a/module/config/generalConfig.mjs +++ b/module/config/generalConfig.mjs @@ -376,15 +376,15 @@ export const abilityCosts = { export const countdownTypes = { spotlight: { id: 'spotlight', - label: 'DAGGERHEART.CONFIG.CountdownTypes.Spotlight' + label: 'DAGGERHEART.CONFIG.CountdownType.spotlight' }, characterAttack: { id: 'characterAttack', - label: 'DAGGERHEART.CONFIG.CountdownTypes.CharacterAttack' + label: 'DAGGERHEART.CONFIG.CountdownType.characterAttack' }, custom: { id: 'custom', - label: 'DAGGERHEART.CONFIG.CountdownTypes.Custom' + label: 'DAGGERHEART.CONFIG.CountdownType.custom' } }; export const rollTypes = { diff --git a/module/config/hooksConfig.mjs b/module/config/hooksConfig.mjs deleted file mode 100644 index 8410c0de..00000000 --- a/module/config/hooksConfig.mjs +++ /dev/null @@ -1,4 +0,0 @@ -export const hooks = { - characterAttack: 'characterAttackHook', - spotlight: 'spotlightHook' -}; diff --git a/module/config/system.mjs b/module/config/system.mjs index 6ad0e689..e72667b1 100644 --- a/module/config/system.mjs +++ b/module/config/system.mjs @@ -3,7 +3,6 @@ import * as DOMAIN from './domainConfig.mjs'; import * as ACTOR from './actorConfig.mjs'; import * as ITEM from './itemConfig.mjs'; import * as SETTINGS from './settingsConfig.mjs'; -import { hooks as HOOKS } from './hooksConfig.mjs'; import * as EFFECTS from './effectConfig.mjs'; import * as ACTIONS from './actionConfig.mjs'; import * as FLAGS from './flagsConfig.mjs'; @@ -17,7 +16,6 @@ export const SYSTEM = { ACTOR, ITEM, SETTINGS, - HOOKS, EFFECTS, ACTIONS, FLAGS diff --git a/module/data/action/attackAction.mjs b/module/data/action/attackAction.mjs index d953416a..e7ef84c6 100644 --- a/module/data/action/attackAction.mjs +++ b/module/data/action/attackAction.mjs @@ -37,4 +37,13 @@ export default class DHAttackAction extends DHDamageAction { base: true }; } + + async use(event, ...args) { + const result = await super.use(event, args); + + const { updateCountdowns } = game.system.api.applications.ui.DhCountdowns; + await updateCountdowns(CONFIG.DH.GENERAL.countdownTypes.characterAttack.id); + + return result; + } } diff --git a/module/data/countdowns.mjs b/module/data/countdowns.mjs index e9649f6e..881ecf20 100644 --- a/module/data/countdowns.mjs +++ b/module/data/countdowns.mjs @@ -102,7 +102,7 @@ class DhCountdown extends foundry.abstract.DataModel { value: new fields.StringField({ required: true, choices: CONFIG.DH.GENERAL.countdownTypes, - initial: CONFIG.DH.GENERAL.countdownTypes.spotlight.id, + initial: CONFIG.DH.GENERAL.countdownTypes.custom.id, label: 'DAGGERHEART.APPLICATIONS.Countdown.FIELDS.countdowns.element.progress.type.value.label' }), label: new fields.StringField({ @@ -132,7 +132,13 @@ class DhCountdown extends foundry.abstract.DataModel { export const registerCountdownHooks = () => { Hooks.on(socketEvent.Refresh, ({ refreshType, application }) => { if (refreshType === RefreshType.Countdown) { - foundry.applications.instances.get(application)?.render(); + if (application) { + foundry.applications.instances.get(application)?.render(); + } else { + foundry.applications.instances.get('narrative-countdowns').render(); + foundry.applications.instances.get('encounter-countdowns').render(); + } + return false; } }); diff --git a/module/data/settings/Automation.mjs b/module/data/settings/Automation.mjs index 4e375919..11b50406 100644 --- a/module/data/settings/Automation.mjs +++ b/module/data/settings/Automation.mjs @@ -4,20 +4,22 @@ export default class DhAutomation extends foundry.abstract.DataModel { static defineSchema() { const fields = foundry.data.fields; return { - hope: new fields.BooleanField({ - required: true, - initial: false, - label: 'DAGGERHEART.SETTINGS.Automation.FIELDS.hope.label' - }), // Label need to be updated into something like "Duality Roll Auto Gain" + a hint + hopeFear: new fields.SchemaField({ + gm: new fields.BooleanField({ + required: true, + initial: false, + label: 'DAGGERHEART.SETTINGS.Automation.FIELDS.hope.label' + }), + players: new fields.BooleanField({ + required: true, + initial: false, + label: 'DAGGERHEART.SETTINGS.Automation.FIELDS.hope.label' + }) + }), actionPoints: new fields.BooleanField({ required: true, initial: false, label: 'DAGGERHEART.SETTINGS.Automation.FIELDS.actionPoints.label' - }), - countdowns: new fields.BooleanField({ - requireD: true, - initial: false, - label: 'DAGGERHEART.SETTINGS.Automation.FIELDS.countdowns.label' }) }; } diff --git a/module/dice/dhRoll.mjs b/module/dice/dhRoll.mjs index 8744223a..c250444d 100644 --- a/module/dice/dhRoll.mjs +++ b/module/dice/dhRoll.mjs @@ -148,9 +148,9 @@ export const registerRollDiceHooks = () => { const actor = await fromUuid(config.source.actor), updates = []; if (!actor) return; - if (config.roll.isCritical || config.roll.result.duality === 1) updates.push({ type: 'hope', value: 1 }); - if (config.roll.isCritical) updates.push({ type: 'stress', value: -1 }); - if (config.roll.result.duality === -1) updates.push({ type: 'fear', value: 1 }); + if (config.roll.isCritical || config.roll.result.duality === 1) updates.push({ key: 'hope', value: 1 }); + if (config.roll.isCritical) updates.push({ key: 'stress', value: -1 }); + if (config.roll.result.duality === -1) updates.push({ key: 'fear', value: 1 }); if (updates.length) actor.modifyResource(updates); diff --git a/module/helpers/handlebarsHelper.mjs b/module/helpers/handlebarsHelper.mjs index 407f065e..21f27cd7 100644 --- a/module/helpers/handlebarsHelper.mjs +++ b/module/helpers/handlebarsHelper.mjs @@ -40,7 +40,9 @@ export default class RegisterHandlebarsHelpers { static damageSymbols(damageParts) { const symbols = new Set(); - damageParts.forEach(part => symbols.add(...CONFIG.DH.GENERAL.damageTypes[part.type].icon)); + damageParts.forEach(part => + part.type.values().forEach(type => symbols.add(CONFIG.DH.GENERAL.damageTypes[type].icon)) + ); return new Handlebars.SafeString(Array.from(symbols).map(symbol => ``)); }