Skip to content

Commit

Permalink
addStowedItems
Browse files Browse the repository at this point in the history
- Add 'addStowedItems' module setting.
  • Loading branch information
Larkinabout committed Jun 30, 2023
1 parent 776bfb4 commit 40bb86d
Show file tree
Hide file tree
Showing 15 changed files with 168 additions and 6 deletions.
10 changes: 10 additions & 0 deletions languages/br.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
"hint": "Choose whether to add damage and critical actions for strikes by default",
"name": "Add Damage and Critical"
},
"addStowedItems": {
"hint": "Choose where to add stowed items",
"name": "Add Stowed Items",
"choices": {
"containers": "Container Groups Only",
"nonContainers": "Non-Container Groups Only",
"both": "Container and Non-Container Groups",
"none": "No Groups"
}
},
"addUnequippedItems": {
"hint": "Choose whether to add unequipped items by default",
"name": "Add Unequipped Items"
Expand Down
10 changes: 10 additions & 0 deletions languages/cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
"hint": "Choose whether to add damage and critical actions for strikes by default",
"name": "Add Damage and Critical"
},
"addStowedItems": {
"hint": "Choose where to add stowed items",
"name": "Add Stowed Items",
"choices": {
"containers": "Container Groups Only",
"nonContainers": "Non-Container Groups Only",
"both": "Container and Non-Container Groups",
"none": "No Groups"
}
},
"addUnequippedItems": {
"hint": "Choose whether to add unequipped items by default",
"name": "Add Unequipped Items"
Expand Down
10 changes: 10 additions & 0 deletions languages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
"hint": "Choose whether to add damage and critical actions for strikes by default",
"name": "Add Damage and Critical"
},
"addStowedItems": {
"hint": "Choose where to add stowed items",
"name": "Add Stowed Items",
"choices": {
"containers": "Container Groups Only",
"nonContainers": "Non-Container Groups Only",
"both": "Container and Non-Container Groups",
"none": "No Groups"
}
},
"addUnequippedItems": {
"hint": "Choose whether to add unequipped items by default",
"name": "Add Unequipped Items"
Expand Down
10 changes: 10 additions & 0 deletions languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
"hint": "Choose whether to add damage and critical actions for strikes by default",
"name": "Add Damage and Critical"
},
"addStowedItems": {
"hint": "Choose where to add stowed items",
"name": "Add Stowed Items",
"choices": {
"containers": "Container Groups Only",
"nonContainers": "Non-Container Groups Only",
"both": "Container and Non-Container Groups",
"none": "No Groups"
}
},
"addUnequippedItems": {
"hint": "Choose whether to add unequipped items by default",
"name": "Add Unequipped Items"
Expand Down
10 changes: 10 additions & 0 deletions languages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
"hint": "Choose whether to add damage and critical actions for strikes by default",
"name": "Add Damage and Critical"
},
"addStowedItems": {
"hint": "Choose where to add stowed items",
"name": "Add Stowed Items",
"choices": {
"containers": "Container Groups Only",
"nonContainers": "Non-Container Groups Only",
"both": "Container and Non-Container Groups",
"none": "No Groups"
}
},
"addUnequippedItems": {
"hint": "Choose whether to add unequipped items by default",
"name": "Add Unequipped Items"
Expand Down
10 changes: 10 additions & 0 deletions languages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
"hint": "Choose whether to add damage and critical actions for strikes by default",
"name": "Add Damage and Critical"
},
"addStowedItems": {
"hint": "Choose where to add stowed items",
"name": "Add Stowed Items",
"choices": {
"containers": "Container Groups Only",
"nonContainers": "Non-Container Groups Only",
"both": "Container and Non-Container Groups",
"none": "No Groups"
}
},
"addUnequippedItems": {
"hint": "Choose whether to add unequipped items by default",
"name": "Add Unequipped Items"
Expand Down
10 changes: 10 additions & 0 deletions languages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
"hint": "Choose whether to add damage and critical actions for strikes by default",
"name": "Add Damage and Critical"
},
"addStowedItems": {
"hint": "Choose where to add stowed items",
"name": "Add Stowed Items",
"choices": {
"containers": "Container Groups Only",
"nonContainers": "Non-Container Groups Only",
"both": "Container and Non-Container Groups",
"none": "No Groups"
}
},
"addUnequippedItems": {
"hint": "Choose whether to add unequipped items by default",
"name": "Add Unequipped Items"
Expand Down
10 changes: 10 additions & 0 deletions languages/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
"hint": "Choose whether to add damage and critical actions for strikes by default",
"name": "Add Damage and Critical"
},
"addStowedItems": {
"hint": "Choose where to add stowed items",
"name": "Add Stowed Items",
"choices": {
"containers": "Container Groups Only",
"nonContainers": "Non-Container Groups Only",
"both": "Container and Non-Container Groups",
"none": "No Groups"
}
},
"addUnequippedItems": {
"hint": "Choose whether to add unequipped items by default",
"name": "Add Unequipped Items"
Expand Down
10 changes: 10 additions & 0 deletions languages/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
"hint": "Choose whether to add damage and critical actions for strikes by default",
"name": "Add Damage and Critical"
},
"addStowedItems": {
"hint": "Choose where to add stowed items",
"name": "Add Stowed Items",
"choices": {
"containers": "Container Groups Only",
"nonContainers": "Non-Container Groups Only",
"both": "Container and Non-Container Groups",
"none": "No Groups"
}
},
"addUnequippedItems": {
"hint": "Choose whether to add unequipped items by default",
"name": "Add Unequipped Items"
Expand Down
10 changes: 10 additions & 0 deletions languages/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
"hint": "Choose whether to add damage and critical actions for strikes by default",
"name": "Add Damage and Critical"
},
"addStowedItems": {
"hint": "Choose where to add stowed items",
"name": "Add Stowed Items",
"choices": {
"containers": "Container Groups Only",
"nonContainers": "Non-Container Groups Only",
"both": "Container and Non-Container Groups",
"none": "No Groups"
}
},
"addUnequippedItems": {
"hint": "Choose whether to add unequipped items by default",
"name": "Add Unequipped Items"
Expand Down
10 changes: 10 additions & 0 deletions languages/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
"hint": "Choose whether to add damage and critical actions for strikes by default",
"name": "Add Damage and Critical"
},
"addStowedItems": {
"hint": "Choose where to add stowed items",
"name": "Add Stowed Items",
"choices": {
"containers": "Container Groups Only",
"nonContainers": "Non-Container Groups Only",
"both": "Container and Non-Container Groups",
"none": "No Groups"
}
},
"addUnequippedItems": {
"hint": "Choose whether to add unequipped items by default",
"name": "Add Unequipped Items"
Expand Down
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"version": "This is auto replaced",
"compatibility": {
"minimum": "10",
"verified": "11.301"
"verified": "11.304"
},
"esmodules": [
"./scripts/token-action-hud-pf2e.min.js"
Expand Down Expand Up @@ -108,7 +108,7 @@
{
"minimum": "1.4.8",
"maximum": "1.4",
"verified": "1.4.9"
"verified": "1.4.10"
}
]
}
Expand Down
36 changes: 33 additions & 3 deletions scripts/action-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
this.showStrikeNames = Utils.getSetting('showStrikeNames')
this.splitStrikes = Utils.getSetting('splitStrikes')
this.addDamageAndCritical = Utils.getSetting('addDamageAndCritical')
this.addStowedItems = Utils.getSetting('addStowedItems')
this.addUnequippedItems = Utils.getSetting('addUnequippedItems')

