239 lines
8.1 KiB
JavaScript
239 lines
8.1 KiB
JavaScript
import AwEActorSheet from "./base-actor-sheet.mjs"
|
|
import { SYSTEM } from "../../config/system.mjs"
|
|
|
|
export default class AwECreatureSheet extends AwEActorSheet {
|
|
/** @override */
|
|
static DEFAULT_OPTIONS = {
|
|
classes: ["creature"],
|
|
position: {
|
|
width: 700,
|
|
height: 700
|
|
},
|
|
window: {
|
|
contentClasses: ["creature-content"]
|
|
},
|
|
actions: {
|
|
createAbility: AwECreatureSheet.#onCreateAbility,
|
|
createSkill: AwECreatureSheet.#onCreateSkill,
|
|
createEffect: AwECreatureSheet.#onCreateEffect,
|
|
createWeapon: AwECreatureSheet.#onCreateWeapon,
|
|
createKit: AwECreatureSheet.#onCreateKit,
|
|
createEquipment: AwECreatureSheet.#onCreateEquipment,
|
|
rollWeapon: AwECreatureSheet.#onRollWeapon,
|
|
rollDamage: AwECreatureSheet.#onRollDamage,
|
|
useAbility: AwECreatureSheet.#onUseAbility,
|
|
toggleCondition: AwECreatureSheet.#onToggleCondition,
|
|
addTrait: AwECreatureSheet.#onAddTrait,
|
|
removeTrait: AwECreatureSheet.#onRemoveTrait
|
|
}
|
|
}
|
|
|
|
/** @override */
|
|
static PARTS = {
|
|
header: {
|
|
template: "systems/fvtt-adventures-with-emmy/templates/creature-header.hbs"
|
|
},
|
|
tabs: {
|
|
template: "templates/generic/tab-navigation.hbs"
|
|
},
|
|
main: {
|
|
template: "systems/fvtt-adventures-with-emmy/templates/creature-main.hbs"
|
|
},
|
|
inventory: {
|
|
template: "systems/fvtt-adventures-with-emmy/templates/creature-inventory.hbs"
|
|
},
|
|
description: {
|
|
template: "systems/fvtt-adventures-with-emmy/templates/creature-description.hbs"
|
|
},
|
|
eureka: {
|
|
template: "systems/fvtt-adventures-with-emmy/templates/creature-eureka.hbs"
|
|
}
|
|
}
|
|
|
|
/** @override */
|
|
tabGroups = {
|
|
sheet: "main"
|
|
}
|
|
|
|
#getTabs() {
|
|
const tabs = {
|
|
main: { id: "main", group: "sheet", icon: "fa-solid fa-dragon", label: "AWEMMY.Sheet.Tab.Main" },
|
|
inventory: { id: "inventory", group: "sheet", icon: "fa-solid fa-backpack", label: "AWEMMY.Sheet.Tab.Inventory" },
|
|
description: { id: "description", group: "sheet", icon: "fa-solid fa-scroll", label: "AWEMMY.Sheet.Tab.Description" },
|
|
eureka: { id: "eureka", group: "sheet", icon: "fa-solid fa-lightbulb", label: "AWEMMY.Sheet.Tab.Eureka" }
|
|
}
|
|
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 }
|
|
)
|
|
return context
|
|
}
|
|
|
|
/** @override */
|
|
async _preparePartContext(partId, context) {
|
|
switch (partId) {
|
|
case "main":
|
|
context.tab = context.tabs.main
|
|
context.abilities = this.document.itemTypes.ability.map(item => ({
|
|
id: item.id,
|
|
uuid: item.uuid,
|
|
name: item.name,
|
|
img: item.img,
|
|
system: item.system,
|
|
costLabel: game.i18n.localize(SYSTEM.ABILITY_COST[item.system.cost]?.label ?? item.system.cost),
|
|
usedToday: item.system.usedToday
|
|
}))
|
|
context.skills = this.document.itemTypes.skill.map(item => ({
|
|
id: item.id,
|
|
uuid: item.uuid,
|
|
name: item.name,
|
|
img: item.img,
|
|
system: item.system
|
|
}))
|
|
context.effects = this.document.itemTypes.effect.map(item => ({
|
|
id: item.id,
|
|
uuid: item.uuid,
|
|
name: item.name,
|
|
img: item.img,
|
|
system: item.system
|
|
}))
|
|
const doc = this.document
|
|
context.conditions = Object.values(SYSTEM.CONDITIONS).map(c => ({
|
|
...c,
|
|
label: game.i18n.localize(c.label),
|
|
img: `systems/fvtt-adventures-with-emmy/assets/conditions/${c.id}.svg`,
|
|
active: doc.statuses.has(c.id)
|
|
}))
|
|
context.inhibitedActive = doc.statuses.has("inhibited")
|
|
context.vulnerableActive = doc.statuses.has("vulnerable")
|
|
context.inhibitedPenalty = doc.system.inhibitedPenalty
|
|
context.vulnerablePenalty = doc.system.vulnerablePenalty
|
|
context.hasConditionPenalties = context.inhibitedActive || context.vulnerableActive
|
|
context.traitSuggestions = SYSTEM.TRAITS
|
|
break
|
|
case "inventory":
|
|
context.tab = context.tabs.inventory
|
|
context.kits = this.document.itemTypes.kit
|
|
context.weapons = this.document.itemTypes.weapon
|
|
context.equipments = this.document.itemTypes.equipment
|
|
break
|
|
case "description":
|
|
context.tab = context.tabs.description
|
|
break
|
|
case "eureka":
|
|
context.tab = context.tabs.eureka
|
|
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
|
|
return super._onDropItem(item)
|
|
}
|
|
|
|
/** @override */
|
|
_onRender(context, options) {
|
|
super._onRender(context, options)
|
|
this.element.querySelectorAll("input.new-tag[data-action]").forEach(input => {
|
|
input.addEventListener("keydown", event => {
|
|
if (event.key !== "Enter") return
|
|
event.preventDefault()
|
|
const actionName = input.dataset.action
|
|
const handler = this.options.actions?.[actionName]
|
|
if (handler) handler.call(this, event, input)
|
|
})
|
|
})
|
|
}
|
|
|
|
static #onCreateAbility(event, target) {
|
|
const type = "ability"
|
|
this.document.createEmbeddedDocuments("Item", [{ name: CONFIG.Item.documentClass.defaultName({ type }), type }])
|
|
}
|
|
|
|
static #onCreateSkill(event, target) {
|
|
const type = "skill"
|
|
this.document.createEmbeddedDocuments("Item", [{ name: CONFIG.Item.documentClass.defaultName({ type }), type }])
|
|
}
|
|
|
|
static #onCreateEffect(event, target) {
|
|
const type = "effect"
|
|
this.document.createEmbeddedDocuments("Item", [{ name: CONFIG.Item.documentClass.defaultName({ type }), type }])
|
|
}
|
|
|
|
static #onCreateWeapon(event, target) {
|
|
const type = "weapon"
|
|
this.document.createEmbeddedDocuments("Item", [{ name: CONFIG.Item.documentClass.defaultName({ type }), type }])
|
|
}
|
|
|
|
static #onCreateKit(event, target) {
|
|
const type = "kit"
|
|
this.document.createEmbeddedDocuments("Item", [{ name: CONFIG.Item.documentClass.defaultName({ type }), type }])
|
|
}
|
|
|
|
static #onCreateEquipment(event, target) {
|
|
const type = "equipment"
|
|
this.document.createEmbeddedDocuments("Item", [{ name: CONFIG.Item.documentClass.defaultName({ type }), type }])
|
|
}
|
|
|
|
static async #onUseAbility(event, target) {
|
|
const itemId = target.closest("[data-item-id]")?.dataset.itemId
|
|
await this.document.useAbility(itemId)
|
|
}
|
|
|
|
static async #onToggleCondition(event, target) {
|
|
const conditionId = target.dataset.conditionId
|
|
await this.document.toggleStatusEffect(conditionId)
|
|
}
|
|
|
|
static async #onRollWeapon(event, target) {
|
|
const itemId = target.closest("[data-item-id]")?.dataset.itemId
|
|
const item = this.document.items.get(itemId)
|
|
if (!item) return
|
|
await this.document.rollWeapon(item)
|
|
}
|
|
|
|
static async #onRollDamage(event, target) {
|
|
const itemId = target.closest("[data-item-id]")?.dataset.itemId
|
|
const item = this.document.items.get(itemId)
|
|
if (!item) return
|
|
await this.document.rollDamage(item)
|
|
}
|
|
|
|
static async #onAddTrait(event, target) {
|
|
const value = target.value.trim()
|
|
if (!value) return
|
|
const current = foundry.utils.getProperty(this.document, "system.traits") ?? []
|
|
await this.document.update({ "system.traits": [...current, value] })
|
|
target.value = ""
|
|
}
|
|
|
|
static async #onRemoveTrait(event, target) {
|
|
const index = Number(target.dataset.index)
|
|
const current = [...(foundry.utils.getProperty(this.document, "system.traits") ?? [])]
|
|
current.splice(index, 1)
|
|
await this.document.update({ "system.traits": current })
|
|
}
|
|
}
|