Item ehnance, fixes on actor sheet

This commit is contained in:
2026-03-08 11:35:00 +01:00
parent e9abefd90d
commit aaf965c78a
13 changed files with 849 additions and 208 deletions

View File

@@ -57,6 +57,10 @@ export default class OathHammerCharacterSheet extends OathHammerActorSheet {
async _prepareContext() {
const context = await super._prepareContext()
context.tabs = this.#getTabs()
// lineage/class/experience available to all parts (header + identity tab)
const doc = this.document
context.lineage = doc.itemTypes.lineage?.[0] ?? null
context.characterClass = doc.itemTypes["class"]?.[0] ?? null
return context
}
@@ -68,8 +72,6 @@ export default class OathHammerCharacterSheet extends OathHammerActorSheet {
break
case "identity":
context.tab = context.tabs.identity
context.lineage = doc.itemTypes.lineage?.[0] ?? null
context.characterClass = doc.itemTypes["class"]?.[0] ?? null
context.abilities = doc.itemTypes.ability
context.oaths = doc.itemTypes.oath
break
@@ -89,14 +91,26 @@ export default class OathHammerCharacterSheet extends OathHammerActorSheet {
attribute: attr,
label: `OATHHAMMER.Attribute.${attr.charAt(0).toUpperCase()}${attr.slice(1)}`,
attrRank: attrRanks[attr],
skillData: skillKeys.map(skillKey => ({
key: skillKey,
label: SYSTEM.SKILLS[skillKey].label,
rank: sys.skills[skillKey].rank,
name: `system.skills.${skillKey}.rank`,
total: attrRanks[attr] + sys.skills[skillKey].rank,
field: skillSchemaFields[skillKey].fields.rank,
}))
skillData: skillKeys.map(skillKey => {
const sk = sys.skills[skillKey]
return {
key: skillKey,
label: SYSTEM.SKILLS[skillKey].label,
rank: sk.rank,
modifier: sk.modifier,
colorDice: sk.colorDice,
colorDiceType: sk.colorDiceType,
rankName: `system.skills.${skillKey}.rank`,
modifierName: `system.skills.${skillKey}.modifier`,
colorDiceName: `system.skills.${skillKey}.colorDice`,
colorDiceTypeName: `system.skills.${skillKey}.colorDiceType`,
rankOptions: [0,1,2,3,4].map(v => ({ value: v, label: String(v), selected: v === sk.rank })),
total: attrRanks[attr] + sk.rank,
// legacy - kept for formInput compatibility
name: `system.skills.${skillKey}.rank`,
field: skillSchemaFields[skillKey].fields.rank,
}
})
}))
break
}
@@ -125,6 +139,36 @@ export default class OathHammerCharacterSheet extends OathHammerActorSheet {
return context
}
/** Auto-fill colorDice count when color type changes */
static #COLOR_THRESHOLDS = { white: 4, red: 3, black: 2 }
_onRender(context, options) {
super._onRender?.(context, options)
// Color dice auto-fill
this.element.querySelectorAll('select.color-dice-select').forEach(select => {
select.addEventListener('change', event => {
const threshold = OathHammerCharacterSheet.#COLOR_THRESHOLDS[event.target.value] ?? 4
const countInput = event.target.closest('.skill-color-col')?.querySelector('input[type="number"]')
if (countInput) {
countInput.value = threshold
countInput.dispatchEvent(new Event('change', { bubbles: true }))
}
const dot = event.target.closest('.skill-color-col')?.querySelector('.color-dice-dot')
if (dot) dot.className = `color-dice-dot color-dice-${event.target.value}`
})
})
// Equipped checkbox — directly updates the item
this.element.querySelectorAll('input.item-equipped-cb').forEach(cb => {
cb.addEventListener('change', event => {
const itemId = event.target.dataset.itemId
const item = this.document.items.get(itemId)
if (item) item.update({ 'system.equipped': event.target.checked })
})
})
}
async _onDrop(event) {
if (!this.isEditable) return
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event)