All checks were successful
Release Creation / build (release) Successful in 1m26s
159 lines
5.1 KiB
JavaScript
159 lines
5.1 KiB
JavaScript
import FTLNomadActorSheet from "./base-actor-sheet.mjs"
|
|
|
|
export default class FTLNomadCreatureSheet extends FTLNomadActorSheet {
|
|
/** @override */
|
|
static DEFAULT_OPTIONS = {
|
|
classes: ["creature"],
|
|
position: {
|
|
width: 860,
|
|
height: 620,
|
|
},
|
|
window: {
|
|
contentClasses: ["creature-content"],
|
|
},
|
|
actions: {
|
|
createTrait: FTLNomadCreatureSheet.#onCreateTrait,
|
|
createAbility: FTLNomadCreatureSheet.#onCreateAbility
|
|
},
|
|
}
|
|
|
|
/** @override */
|
|
static PARTS = {
|
|
main: {
|
|
template: "systems/fvtt-ftl-nomad/templates/creature-main.hbs",
|
|
},
|
|
tabs: {
|
|
template: "templates/generic/tab-navigation.hbs",
|
|
},
|
|
traits: {
|
|
template: "systems/fvtt-ftl-nomad/templates/creature-trait.hbs",
|
|
},
|
|
biography: {
|
|
template: "systems/fvtt-ftl-nomad/templates/creature-biography.hbs",
|
|
},
|
|
}
|
|
|
|
/** @override */
|
|
tabGroups = {
|
|
sheet: "traits",
|
|
}
|
|
|
|
/**
|
|
* Prepare an array of form header tabs.
|
|
* @returns {Record<string, Partial<ApplicationTab>>}
|
|
*/
|
|
#getTabs() {
|
|
const tabs = {
|
|
traits: { id: "traits", group: "sheet", icon: "fa-solid fa-shapes", label: "FTLNOMAD.Label.traits" },
|
|
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 TextEditor.enrichHTML(this.document.system.description, { async: true })
|
|
context.enrichedNotes = await TextEditor.enrichHTML(this.document.system.notes, { async: true })
|
|
|
|
return context
|
|
}
|
|
|
|
/** @override */
|
|
async _preparePartContext(partId, context) {
|
|
const doc = this.document
|
|
switch (partId) {
|
|
case "main":
|
|
break
|
|
case "traits":
|
|
context.tab = context.tabs.traits
|
|
context.abilities = doc.itemTypes["creature-ability"]
|
|
context.abilities.sort((a, b) => a.name.localeCompare(b.name))
|
|
context.traits = doc.itemTypes["creature-trait"]
|
|
context.traits.sort((a, b) => a.name.localeCompare(b.name))
|
|
break
|
|
case "biography":
|
|
context.tab = context.tabs.biography
|
|
context.enrichedDescription = await TextEditor.enrichHTML(doc.system.description, { async: true })
|
|
context.enrichedNotes = await TextEditor.enrichHTML(doc.system.notes, { async: true })
|
|
break
|
|
}
|
|
return context
|
|
}
|
|
|
|
/**
|
|
* Creates a new attack item directly from the sheet and embeds it into the document.
|
|
* @param {Event} event The initiating click event.
|
|
* @param {HTMLElement} target The current target of the event listener.
|
|
*/
|
|
static #onCreateTrait(event, target) {
|
|
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("FTLNOMAD.Label.newTrait"), type: "creaturetrait" }])
|
|
}
|
|
|
|
static #onCreateAbility(event, target) {
|
|
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("FTLNOMAD.Label.newAbility"), type: "creatureability" }])
|
|
}
|
|
|
|
/**
|
|
* 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<void>} 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 formula
|
|
let roll
|
|
switch (rollType) {
|
|
case "skill":
|
|
let skillId = $(event.currentTarget).data("skill-id");
|
|
item = this.actor.system.skills[skillId];
|
|
await this.document.system.roll(rollType, item)
|
|
break
|
|
case "creature-damage":
|
|
formula = this.actor.system.damage
|
|
// Rolll the damage
|
|
roll = new Roll(formula)
|
|
await roll.evaluate()
|
|
roll.toMessage( { flavor: `${this.actor.name} : Damage roll` })
|
|
break
|
|
case "creature-number":
|
|
formula = this.actor.system.numberAppearing
|
|
// Rolll the damage
|
|
roll = new Roll(formula)
|
|
await roll.evaluate()
|
|
roll.toMessage({flavor: `${this.actor.name} : Number Appearing roll`})
|
|
break
|
|
default:
|
|
throw new Error(`Unknown roll type ${rollType}`)
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|
|
}
|