Skip to content

Commit

Permalink
Merge pull request #140 from Silvertower/main
Browse files Browse the repository at this point in the history
Fix an issue causing strike trait toggles to fail
  • Loading branch information
Silvertower authored Apr 10, 2024
2 parents b28febf + 481e23f commit c7566e9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
6 changes: 3 additions & 3 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@
"type": "system",
"compatibility": [
{
"minimum": "5.14.0",
"verified": "5.14.3"
"minimum": "5.15.0",
"verified": "5.15.0"
}
]
}
Expand All @@ -108,7 +108,7 @@
{
"minimum": "1.5.0",
"maximum": "1.5",
"verified": "1.5.3"
"verified": "1.5.4"
}
]
}
Expand Down
6 changes: 3 additions & 3 deletions scripts/action-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1617,14 +1617,14 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
if (strike.versatileOptions?.length) {
// Get actions
versatileOptionActions = strike.versatileOptions.map(versatileOption => {
const id = encodeURIComponent(`${strike.item.id}>${strike.slug}>${versatileOption.value}>`)
const encodedId = encodeURIComponent(`${strike.item.id}>${strike.slug}>${versatileOption.value}>`)
const fullName = coreModule.api.Utils.i18n(versatileOption.label)
return {
id: encodeURIComponent(`${strike.item.id}>${strike.slug}>${versatileOption.value}>`),
id: encodedId,
name: '',
fullName,
listName: `${strikeGroupListName}: ${fullName}`,
encodedValue: ['versatileOption', id].join(this.delimiter),
encodedValue: ['versatileOption', encodedId].join(this.delimiter),
cssClass: this.#getActionCss(versatileOption),
icon1: this.#getActionIcon(versatileOption.glyph, fullName)
}
Expand Down
19 changes: 14 additions & 5 deletions scripts/roll-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,16 +634,25 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {

// Adapted from pf2e
async function toggleWeaponTrait ({ weapon, trait, selection }) {
if (weapon.system.traits.toggles[trait].selection === selection) return
if (!actor?.isOfType('character')) return

const item = weapon.actor?.items.get(weapon.id)
const item = actor.items.get(weapon.id)

const property = trait === 'double-barrel' ? 'doubleBarrel' : trait
const current = item.system.traits.toggles[property].selected
if (current === selection) return

if (item?.isOfType('weapon') && item === weapon) {
await item.update({ [`system.traits.toggles.${trait}.selection`]: selection })
const value = property === 'doubleBarrel' ? !!selection : selection
await item.update({ [`system.traits.toggles.${property}.selected`]: value })
} else if (item?.isOfType('weapon') && weapon.altUsageType === 'melee') {
item.update({ [`system.meleeUsage.traitToggles.${trait}`]: selection })
} else {
const rule = item?.rules.find(r => r.key === 'Strike' && !r.ignored && r.slug === weapon.slug)
} else if (trait === 'versatile' && item?.isOfType('shield')) {
item.update({ 'system.traits.integrated.versatile.selected': selection })
} else if (trait !== 'double-barrel') {
const rule = item?.rules.find(
r => r.key === 'Strike' && !r.ignored && r.slug === weapon.slug
)
await rule?.toggleTrait({ trait, selection })
}
}
Expand Down

0 comments on commit c7566e9

Please sign in to comment.