// Set group variables
Expand Down Expand Up @@ -662,9 +663,10 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
for (const [key, value] of this.items) {
const hasQuantity = value.system?.quantity > 0
const isEquippedItem = this.#isEquippedItem(value)
const isAddItem = this.#isAddItem('nonContainer', value)
const type = value.type

if (hasQuantity) {
if (hasQuantity && isAddItem) {
const itemType = isEquippedItem ? 'equipped' : 'unequipped'
const itemCategoryMap = inventoryMap.get(itemType) ?? new Map()
itemCategoryMap.set(key, value)
Expand Down Expand Up @@ -748,10 +750,18 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
// Add group to action list
await this.addGroup(groupData, parentGroupData)

const items = new Map(contents.map(content => [content.id, content]))
const contentsMap = new Map()

for (const content of contents) {
const isAddItem = this.#isAddItem('container', content)

if (isAddItem) {
contentsMap.set(content.id, content)
}
}

const actions = await Promise.all(
[...items].map(async ([_, itemData]) => {
[...contentsMap].map(async ([_, itemData]) => {
const id = this.#getActionId(itemData)
const name = this.#getActionName(itemData)
const listName = this.#getActionListName(itemData, actionType)
Expand Down Expand Up @@ -1667,6 +1677,26 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
return false
}

#isAddItem (groupType, item) {
if (item.system.equipped?.carryType !== 'stowed') return true
return this.#isAddStowedItem(groupType, item)
}

/**
* Is add stowed item
* @private
* @param {string} groupType The group type: container or nonContainer
* @param {object} item The item
* @returns {boolean} Whether the stowed item should be added to the group
*/
#isAddStowedItem (groupType, item) {
if (item.system.equipped?.carryType !== 'stowed') return true
if (this.addStowedItems === 'both') return true
if (groupType === 'container' && this.addStowedItems === 'containers') return true
if (groupType === 'nonContainer' && this.addStowedItems === 'nonContainers') return true
return false
}

/**
* Get item info
* @private
Expand Down
22 changes: 22 additions & 0 deletions scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,28 @@ export function register (updateFunc) {
}
})

game.settings.register(MODULE.ID, 'addStowedItems', {
name: game.i18n.localize(
'tokenActionHud.pf2e.settings.addStowedItems.name'
),
hint: game.i18n.localize(
'tokenActionHud.pf2e.settings.addStowedItems.hint'
),
scope: 'client',
config: true,
type: String,
default: 'containers',
choices: {
containers: game.i18n.localize('tokenActionHud.pf2e.settings.addStowedItems.choices.containers'),
nonContainers: game.i18n.localize('tokenActionHud.pf2e.settings.addStowedItems.choices.nonContainers'),
both: game.i18n.localize('tokenActionHud.pf2e.settings.addStowedItems.choices.both'),
none: game.i18n.localize('tokenActionHud.pf2e.settings.addStowedItems.choices.none')
},
onChange: (value) => {
updateFunc(value)
}
})

game.settings.register(MODULE.ID, 'addUnequippedItems', {
name: game.i18n.localize(
'tokenActionHud.pf2e.settings.addUnequippedItems.name'
Expand Down
2 changes: 1 addition & 1 deletion scripts/token-action-hud-pf2e.min.js

Large diffs are not rendered by default.

0 comments on commit 40bb86d

Please sign in to comment.