From dff8a46ebbe02d6459530da246b9740bcfca064d Mon Sep 17 00:00:00 2001 From: Eldritch-Oliver Date: Tue, 16 Sep 2025 00:45:48 -0600 Subject: [PATCH] Make the size settings apply to the application when it is constructed --- module/apps/PlayerSheet.mjs | 65 ++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 9 deletions(-) diff --git a/module/apps/PlayerSheet.mjs b/module/apps/PlayerSheet.mjs index eecd4ff..54c7d44 100644 --- a/module/apps/PlayerSheet.mjs +++ b/module/apps/PlayerSheet.mjs @@ -1,9 +1,11 @@ import { __ID__, filePath } from "../consts.mjs"; import { AttributeManager } from "./AttributeManager.mjs"; import { attributeSorter } from "../utils/attributeSort.mjs"; +import { ResizeControlManager } from "./ResizeControlManager.mjs"; const { HandlebarsApplicationMixin } = foundry.applications.api; const { ActorSheetV2 } = foundry.applications.sheets; +const { getProperty } = foundry.utils; export class PlayerSheet extends HandlebarsApplicationMixin(ActorSheetV2) { @@ -26,6 +28,7 @@ export class PlayerSheet extends HandlebarsApplicationMixin(ActorSheetV2) { }, actions: { manageAttributes: this.#manageAttributes, + sizeSettings: this.#configureSizeSettings, }, }; @@ -37,6 +40,31 @@ export class PlayerSheet extends HandlebarsApplicationMixin(ActorSheetV2) { // #endregion Options // #region Lifecycle + constructor(options) { + if (options.document) { + const sizing = getProperty(options.document, `flags.${__ID__}.PlayerSheet.size`) ?? {}; + + options.window ??= {}; + switch (sizing.resizable) { + case `false`: + options.window.resizable ??= false; + break; + case `true`: + options.window.resizable ??= true; + break; + }; + + options.position ??= {}; + if (sizing.width) { + options.position.width ??= sizing.width; + } + if (sizing.height) { + options.position.height ??= sizing.height; + } + }; + super(options); + }; + _getHeaderControls() { const controls = super._getHeaderControls(); @@ -51,13 +79,22 @@ export class PlayerSheet extends HandlebarsApplicationMixin(ActorSheetV2) { return isGM || (allowPlayerEdits && editable); }, }); + controls.push({ + icon: `fa-solid fa-crop-simple`, + label: `Configure Size`, + action: `sizeSettings`, + visible: () => { + const isGM = game.user.isGM; + return isGM; + }, + }); return controls; }; async close() { - this.attributeManager?.close(); - this.attributeManager = null; + this.#attributeManager?.close(); + this.#attributeManager = null; return super.close(); }; // #endregion Lifecycle @@ -109,16 +146,26 @@ export class PlayerSheet extends HandlebarsApplicationMixin(ActorSheetV2) { // #endregion Data Prep // #region Actions - attributeManager = null; - + #attributeManager = null; /** @this {PlayerSheet} */ static async #manageAttributes() { - this.attributeManager ??= new AttributeManager({ document: this.actor }); - if (this.attributeManager.rendered) { - await this.attributeManager.bringToFront(); + this.#attributeManager ??= new AttributeManager({ document: this.actor }); + if (this.#attributeManager.rendered) { + await this.#attributeManager.bringToFront(); } else { - await this.attributeManager.render({ force: true }); - } + await this.#attributeManager.render({ force: true }); + }; + }; + + #sizeSettings = null; + /** @this {PlayerSheet} */ + static async #configureSizeSettings() { + this.#sizeSettings ??= new ResizeControlManager({ document: this.actor }); + if (this.#sizeSettings.rendered) { + await this.#sizeSettings.bringToFront(); + } else { + await this.#sizeSettings.render({ force: true }); + }; }; // #endregion Actions };