import OathHammerActorSheet from "./base-actor-sheet.mjs" import { SYSTEM } from "../../config/system.mjs" export default class OathHammerCharacterSheet extends OathHammerActorSheet { /** @override */ static DEFAULT_OPTIONS = { classes: ["character"], position: { width: 972, height: 780, }, window: { contentClasses: ["character-content"], }, actions: { createWeapon: OathHammerCharacterSheet.#onCreateWeapon, createSpell: OathHammerCharacterSheet.#onCreateSpell, createMiracle: OathHammerCharacterSheet.#onCreateMiracle, createEquipment: OathHammerCharacterSheet.#onCreateEquipment, }, } /** @override */ static PARTS = { main: { template: "systems/fvtt-oath-hammer/templates/actor/character-sheet.hbs" }, tabs: { template: "templates/generic/tab-navigation.hbs" }, identity: { template: "systems/fvtt-oath-hammer/templates/actor/character-identity.hbs" }, skills: { template: "systems/fvtt-oath-hammer/templates/actor/character-skills.hbs" }, combat: { template: "systems/fvtt-oath-hammer/templates/actor/character-combat.hbs" }, magic: { template: "systems/fvtt-oath-hammer/templates/actor/character-magic.hbs" }, equipment: { template: "systems/fvtt-oath-hammer/templates/actor/character-equipment.hbs" }, notes: { template: "systems/fvtt-oath-hammer/templates/actor/character-notes.hbs" }, } /** @override */ tabGroups = { sheet: "identity", } #getTabs() { const tabs = { identity: { id: "identity", group: "sheet", icon: "fa-solid fa-person", label: "OATHHAMMER.Tab.Identity" }, skills: { id: "skills", group: "sheet", icon: "fa-solid fa-scroll", label: "OATHHAMMER.Tab.Skills" }, combat: { id: "combat", group: "sheet", icon: "fa-solid fa-swords", label: "OATHHAMMER.Tab.Combat" }, magic: { id: "magic", group: "sheet", icon: "fa-solid fa-wand-magic-sparkles", label: "OATHHAMMER.Tab.Magic" }, equipment: { id: "equipment", group: "sheet", icon: "fa-solid fa-backpack", label: "OATHHAMMER.Tab.Equipment" }, notes: { id: "notes", group: "sheet", icon: "fa-solid fa-book", label: "OATHHAMMER.Tab.Notes" }, } for (const v of Object.values(tabs)) { v.active = this.tabGroups[v.group] === v.id v.cssClass = v.active ? "active" : "" } return tabs } /** @override */ 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 } /** @override */ async _preparePartContext(partId, context) { const doc = this.document switch (partId) { case "main": break case "identity": context.tab = context.tabs.identity context.traits = doc.itemTypes.trait.map(a => { const typeKey = SYSTEM.TRAIT_TYPE_CHOICES[a.system.traitType] const periodKey = SYSTEM.TRAIT_USAGE_PERIOD[a.system.usagePeriod] const isPassive = a.system.usagePeriod === "none" return { id: a.id, uuid: a.uuid, img: a.img, name: a.name, system: a.system, _typeLabel: typeKey ? game.i18n.localize(typeKey) : a.system.traitType, _usageLabel: isPassive ? game.i18n.localize("OATHHAMMER.UsagePeriod.None") : `${a.system.maxUses > 0 ? a.system.maxUses + " / " : ""}${game.i18n.localize(periodKey)}` } }) context.oaths = doc.itemTypes.oath.map(o => { const typeEntry = SYSTEM.OATH_TYPES[o.system.oathType] return { id: o.id, uuid: o.uuid, img: o.img, name: o.name, system: o.system, _typeLabel: typeEntry ? game.i18n.localize(typeEntry.label) : o.system.oathType, _violated: o.system.violated } }) break case "skills": { context.tab = context.tabs.skills const sys = doc.system const skillSchemaFields = doc.system.schema.fields.skills.fields const attrRanks = { might: sys.attributes.might.rank, toughness: sys.attributes.toughness.rank, agility: sys.attributes.agility.rank, willpower: sys.attributes.willpower.rank, intelligence: sys.attributes.intelligence.rank, fate: sys.attributes.fate.rank, } context.skillGroups = Object.entries(SYSTEM.SKILLS_BY_ATTRIBUTE).map(([attr, skillKeys]) => ({ attribute: attr, label: `OATHHAMMER.Attribute.${attr.charAt(0).toUpperCase()}${attr.slice(1)}`, attrRank: attrRanks[attr], 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 } case "combat": context.tab = context.tabs.combat context.weapons = doc.itemTypes.weapon.map(w => { const groupKey = SYSTEM.WEAPON_PROFICIENCY_GROUPS[w.system.proficiencyGroup] const traitsLabel = [...w.system.traits].map(t => { const tk = SYSTEM.WEAPON_TRAITS[t] return tk ? game.i18n.localize(tk) : t }).join(", ") return { id: w.id, uuid: w.uuid, img: w.img, name: w.name, system: w.system, _groupLabel: groupKey ? game.i18n.localize(groupKey) : w.system.proficiencyGroup, _traitsTooltip: traitsLabel || null, _isMagic: w.system.isMagic } }) context.armors = doc.itemTypes.armor.map(a => { const typeKey = SYSTEM.ARMOR_TYPE_CHOICES[a.system.armorType] const traitsLabel = [...a.system.traits].map(t => { const tk = SYSTEM.ARMOR_TRAITS[t] return tk ? game.i18n.localize(tk) : t }).join(", ") return { id: a.id, uuid: a.uuid, img: a.img, name: a.name, system: a.system, _typeLabel: typeKey ? game.i18n.localize(typeKey) : a.system.armorType, _traitsTooltip: traitsLabel || null, _isMagic: a.system.isMagic } }) context.ammunition = doc.itemTypes.ammunition break case "magic": context.tab = context.tabs.magic context.spells = doc.itemTypes.spell context.miracles = doc.itemTypes.miracle break case "equipment": context.tab = context.tabs.equipment context.equipment = doc.itemTypes.equipment context.magicItems = doc.itemTypes["magic-item"] break case "notes": context.tab = context.tabs.notes context.enrichedBackground = await foundry.applications.ux.TextEditor.implementation.enrichHTML(doc.system.background, { async: true }) context.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(doc.system.description, { async: true }) context.enrichedNotes = await foundry.applications.ux.TextEditor.implementation.enrichHTML(doc.system.notes, { async: true }) break } 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) if (data.type === "Item") { const item = await fromUuid(data.uuid) return this._onDropItem(item) } } static #onCreateWeapon(event, target) { this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("OATHHAMMER.NewItem.Weapon"), type: "weapon" }]) } static #onCreateSpell(event, target) { this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("OATHHAMMER.NewItem.Spell"), type: "spell" }]) } static #onCreateMiracle(event, target) { this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("OATHHAMMER.NewItem.Miracle"), type: "miracle" }]) } static #onCreateEquipment(event, target) { this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("OATHHAMMER.NewItem.Equipment"), type: "equipment" }]) } }