import FTLNomadActorSheet from "./base-actor-sheet.mjs" export default class FTLNomadCharacterSheet extends FTLNomadActorSheet { /** @override */ static DEFAULT_OPTIONS = { classes: ["character"], position: { width: 860, height: 620, }, window: { contentClasses: ["character-content"], }, actions: { createEquipment: FTLNomadCharacterSheet.#onCreateEquipment, createArmor: FTLNomadCharacterSheet.#onCreateArmor, createWeapon: FTLNomadCharacterSheet.#onCreateWeapon, createTalent: FTLNomadCharacterSheet.#onCreateTalent, createImplant: FTLNomadCharacterSheet.#onCreateImplant, createPsionic: FTLNomadCharacterSheet.#onCreatePsionic, createLanguage: FTLNomadCharacterSheet.#onCreateLanguage }, } /** @override */ static PARTS = { main: { template: "systems/fvtt-ftl-nomad/templates/character-main.hbs", }, tabs: { template: "templates/generic/tab-navigation.hbs", }, talents: { template: "systems/fvtt-ftl-nomad/templates/character-talents.hbs", }, equipment: { template: "systems/fvtt-ftl-nomad/templates/character-equipment.hbs", }, biography: { template: "systems/fvtt-ftl-nomad/templates/character-biography.hbs", }, } /** @override */ tabGroups = { sheet: "talents", } /** * Prepare an array of form header tabs. * @returns {Record>} */ #getTabs() { const tabs = { talents: { id: "talents", group: "sheet", icon: "fa-solid fa-compass", label: "FTLNOMAD.Label.talents" }, equipment: { id: "equipment", group: "sheet", icon: "fa-solid fa-shapes", label: "FTLNOMAD.Label.equipment" }, biography: { id: "biography", group: "sheet", icon: "fa-solid fa-book", label: "FTLNOMAD.Label.biography" }, } 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() context.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.description, { async: true }) context.enrichedNotes = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.notes, { async: true }) return context } /** @override */ async _preparePartContext(partId, context) { const doc = this.document switch (partId) { case "main": break case "talents": context.tab = context.tabs.talents context.talents = doc.itemTypes.talent context.talents.sort((a, b) => a.name.localeCompare(b.name)) context.implants = doc.itemTypes.implant context.implants.sort((a, b) => a.name.localeCompare(b.name)) context.psionics = doc.itemTypes.psionic context.psionics.sort((a, b) => a.name.localeCompare(b.name)) context.languages = doc.itemTypes.language context.languages.sort((a, b) => a.name.localeCompare(b.name)) break case "equipment": context.tab = context.tabs.equipment context.weapons = doc.itemTypes.weapon context.weapons.sort((a, b) => a.name.localeCompare(b.name)) context.armors = doc.itemTypes.armor context.armors.sort((a, b) => a.name.localeCompare(b.name)) context.equipments = doc.itemTypes.equipment context.equipments.sort((a, b) => a.name.localeCompare(b.name)) break case "biography": context.tab = context.tabs.biography 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 } static #onCreateEquipment(event, target) { this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("FTLNOMAD.Label.newEquipment"), type: "equipment" }]) } static #onCreateWeapon(event, target) { this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("FTLNOMAD.Label.newWeapon"), type: "weapon" }]) } static #onCreateArmor(event, target) { this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("FTLNOMAD.Label.newArmor"), type: "armor" }]) } static #onCreateTalent(event, target) { this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("FTLNOMAD.Label.newTalent"), type: "talent" }]) } static #onCreateImplant(event, target) { this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("FTLNOMAD.Label.newImplant"), type: "implant" }]) } static #onCreatePsionic(event, target) { this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("FTLNOMAD.Label.newPsionic"), type: "psionic" }]) } static #onCreateLanguage(event, target) { this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("FTLNOMAD.Label.newLanguage"), type: "language" }]) } /** * Handles the roll action triggered by user interaction. * * @param {PointerEvent} event The event object representing the user interaction. * @param {HTMLElement} target The target element that triggered the roll. * * @returns {Promise} A promise that resolves when the roll action is complete. * * @throws {Error} Throws an error if the roll type is not recognized. * * @description This method checks the current mode (edit or not) and determines the type of roll * (save, resource, or damage) based on the target element's data attributes. It retrieves the * corresponding value from the document's system and performs the roll. */ async _onRoll(event, target) { const rollType = $(event.currentTarget).data("roll-type") let item let li switch (rollType) { case "skill": let skillId = $(event.currentTarget).data("skill-id"); item = this.actor.system.skills[skillId]; break case "weapon": case "damage": li = $(event.currentTarget).parents(".item"); item = this.actor.items.get(li.data("item-id")); break default: throw new Error(`Unknown roll type ${rollType}`) } await this.document.system.roll(rollType, item) } async _onDrop(event) { if (!this.isEditable || !this.isEditMode) return const data = TextEditor.getDragEventData(event) // Handle different data types switch (data.type) { case "Item": const item = await fromUuid(data.uuid) return super._onDropItem(item) } } }