All checks were successful
Release Creation / build (release) Successful in 57s
135 lines
4.2 KiB
JavaScript
135 lines
4.2 KiB
JavaScript
import FTLNomadActorSheet from "./base-actor-sheet.mjs"
|
|
|
|
export default class FTLNomadStarshipSheet extends FTLNomadActorSheet {
|
|
/** @override */
|
|
static DEFAULT_OPTIONS = {
|
|
classes: ["starship"],
|
|
position: {
|
|
width: 680,
|
|
height: 640,
|
|
},
|
|
window: {
|
|
contentClasses: ["starship-content"],
|
|
},
|
|
actions: {
|
|
createEquipment: FTLNomadStarshipSheet.#onCreateEquipment,
|
|
createWeapon: FTLNomadStarshipSheet.#onCreateWeapon,
|
|
},
|
|
}
|
|
|
|
/** @override */
|
|
static PARTS = {
|
|
main: {
|
|
template: "systems/fvtt-ftl-nomad/templates/starship-main.hbs",
|
|
},
|
|
tabs: {
|
|
template: "templates/generic/tab-navigation.hbs",
|
|
},
|
|
equipment: {
|
|
template: "systems/fvtt-ftl-nomad/templates/starship-equipment.hbs",
|
|
},
|
|
description: {
|
|
template: "systems/fvtt-ftl-nomad/templates/starship-description.hbs",
|
|
},
|
|
}
|
|
|
|
/** @override */
|
|
tabGroups = {
|
|
sheet: "equipment",
|
|
}
|
|
|
|
/**
|
|
* Prepare an array of form header tabs.
|
|
* @returns {Record<string, Partial<ApplicationTab>>}
|
|
*/
|
|
#getTabs() {
|
|
const tabs = {
|
|
equipment: { id: "equipment", group: "sheet", icon: "fa-solid fa-shapes", label: "FTLNOMAD.Label.equipment" },
|
|
description: { id: "description", group: "sheet", icon: "fa-solid fa-book", label: "FTLNOMAD.Label.description" },
|
|
}
|
|
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 })
|
|
context.enrichedModifications = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.modifications, { async: true })
|
|
|
|
return context
|
|
}
|
|
|
|
_generateTooltip(type, target) {
|
|
}
|
|
|
|
/** @override */
|
|
async _preparePartContext(partId, context) {
|
|
const doc = this.document
|
|
switch (partId) {
|
|
case "main":
|
|
break
|
|
case "equipment":
|
|
context.tab = context.tabs.equipment
|
|
context.weapons = doc.itemTypes.weapon
|
|
context.weapons.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 "description":
|
|
context.tab = context.tabs.description
|
|
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" }])
|
|
}
|
|
|
|
async _onRoll(event, target) {
|
|
let rollType = $(event.currentTarget).data("roll-type")
|
|
let item
|
|
console.log("rollType", rollType)
|
|
switch (rollType) {
|
|
case "damage":
|
|
let li = $(event.currentTarget).parents(".item");
|
|
item = this.actor.items.get(li.data("item-id"));
|
|
break
|
|
case "starship-guns":
|
|
item = { name: "Starship Guns", type: "weapon", system: { damage: this.actor.system.guns, rangeType: "heavyweapon" } }
|
|
rollType = "damage"
|
|
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)
|
|
}
|
|
}
|
|
|
|
}
|