ENhance actor sheet with roll messages

This commit is contained in:
2026-03-07 16:09:00 +01:00
parent 8dec307ced
commit 63da2ef664
32 changed files with 888 additions and 22 deletions
+199
View File
@@ -0,0 +1,199 @@
import { SYSTEM } from '../../config/system.mjs'
export let ActionHandler = null
Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
ActionHandler = class ActionHandler extends coreModule.api.ActionHandler {
/** @override */
async buildSystemActions(groupIds) {
this.actors = (!this.actor) ? this._getActors() : [this.actor]
this.actorType = this.actor?.type
if (this.actorType === 'character') {
await this.#buildCharacterActions()
} else if (this.actorType === 'creature') {
await this.#buildCreatureActions()
}
}
async #buildCharacterActions() {
await this.#buildAttributes()
await this.#buildHP()
await this.#buildFlow()
await this.#buildWeapons()
await this.#buildConditions()
await this.#buildAbilities()
await this.#buildKits()
await this.#buildUtility()
}
async #buildCreatureActions() {
await this.#buildAttributes()
await this.#buildHP()
}
async #buildAttributes() {
const actions = []
const attrKeys = ['agility', 'fitness', 'awareness', 'influence']
const labelKeys = {
agility: 'AWEMMY.Attribute.Agility',
fitness: 'AWEMMY.Attribute.Fitness',
awareness: 'AWEMMY.Attribute.Awareness',
influence: 'AWEMMY.Attribute.Influence'
}
for (const key of attrKeys) {
const attr = this.actor.system.attributes?.[key]
if (!attr) continue
const mod = attr.mod ?? 0
const modText = mod >= 0 ? `+${mod}` : `${mod}`
actions.push({
name: coreModule.api.Utils.i18n(labelKeys[key]),
id: key,
info1: { text: modText },
encodedValue: ['attribute', key].join(this.delimiter)
})
}
await this.addActions(actions, { id: 'attributes', type: 'system' })
}
async #buildHP() {
const hp = this.actor.system.hp
if (!hp) return
const tooltip = { content: `${hp.value} / ${hp.max}`, direction: 'LEFT' }
const actions = [
{
name: `${hp.value} / ${hp.max}`,
id: 'hp_display',
tooltip,
encodedValue: ['hp', 'display'].join(this.delimiter)
},
{
name: '+',
id: 'hp_add',
tooltip,
encodedValue: ['hp', 'add'].join(this.delimiter)
},
{
name: '',
id: 'hp_sub',
tooltip,
encodedValue: ['hp', 'sub'].join(this.delimiter)
}
]
await this.addActions(actions, { id: 'hp', type: 'system' })
}
async #buildFlow() {
const fp = this.actor.system.flowPoints
if (fp === undefined) return
const tooltip = { content: `FP: ${fp.value}`, direction: 'LEFT' }
const actions = [
{
name: `${fp.value} FP`,
id: 'flow_display',
tooltip,
encodedValue: ['flow', 'display'].join(this.delimiter)
},
{
name: '+',
id: 'flow_add',
tooltip,
encodedValue: ['flow', 'add'].join(this.delimiter)
},
{
name: '',
id: 'flow_sub',
tooltip,
encodedValue: ['flow', 'sub'].join(this.delimiter)
}
]
await this.addActions(actions, { id: 'flow', type: 'system' })
}
async #buildWeapons() {
const weapons = this.actor.itemTypes?.weapon ?? []
for (const weapon of weapons) {
const attrId = weapon.system.attackAttribute
const attr = this.actor.system.attributes?.[attrId]
const mod = attr?.mod ?? 0
const modText = mod >= 0 ? `+${mod}` : `${mod}`
const groupData = { id: `weapon_${weapon.id}`, name: weapon.name, type: 'system' }
this.addGroup(groupData, { id: 'weapons', type: 'system' }, true)
const actions = [{
name: weapon.name,
id: `weapon_${weapon.id}`,
info1: { text: modText },
encodedValue: ['weapon', weapon.id].join(this.delimiter)
}]
await this.addActions(actions, { id: `weapon_${weapon.id}`, type: 'system' })
}
}
async #buildConditions() {
const actions = []
for (const [key, cond] of Object.entries(SYSTEM.CONDITIONS)) {
const isActive = this.actor.statuses?.has(key) ?? false
actions.push({
name: coreModule.api.Utils.i18n(cond.label),
id: key,
info1: { text: isActive ? '✓' : '' },
encodedValue: ['condition', key].join(this.delimiter)
})
}
await this.addActions(actions, { id: 'conditions', type: 'system' })
}
async #buildAbilities() {
const abilities = this.actor.itemTypes?.ability ?? []
const actions = []
for (const ability of abilities) {
const sys = ability.system
const costLabel = game.i18n.localize(SYSTEM.ABILITY_COST[sys.cost]?.label ?? sys.cost)
const isUsed = sys.usedToday
actions.push({
name: ability.name,
id: ability.id,
info1: { text: isUsed ? `${costLabel}` : costLabel },
encodedValue: ['ability', ability.id].join(this.delimiter)
})
}
await this.addActions(actions, { id: 'abilities', type: 'system' })
}
async #buildKits() {
const kits = this.actor.itemTypes?.kit ?? []
const actions = []
for (const kit of kits) {
const charges = kit.system.charges
const chargesText = `${charges.value}/${charges.max}`
actions.push({
name: kit.name,
id: kit.id,
info1: { text: chargesText },
encodedValue: ['kit', kit.id].join(this.delimiter)
})
}
await this.addActions(actions, { id: 'kits', type: 'system' })
}
async #buildUtility() {
const actions = []
actions.push({
name: coreModule.api.Utils.i18n('AWEMMY.TAH.LongRest'),
id: 'longRest',
encodedValue: ['utility', 'longRest'].join(this.delimiter)
})
if (game.combat?.current?.tokenId === this.token?.id) {
actions.push({
name: coreModule.api.Utils.i18n('AWEMMY.TAH.EndTurn'),
id: 'endTurn',
encodedValue: ['utility', 'endTurn'].join(this.delimiter)
})
}
await this.addActions(actions, { id: 'utility', type: 'system' })
}
}
})