Skip to content

Commit

Permalink
Merge pull request #161 from Silvertower/main
Browse files Browse the repository at this point in the history
Updates to support PF2e system 6.6.2
  • Loading branch information
Silvertower authored Nov 11, 2024
2 parents ea90d9e + beb5a44 commit 725b7ac
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 28 deletions.
6 changes: 3 additions & 3 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@
"id": "pf2e",
"type": "system",
"compatibility": {
"minimum": "6.5.0",
"verified": "6.6.0"
"minimum": "6.6.2",
"verified": "6.6.2"
}
}
],
Expand All @@ -107,7 +107,7 @@
"type": "module",
"compatibility": {
"minimum": "2.0.0",
"verified": "2.0.5",
"verified": "2.0.6",
"maximum": "2.0.99"
}
}
Expand Down
62 changes: 43 additions & 19 deletions scripts/action-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
this.#buildEffects(),
this.#buildFeats(),
this.#buildHeroActions(),
this.#buildHeroPoints(),
this.#buildPoints('heroPoints'),
this.#buildPoints('mythicPoints'),
this.#buildInitiative(),
this.#buildInventory(),
this.#buildPerceptionCheck(),
Expand Down Expand Up @@ -451,26 +452,47 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
/**
* Build hero points
*/
async #buildHeroPoints () {
const actionType = 'heroPoints'
async #buildPoints (actionType) {
let actions, groupData

const mythicEnabled = this.actor.system.resources?.mythicPoints.max ? true : false

// Create group data
const groupData = { id: 'hero-points', type: 'system' }
if (actionType === 'heroPoints' && !mythicEnabled) {
groupData = { id: 'hero-points', type: 'system' }

const heroPoints = this.actor.system.resources?.heroPoints
const value = heroPoints.value
const max = heroPoints.max
const heroPoints = this.actor.system.resources?.heroPoints
const value = heroPoints.value
const max = heroPoints.max

// Get actions
const actions = [{
id: 'heroPoints',
name: coreModule.api.Utils.i18n('PF2E.HeroPointsLabel'),
encodedValue: [actionType, actionType].join(this.delimiter),
info1: { text: (max > 0) ? `${value ?? 0}/${max}` : '' }
}]
// Get actions
actions = [{
id: 'heroPoints',
name: coreModule.api.Utils.i18n('PF2E.Actor.Resource.HeroPoints'),
encodedValue: [actionType, actionType].join(this.delimiter),
info1: { text: (max > 0) ? `${value ?? 0}/${max}` : '' }
}]
}
else if (actionType === 'mythicPoints' && mythicEnabled) {
groupData = { id: 'mythic-points', type: 'system' }

const mythicPoints = this.actor.system.resources?.mythicPoints
const value = mythicPoints.value
const max = mythicPoints.max

// Get actions
actions = [{
id: 'mythicPoints',
name: coreModule.api.Utils.i18n('PF2E.Actor.Resource.MythicPoints'),
encodedValue: [actionType, actionType].join(this.delimiter),
info1: { text: (max > 0) ? `${value ?? 0}/${max}` : '' }
}]
}

// Add actions to action list
this.addActions(actions, groupData)
if (actions && groupData) {
this.addActions(actions, groupData)
}
}

/**
Expand Down Expand Up @@ -593,9 +615,9 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
}

/**
* Build Hero Actions
* @private
*/
* Build hero actions
* @private
*/
async #buildHeroActions () {
if (!game.modules.get('pf2e-hero-actions')?.active) return

Expand Down Expand Up @@ -2126,7 +2148,9 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {

if (!description && !tagsHtml && !modifiersHtml) return name

return `<div>${nameHtml}${headerTags}${description}${propertiesHtml}</div>`
const tooltipHtml = `<div>${nameHtml}${headerTags}${description}${propertiesHtml}</div>`

return await TextEditor.enrichHTML(tooltipHtml, { async: true })
}

/**
Expand Down
3 changes: 2 additions & 1 deletion scripts/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ export const GROUP = {
generalFeats: { id: 'general-feats', name: 'PF2E.FeatGeneralHeader', type: 'system' },
bonusFeats: { id: 'bonus-feats', name: 'PF2E.FeatBonusHeader', type: 'system' },
spells: { id: 'spells', name: 'PF2E.Item.Spell.Plural', type: 'system' },
heroPoints: { id: 'hero-points', name: 'PF2E.HeroPointsLabel', type: 'system' },
heroPoints: { id: 'hero-points', name: 'PF2E.Actor.Resource.HeroPoints', type: 'system' },
mythicPoints: { id: 'mythic-points', name: 'PF2E.Actor.Resource.MythicPoints', type: 'system' },
initiative: { id: 'initiative', name: 'PF2E.InitiativeLabel', type: 'system' },
perceptionCheck: { id: 'perception-check', name: 'PF2E.PerceptionLabel', type: 'system' },
coreSkills: { id: 'core-skills', name: 'PF2E.CoreSkillsHeader', type: 'system' },
Expand Down
1 change: 1 addition & 0 deletions scripts/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
name: coreModule.api.Utils.i18n('tokenActionHud.pf2e.attributes'),
groups: [
{ ...groups.heroPoints, nestId: 'attributes_hero-points' },
{ ...groups.mythicPoints, nestId: 'attributes_mythic-points' },
{ ...groups.initiative, nestId: 'attributes_initiative' },
{ ...groups.perceptionCheck, nestId: 'attributes_perception-check' },
{ ...groups.saves, nestId: 'attributes_saves' }
Expand Down
18 changes: 14 additions & 4 deletions scripts/roll-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,15 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
case 'feat':
this.#rollItemMacro(event, actor, actionId)
break
case 'heroAction':
this.#performHeroAction(actor, actionId)
break
case 'heroAction':
this.#performHeroAction(actor, actionId)
break
case 'heroPoints':
await this.#adjustResources(actor, 'heroPoints', 'value')
break
case 'mythicPoints':
await this.#adjustResources(actor, 'mythicPoints', 'value')
break
case 'initiative':
this.#rollInitiative(actor, actionId)
break
Expand Down Expand Up @@ -375,7 +378,14 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
}
}

await actor.update({ "system.resources.heroPoints.value": value });
switch (resource) {
case "heroPoints":
await actor.update({ "system.resources.heroPoints.value": value })
break
case "mythicPoints":
await actor.update({ "system.resources.mythicPoints.value": value })
break
}

Hooks.callAll('forceUpdateTokenActionHud')
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/token-action-hud-pf2e.min.js.map

Large diffs are not rendered by default.

0 comments on commit 725b7ac

Please sign in to comment.