feat: complete DS4 ApplicationV2 migration with item and effect sheets
Port remaining DS4ItemSheet and DS4ActiveEffectConfig to ApplicationV2.
This commit is contained in:
parent
4821eba0a9
commit
c363295e0f
3 changed files with 49 additions and 18 deletions
|
@ -2,31 +2,55 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DS4 Active Effect Configuration Sheet
|
||||||
|
*/
|
||||||
export class DS4ActiveEffectConfig extends foundry.applications.sheets.ActiveEffectConfig {
|
export class DS4ActiveEffectConfig extends foundry.applications.sheets.ActiveEffectConfig {
|
||||||
|
static DEFAULT_OPTIONS = {
|
||||||
|
...super.DEFAULT_OPTIONS,
|
||||||
|
classes: ["sheet", "ds4-active-effect-config"],
|
||||||
|
};
|
||||||
|
|
||||||
/** @override */
|
/** @override */
|
||||||
static get defaultOptions() {
|
get template() {
|
||||||
return foundry.utils.mergeObject(super.defaultOptions, {
|
return "systems/ds4/templates/sheets/active-effect/active-effect-config.hbs";
|
||||||
template: "systems/ds4/templates/sheets/active-effect/active-effect-config.hbs",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @override */
|
||||||
* @override
|
async _prepareContext(options) {
|
||||||
* @param {JQuery} html
|
const context = await super._prepareContext(options);
|
||||||
*/
|
|
||||||
activateListeners(html) {
|
// Add DS4-specific context
|
||||||
super.activateListeners(html);
|
context.itemEffectConfig = this.document.flags?.ds4?.itemEffectConfig || {};
|
||||||
const checkbox = html[0]?.querySelector('input[name="flags.ds4.itemEffectConfig.applyToItems"]');
|
context.applyToItems = context.itemEffectConfig.applyToItems || false;
|
||||||
checkbox?.addEventListener("change", () => this.#toggleItemEffectConfig(checkbox.checked));
|
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @override */
|
||||||
|
async _onRender(context, options) {
|
||||||
|
await super._onRender(context, options);
|
||||||
|
|
||||||
|
// Set up initial visibility of item effect config section
|
||||||
|
const applyToItems = this.document.flags?.ds4?.itemEffectConfig?.applyToItems || false;
|
||||||
|
this._toggleItemEffectConfigVisibility(applyToItems);
|
||||||
|
|
||||||
|
// Add event listener for the checkbox
|
||||||
|
const checkbox = this.element.querySelector('input[name="flags.ds4.itemEffectConfig.applyToItems"]');
|
||||||
|
if (checkbox) {
|
||||||
|
checkbox.addEventListener("change", (event) => {
|
||||||
|
this._toggleItemEffectConfigVisibility(event.target.checked);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggle the visibility of the item effect config section
|
* Toggle the visibility of the item effect config section
|
||||||
* @param {boolean} active The target state
|
* @param {boolean} active - The target state
|
||||||
*/
|
*/
|
||||||
#toggleItemEffectConfig(active) {
|
_toggleItemEffectConfigVisibility(active) {
|
||||||
const elements = this.element[0]?.querySelectorAll(".ds4-item-effect-config");
|
const elements = this.element.querySelectorAll(".ds4-item-effect-config");
|
||||||
elements?.forEach((element) => {
|
elements.forEach((element) => {
|
||||||
if (active) {
|
if (active) {
|
||||||
element.classList.remove("ds4-hidden");
|
element.classList.remove("ds4-hidden");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -119,6 +119,8 @@ export class DS4ActorSheet extends foundry.applications.api.DocumentSheetV2 {
|
||||||
if (this.document.effects && this.document.effects.size > 0) {
|
if (this.document.effects && this.document.effects.size > 0) {
|
||||||
for (const effect of this.document.effects) {
|
for (const effect of this.document.effects) {
|
||||||
const enrichedEffect = effect.toObject();
|
const enrichedEffect = effect.toObject();
|
||||||
|
enrichedEffect.id = effect.id;
|
||||||
|
enrichedEffect.uuid = effect.uuid;
|
||||||
enrichedEffect.sourceName = effect.sourceName;
|
enrichedEffect.sourceName = effect.sourceName;
|
||||||
context.enrichedEffects.push(enrichedEffect);
|
context.enrichedEffects.push(enrichedEffect);
|
||||||
}
|
}
|
||||||
|
@ -380,7 +382,7 @@ export class DS4ActorSheet extends foundry.applications.api.DocumentSheetV2 {
|
||||||
*/
|
*/
|
||||||
async _onCreateEffect() {
|
async _onCreateEffect() {
|
||||||
const effectData = {
|
const effectData = {
|
||||||
name: game.i18n.localize("DS4.EffectNew"),
|
name: game.i18n.localize("DS4.NewEffectName"),
|
||||||
icon: "icons/svg/aura.svg",
|
icon: "icons/svg/aura.svg",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,11 @@ export class DS4ItemSheet extends foundry.applications.sheets.ItemSheetV2 {
|
||||||
actions: {
|
actions: {
|
||||||
controlEffect: DS4ItemSheet.prototype._onControlEffect,
|
controlEffect: DS4ItemSheet.prototype._onControlEffect,
|
||||||
createEffect: DS4ItemSheet.prototype._onCreateEffect,
|
createEffect: DS4ItemSheet.prototype._onCreateEffect,
|
||||||
|
createeffect: DS4ItemSheet.prototype._onCreateEffect,
|
||||||
editEffect: DS4ItemSheet.prototype._onEditEffect,
|
editEffect: DS4ItemSheet.prototype._onEditEffect,
|
||||||
|
editeffect: DS4ItemSheet.prototype._onEditEffect,
|
||||||
deleteEffect: DS4ItemSheet.prototype._onDeleteEffect,
|
deleteEffect: DS4ItemSheet.prototype._onDeleteEffect,
|
||||||
|
deleteeffect: DS4ItemSheet.prototype._onDeleteEffect,
|
||||||
changeTab: DS4ItemSheet.prototype._onChangeTab,
|
changeTab: DS4ItemSheet.prototype._onChangeTab,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -85,6 +88,8 @@ export class DS4ItemSheet extends foundry.applications.sheets.ItemSheetV2 {
|
||||||
if (this.item.effects && this.item.effects.size > 0) {
|
if (this.item.effects && this.item.effects.size > 0) {
|
||||||
for (const effect of this.item.effects) {
|
for (const effect of this.item.effects) {
|
||||||
const enrichedEffect = effect.toObject();
|
const enrichedEffect = effect.toObject();
|
||||||
|
enrichedEffect.id = effect.id;
|
||||||
|
enrichedEffect.uuid = effect.uuid;
|
||||||
enrichedEffect.sourceName = effect.sourceName;
|
enrichedEffect.sourceName = effect.sourceName;
|
||||||
context.enrichedEffects.push(enrichedEffect);
|
context.enrichedEffects.push(enrichedEffect);
|
||||||
}
|
}
|
||||||
|
@ -153,7 +158,7 @@ export class DS4ItemSheet extends foundry.applications.sheets.ItemSheetV2 {
|
||||||
*/
|
*/
|
||||||
async _onCreateEffect() {
|
async _onCreateEffect() {
|
||||||
const effectData = {
|
const effectData = {
|
||||||
name: game.i18n.localize("DS4.EffectNew"),
|
name: game.i18n.localize("DS4.NewEffectName"),
|
||||||
icon: "icons/svg/aura.svg",
|
icon: "icons/svg/aura.svg",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue