Skip to content

Commit

Permalink
#95, #97, Include sourcemap
Browse files Browse the repository at this point in the history
- #95: Make buildActions and buildActivations public.
- #97: Fix 'lablel' error.
- Include sourcemap.
  • Loading branch information
Larkinabout committed Jun 11, 2024
1 parent f4daf83 commit 8431be0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
# Create a "module.zip" archive containing all the module's required files.
# If you have other directories or files that will need to be added to
# your packaged module, add them here.
- run: zip -r ./module.zip module.json readme.md LICENSE icons/ languages/ scripts/token-action-hud-dnd5e.min.js styles/
- run: zip -r ./module.zip module.json readme.md LICENSE icons/ languages/ scripts/token-action-hud-dnd5e.min.js* styles/

# Update the GitHub release with the manifest and module archive files.
- name: Update Release with Files
Expand Down
3 changes: 2 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default [
},
output: {
format: 'esm',
file: 'scripts/token-action-hud-dnd5e.min.js'
file: 'scripts/token-action-hud-dnd5e.min.js',
sourcemap: true
},
plugins: [
terser({ keep_classnames: true, keep_fnames: true }),
Expand Down
68 changes: 38 additions & 30 deletions scripts/action-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,13 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {

/**
* Build activations
* @param {array} items The items
* @param {object} groupData The group data
* @param {string} actionType The action type
* @public
* @param {object} data groupData, actionData, actionType
*/
async #buildActivations (items, groupData, actionType = 'item') {
// Create map of items according to activation type
async buildActivations (data) {
const { groupData, actionData, actionType = 'item' } = data

// Create map of items according to activation type
const activationItems = new Map()

// Create activation type mappings
Expand All @@ -274,7 +275,7 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
}

// Loop through items
for (const [key, value] of items) {
for (const [key, value] of actionData) {
const activationType = value.system?.activation?.type
const activationTypeOther = (Object.keys(activationTypeMappings).includes(activationType)) ? activationType : 'other'
const groupId = activationTypeMappings[activationTypeOther]
Expand Down Expand Up @@ -304,8 +305,10 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
this.addGroupInfo(groupDataClone)
}

const actionData = activationItems.get(activationGroupId)

// Build actions
await this.#buildActions(activationItems.get(activationGroupId), groupDataClone, actionType)
await this.buildActions({ groupData: groupDataClone, actionData, actionType })
}
}

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

await Promise.all([
// Build passive effects
this.#buildActions(passiveEffects, { id: 'passive-effects', type: 'system' }, actionType),
this.buildActions({ groupData: { id: 'passive-effects', type: 'system' }, actionData: passiveEffects, actionType }),
// Build temporary effects
this.#buildActions(temporaryEffects, { id: 'temporary-effects', type: 'system' }, actionType)
this.buildActions({ groupData: { id: 'temporary-effects', type: 'system' }, actionData: temporaryEffects, actionType })
])
}

Expand Down Expand Up @@ -707,13 +710,14 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
type: 'system'
}

const features = featuresMap.get(groupId)
const actionData = featuresMap.get(groupId)
const data = { groupData, actionData, actionType }

// Build actions
await this.#buildActions(features, groupData, actionType)
await this.buildActions(data)

// Build activations
if (groupNameMappings[groupId]) await this.#buildActivations(features, groupData, actionType)
if (groupNameMappings[groupId]) await this.buildActivations(data)
}
}

Expand Down Expand Up @@ -798,14 +802,15 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
type: 'system'
}

const inventory = inventoryMap.get(groupId)
const actionData = inventoryMap.get(groupId)
const data = { groupData, actionData }

// Build actions
await this.#buildActions(inventory, groupData)
await this.buildActions(data)

// Build activations
if (this.activationgroupIds) {
await this.#buildActivations(inventory, groupData)
await this.buildActivations(data)
}
}
}
Expand Down Expand Up @@ -1059,13 +1064,14 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
// Add spell slot info to group
this.addGroupInfo(groupData)

const spells = spellsMap.get(groupId)
const actionData = spellsMap.get(groupId)
const data = { groupData, actionData, actionType }

// Build actions
await this.#buildActions(spells, groupData, actionType)
await this.buildActions(data)

// Build activations
if (this.activationgroupIds) { await this.#buildActivations(spells, groupData, actionType) }
if (this.activationgroupIds) { await this.buildActivations(data) }
}
}

Expand Down Expand Up @@ -1122,21 +1128,22 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {

/**
* Build actions
* @private
* @param {object} items
* @param {object} groupData
* @param {string} actionType
* @public
* @param {object} data actionData, groupData, actionType
* @param {object} options
*/
async #buildActions (items, groupData, actionType = 'item') {
// Exit if there are no items
if (items.size === 0) return
async buildActions (data, options) {
const { actionData, groupData, actionType } = data

// Exit if there is no action data
if (actionData.size === 0) return

// Exit if there is no groupId
const groupId = (typeof groupData === 'string' ? groupData : groupData?.id)
if (!groupId) return

// Get actions
const actions = await Promise.all([...items].map(async item => await this.#getAction(actionType, item[1])))
const actions = await Promise.all([...actionData].map(async item => await this.#getAction(actionType, item[1])))

// Add actions to action list
this.addActions(actions, groupData)
Expand All @@ -1147,15 +1154,16 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
* @private
* @param {string} actionType
* @param {object} entity
* @param {object} options
* @returns {object}
*/
async #getAction (actionType, entity) {
async #getAction (actionType = 'item', entity) {
const id = entity.id ?? entity._id
let name = entity?.name ?? entity?.label
if (
entity?.system?.recharge &&
!entity?.system?.recharge?.charged &&
entity?.system?.recharge?.value
!entity?.system?.recharge?.charged &&
entity?.system?.recharge?.value
) {
name += ` (${coreModule.api.Utils.i18n('DND5E.Recharge')})`
}
Expand Down Expand Up @@ -1361,7 +1369,7 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
if (uses?.per && (consumeName || uses?.prompt) && (uses.value > 0 || uses.max > 0)) {
const of = coreModule.api.Utils.i18n('DND5E.of')
const per = uses.per === 'charges' ? '' : ` ${coreModule.api.Utils.i18n('DND5E.per')}`
const period = CONFIG.DND5E.limitedUsePeriods[uses.per].label
const period = CONFIG.DND5E.limitedUsePeriods[uses.per]?.label ?? uses.per
const amount = consumeAmount !== undefined ? consumeAmount : uses.amount
const text = `${amount > 1 ? `${amount} ${of} ` : ''}${uses.value ?? '0'}${uses.max > 0 ? `/${uses.max}` : ''}`
const title = `${text}${per} ${period}${consumeName ? ` (${of} ${consumeName})` : ''}`
Expand Down
3 changes: 2 additions & 1 deletion scripts/token-action-hud-dnd5e.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions scripts/token-action-hud-dnd5e.min.js.map

Large diffs are not rendered by default.

0 comments on commit 8431be0

Please sign in to comment.