211 lines
7.0 KiB
JavaScript
211 lines
7.0 KiB
JavaScript
import AwEActorSheet from "./base-actor-sheet.mjs"
|
|
import { SYSTEM } from "../../config/system.mjs"
|
|
|
|
export default class AwECharacterSheet extends AwEActorSheet {
|
|
/** @override */
|
|
static DEFAULT_OPTIONS = {
|
|
classes: ["character"],
|
|
position: {
|
|
width: 960,
|
|
height: 780
|
|
},
|
|
window: {
|
|
contentClasses: ["character-content"]
|
|
},
|
|
actions: {
|
|
createAbility: AwECharacterSheet.#onCreateAbility,
|
|
createWeapon: AwECharacterSheet.#onCreateWeapon,
|
|
createKit: AwECharacterSheet.#onCreateKit,
|
|
createEquipment: AwECharacterSheet.#onCreateEquipment,
|
|
flowPointsPlus: AwECharacterSheet.#onFlowPointsPlus,
|
|
flowPointsMinus: AwECharacterSheet.#onFlowPointsMinus,
|
|
rollField: AwECharacterSheet.#onRollField
|
|
}
|
|
}
|
|
|
|
/** @override */
|
|
static PARTS = {
|
|
header: {
|
|
template: "systems/fvtt-adventures-with-emmy/templates/character-header.hbs"
|
|
},
|
|
tabs: {
|
|
template: "templates/generic/tab-navigation.hbs"
|
|
},
|
|
main: {
|
|
template: "systems/fvtt-adventures-with-emmy/templates/character-main.hbs"
|
|
},
|
|
biography: {
|
|
template: "systems/fvtt-adventures-with-emmy/templates/character-biography.hbs"
|
|
},
|
|
equipment: {
|
|
template: "systems/fvtt-adventures-with-emmy/templates/character-equipment.hbs"
|
|
}
|
|
}
|
|
|
|
/** @override */
|
|
tabGroups = {
|
|
sheet: "main"
|
|
}
|
|
|
|
/**
|
|
* Prepare an array of form header tabs.
|
|
* @returns {Record<string, Partial<ApplicationTab>>} The tab objects.
|
|
*/
|
|
#getTabs() {
|
|
const tabs = {
|
|
main: { id: "main", group: "sheet", icon: "fa-solid fa-user", label: "AWEMMY.Sheet.Tab.Main" },
|
|
biography: { id: "biography", group: "sheet", icon: "fa-solid fa-book", label: "AWEMMY.Sheet.Tab.Biography" },
|
|
equipment: { id: "equipment", group: "sheet", icon: "fa-solid fa-backpack", label: "AWEMMY.Sheet.Tab.Equipment" }
|
|
}
|
|
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()
|
|
return context
|
|
}
|
|
|
|
/** @override */
|
|
async _preparePartContext(partId, context) {
|
|
const doc = this.document
|
|
switch (partId) {
|
|
case "main":
|
|
context.tab = context.tabs.main
|
|
context.abilities = doc.itemTypes.ability.map(item => ({
|
|
...item,
|
|
costLabel: game.i18n.localize(SYSTEM.ABILITY_COST[item.system.cost]?.label ?? item.system.cost)
|
|
}))
|
|
break
|
|
case "biography":
|
|
context.tab = context.tabs.biography
|
|
context.fields = doc.itemTypes.field.map(item => ({
|
|
...item,
|
|
keyAttrLabel: game.i18n.localize(SYSTEM.ATTRIBUTES[item.system.keyAttribute]?.label ?? item.system.keyAttribute),
|
|
keyAttr2Label: item.system.keyAttribute2
|
|
? game.i18n.localize(SYSTEM.ATTRIBUTES[item.system.keyAttribute2]?.label ?? item.system.keyAttribute2)
|
|
: null
|
|
}))
|
|
context.archetypes = doc.itemTypes.archetype
|
|
context.backgrounds = doc.itemTypes.background
|
|
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
|
|
case "equipment":
|
|
context.tab = context.tabs.equipment
|
|
context.kits = doc.itemTypes.kit
|
|
context.weapons = doc.itemTypes.weapon
|
|
context.equipments = doc.itemTypes.equipment
|
|
break
|
|
}
|
|
return context
|
|
}
|
|
|
|
/** @override */
|
|
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)
|
|
}
|
|
}
|
|
|
|
/** @override */
|
|
async _onDropItem(item) {
|
|
if (!item) return
|
|
// field/background: max 1 (replace existing); archetype: multiple allowed
|
|
if (item.type === "field" || item.type === "background") {
|
|
const existing = this.document.itemTypes[item.type]
|
|
if (existing.length > 0) await existing[0].delete()
|
|
return this.document.createEmbeddedDocuments("Item", [item.toObject()])
|
|
}
|
|
if (item.type === "archetype") {
|
|
return this.document.createEmbeddedDocuments("Item", [item.toObject()])
|
|
}
|
|
return super._onDropItem(item)
|
|
}
|
|
|
|
/**
|
|
* Create a new ability item.
|
|
* @param {Event} event - The triggering event.
|
|
* @param {HTMLElement} target - The target element.
|
|
*/
|
|
static #onCreateAbility(event, target) {
|
|
const type = "ability"
|
|
this.document.createEmbeddedDocuments("Item", [{ name: CONFIG.Item.documentClass.defaultName({ type }), type }])
|
|
}
|
|
|
|
/**
|
|
* Create a new weapon item.
|
|
* @param {Event} event - The triggering event.
|
|
* @param {HTMLElement} target - The target element.
|
|
*/
|
|
static #onCreateWeapon(event, target) {
|
|
const type = "weapon"
|
|
this.document.createEmbeddedDocuments("Item", [{ name: CONFIG.Item.documentClass.defaultName({ type }), type }])
|
|
}
|
|
|
|
/**
|
|
* Create a new kit item.
|
|
* @param {Event} event - The triggering event.
|
|
* @param {HTMLElement} target - The target element.
|
|
*/
|
|
static #onCreateKit(event, target) {
|
|
const type = "kit"
|
|
this.document.createEmbeddedDocuments("Item", [{ name: CONFIG.Item.documentClass.defaultName({ type }), type }])
|
|
}
|
|
|
|
/**
|
|
* Create a new equipment item.
|
|
* @param {Event} event - The triggering event.
|
|
* @param {HTMLElement} target - The target element.
|
|
*/
|
|
static #onCreateEquipment(event, target) {
|
|
const type = "equipment"
|
|
this.document.createEmbeddedDocuments("Item", [{ name: CONFIG.Item.documentClass.defaultName({ type }), type }])
|
|
}
|
|
|
|
/**
|
|
* Increase flow points by 1.
|
|
* @param {Event} event - The triggering event.
|
|
* @param {HTMLElement} target - The target element.
|
|
*/
|
|
static #onFlowPointsPlus(event, target) {
|
|
const current = this.actor.system.flowPoints.value
|
|
this.actor.update({ "system.flowPoints.value": current + 1 })
|
|
}
|
|
|
|
/**
|
|
* Decrease flow points by 1.
|
|
* @param {Event} event - The triggering event.
|
|
* @param {HTMLElement} target - The target element.
|
|
*/
|
|
static #onFlowPointsMinus(event, target) {
|
|
const current = this.actor.system.flowPoints.value
|
|
this.actor.update({ "system.flowPoints.value": Math.max(0, current - 1) })
|
|
}
|
|
|
|
/**
|
|
* Roll the key attribute check from a Field item.
|
|
* @param {PointerEvent} event The triggering event.
|
|
* @param {HTMLElement} target The target element.
|
|
*/
|
|
static async #onRollField(event, target) {
|
|
const itemId = target.closest("[data-item-id]")?.dataset.itemId
|
|
const item = this.document.items.get(itemId)
|
|
if (!item) return
|
|
const attrId = target.dataset.attributeId ?? item.system.keyAttribute
|
|
await this.document.rollAttribute(attrId)
|
|
}
|
|
}
|