Add effects and tabs
This commit is contained in:
@@ -31,6 +31,9 @@ export default class PrismRPGItemSheet extends HandlebarsApplicationMixin(foundr
|
||||
actions: {
|
||||
toggleSheet: PrismRPGItemSheet.#onToggleSheet,
|
||||
editImage: PrismRPGItemSheet.#onEditImage,
|
||||
"create-effect": PrismRPGItemSheet.#onCreateActiveEffect,
|
||||
"effect-edit": PrismRPGItemSheet.#onEffectEdit,
|
||||
"effect-delete": PrismRPGItemSheet.#onEffectDelete,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -65,6 +68,7 @@ export default class PrismRPGItemSheet extends HandlebarsApplicationMixin(foundr
|
||||
context.system = this.document.system
|
||||
context.source = this.document.toObject()
|
||||
context.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.description, { async: true })
|
||||
context.effectCategories = this.#prepareActiveEffectCategories(this.document.effects)
|
||||
context.isEditMode = this.isEditMode
|
||||
context.isPlayMode = this.isPlayMode
|
||||
context.isEditable = this.isEditable
|
||||
@@ -203,5 +207,99 @@ export default class PrismRPGItemSheet extends HandlebarsApplicationMixin(foundr
|
||||
})
|
||||
return fp.browse()
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare Active Effects organized by category (temporary, passive, inactive).
|
||||
* @param {ActiveEffect[]} effects The raw Active Effects collection
|
||||
* @returns {object} The categorized effects
|
||||
* @private
|
||||
*/
|
||||
#prepareActiveEffectCategories(effects) {
|
||||
// Define effect header categories
|
||||
const categories = {
|
||||
temporary: {
|
||||
type: "temporary",
|
||||
label: game.i18n.localize("PRISMRPG.Label.temporary"),
|
||||
effects: [],
|
||||
},
|
||||
passive: {
|
||||
type: "passive",
|
||||
label: game.i18n.localize("PRISMRPG.Label.passive"),
|
||||
effects: [],
|
||||
},
|
||||
inactive: {
|
||||
type: "inactive",
|
||||
label: game.i18n.localize("PRISMRPG.Label.inactive"),
|
||||
effects: [],
|
||||
},
|
||||
}
|
||||
|
||||
// Iterate over active effects, classifying them into categories
|
||||
for (let e of effects) {
|
||||
const effect = e.toObject()
|
||||
if (e.disabled) categories.inactive.effects.push(effect)
|
||||
else if (e.isTemporary) categories.temporary.effects.push(effect)
|
||||
else categories.passive.effects.push(effect)
|
||||
}
|
||||
return categories
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle creating a new Active Effect on the Item.
|
||||
* @param {Event} event The initiating click event.
|
||||
* @param {HTMLElement} target The current target of the event listener.
|
||||
* @private
|
||||
*/
|
||||
static async #onCreateActiveEffect(event, target) {
|
||||
const effectType = target.dataset.effectType
|
||||
let durationValue = undefined
|
||||
let disabled = false
|
||||
|
||||
if (effectType === "temporary") {
|
||||
durationValue = 10
|
||||
}
|
||||
if (effectType === "inactive") {
|
||||
disabled = true
|
||||
}
|
||||
|
||||
const effectData = {
|
||||
name: game.i18n.format("DOCUMENT.New", { type: game.i18n.localize("DOCUMENT.ActiveEffect") }),
|
||||
img: "icons/svg/aura.svg",
|
||||
origin: this.document.uuid,
|
||||
disabled: disabled,
|
||||
changes: [],
|
||||
duration: durationValue !== undefined ? { rounds: durationValue } : {},
|
||||
flags: {}
|
||||
}
|
||||
await this.document.createEmbeddedDocuments("ActiveEffect", [effectData])
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle editing an Active Effect on the Item.
|
||||
* @param {Event} event The initiating click event.
|
||||
* @param {HTMLElement} target The current target of the event listener.
|
||||
* @private
|
||||
*/
|
||||
static async #onEffectEdit(event, target) {
|
||||
const li = target.closest(".item")
|
||||
const effectId = li.dataset.itemId
|
||||
const effect = this.document.effects.get(effectId)
|
||||
if (!effect) return
|
||||
effect.sheet.render(true)
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle deleting an Active Effect from the Item.
|
||||
* @param {Event} event The initiating click event.
|
||||
* @param {HTMLElement} target The current target of the event listener.
|
||||
* @private
|
||||
*/
|
||||
static async #onEffectDelete(event, target) {
|
||||
const li = target.closest(".item")
|
||||
const effectId = li.dataset.itemId
|
||||
const effect = this.document.effects.get(effectId)
|
||||
if (!effect) return
|
||||
await effect.delete()
|
||||
}
|
||||
// #endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user