71 lines
2.5 KiB
JavaScript
71 lines
2.5 KiB
JavaScript
import PrismRPGItemSheet from "./base-item-sheet.mjs"
|
|
|
|
export default class PrismRPGEquipmentSheet extends PrismRPGItemSheet {
|
|
/** @override */
|
|
static DEFAULT_OPTIONS = {
|
|
classes: ["equipment"],
|
|
position: {
|
|
width: 600,
|
|
},
|
|
window: {
|
|
contentClasses: ["equipment-content"],
|
|
},
|
|
}
|
|
|
|
/** @override */
|
|
static PARTS = {
|
|
main: {
|
|
template: "systems/fvtt-prism-rpg/templates/equipment.hbs",
|
|
},
|
|
}
|
|
|
|
/** @override */
|
|
async _prepareContext() {
|
|
const context = await super._prepareContext()
|
|
context.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.description, { async: true })
|
|
|
|
// Enrich passive description if equipment is a kit
|
|
if (this.document.system.isKit && this.document.system.passiveDescription) {
|
|
context.enrichedPassiveDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.passiveDescription, { async: true })
|
|
}
|
|
|
|
// Enrich descriptions for all special activations
|
|
context.enrichedSpecialActivations = await Promise.all(
|
|
this.document.system.specialActivations.map(async (activation) => ({
|
|
...activation,
|
|
enrichedDescription: await foundry.applications.ux.TextEditor.implementation.enrichHTML(activation.description, { async: true })
|
|
}))
|
|
)
|
|
|
|
return context
|
|
}
|
|
|
|
/** @override */
|
|
_onRender(context, options) {
|
|
super._onRender(context, options)
|
|
|
|
// Add event listeners for special activation management
|
|
this.element.querySelectorAll('[data-action="add-special-activation"]').forEach(el => {
|
|
el.addEventListener("click", this._onAddSpecialActivation.bind(this))
|
|
})
|
|
|
|
this.element.querySelectorAll('[data-action="delete-special-activation"]').forEach(el => {
|
|
el.addEventListener("click", this._onDeleteSpecialActivation.bind(this))
|
|
})
|
|
}
|
|
|
|
async _onAddSpecialActivation(event) {
|
|
event.preventDefault()
|
|
const specialActivations = [...this.document.system.specialActivations]
|
|
specialActivations.push({ name: "", description: "" })
|
|
await this.document.update({ "system.specialActivations": specialActivations })
|
|
}
|
|
|
|
async _onDeleteSpecialActivation(event) {
|
|
event.preventDefault()
|
|
const index = parseInt(event.currentTarget.closest("[data-activation-index]").dataset.activationIndex)
|
|
const specialActivations = this.document.system.specialActivations.filter((_, i) => i !== index)
|
|
await this.document.update({ "system.specialActivations": specialActivations })
|
|
}
|
|
}
|