Make the size settings apply to the application when it is constructed
This commit is contained in:
parent
c50e88e483
commit
dff8a46ebb
1 changed files with 56 additions and 9 deletions
|
|
@ -1,9 +1,11 @@
|
||||||
import { __ID__, filePath } from "../consts.mjs";
|
import { __ID__, filePath } from "../consts.mjs";
|
||||||
import { AttributeManager } from "./AttributeManager.mjs";
|
import { AttributeManager } from "./AttributeManager.mjs";
|
||||||
import { attributeSorter } from "../utils/attributeSort.mjs";
|
import { attributeSorter } from "../utils/attributeSort.mjs";
|
||||||
|
import { ResizeControlManager } from "./ResizeControlManager.mjs";
|
||||||
|
|
||||||
const { HandlebarsApplicationMixin } = foundry.applications.api;
|
const { HandlebarsApplicationMixin } = foundry.applications.api;
|
||||||
const { ActorSheetV2 } = foundry.applications.sheets;
|
const { ActorSheetV2 } = foundry.applications.sheets;
|
||||||
|
const { getProperty } = foundry.utils;
|
||||||
|
|
||||||
export class PlayerSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
|
export class PlayerSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
|
||||||
|
|
||||||
|
|
@ -26,6 +28,7 @@ export class PlayerSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
manageAttributes: this.#manageAttributes,
|
manageAttributes: this.#manageAttributes,
|
||||||
|
sizeSettings: this.#configureSizeSettings,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -37,6 +40,31 @@ export class PlayerSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
|
||||||
// #endregion Options
|
// #endregion Options
|
||||||
|
|
||||||
// #region Lifecycle
|
// #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() {
|
_getHeaderControls() {
|
||||||
const controls = super._getHeaderControls();
|
const controls = super._getHeaderControls();
|
||||||
|
|
||||||
|
|
@ -51,13 +79,22 @@ export class PlayerSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
|
||||||
return isGM || (allowPlayerEdits && editable);
|
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;
|
return controls;
|
||||||
};
|
};
|
||||||
|
|
||||||
async close() {
|
async close() {
|
||||||
this.attributeManager?.close();
|
this.#attributeManager?.close();
|
||||||
this.attributeManager = null;
|
this.#attributeManager = null;
|
||||||
return super.close();
|
return super.close();
|
||||||
};
|
};
|
||||||
// #endregion Lifecycle
|
// #endregion Lifecycle
|
||||||
|
|
@ -109,16 +146,26 @@ export class PlayerSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
|
||||||
// #endregion Data Prep
|
// #endregion Data Prep
|
||||||
|
|
||||||
// #region Actions
|
// #region Actions
|
||||||
attributeManager = null;
|
#attributeManager = null;
|
||||||
|
|
||||||
/** @this {PlayerSheet} */
|
/** @this {PlayerSheet} */
|
||||||
static async #manageAttributes() {
|
static async #manageAttributes() {
|
||||||
this.attributeManager ??= new AttributeManager({ document: this.actor });
|
this.#attributeManager ??= new AttributeManager({ document: this.actor });
|
||||||
if (this.attributeManager.rendered) {
|
if (this.#attributeManager.rendered) {
|
||||||
await this.attributeManager.bringToFront();
|
await this.#attributeManager.bringToFront();
|
||||||
} else {
|
} 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
|
// #endregion Actions
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue