diff --git a/langs/en-ca.json b/langs/en-ca.json index 1136454..7813c4b 100644 --- a/langs/en-ca.json +++ b/langs/en-ca.json @@ -9,6 +9,23 @@ "canPlayersManageAttributes": { "name": "Players Can Manage Attributes", "hint": "This allows players who have edit access to a document to be able to edit what attributes those characters have via the attribute editor" + }, + "sheetDefaultHeight": { + "name": "Default Actor Sheet Height", + "hint": "The height that all actor sheets will open at unless overwridden for that sheet specifically. This setting will not affect already opened sheets." + }, + "sheetDefaultWidth": { + "name": "Default Actor Sheet Width", + "hint": "The width that all actor sheets will open at unless overwridden for that sheet specifically. This setting will not affect already opened sheets." + }, + "sheetDefaultResizable": { + "name": "Default Actor Sheet Resizable", + "hint": "Whether or not actor sheets will be able to be resized by default, unless overridden for that specific sheet. This setting will not affect already opened sheets.", + "choices": { + "default": "No Global Default", + "false": "Not Resizable", + "true": "Resizable" + } } }, "sheet-names": { diff --git a/module/apps/PlayerSheet.mjs b/module/apps/PlayerSheet.mjs index 257182a..9f9b0ad 100644 --- a/module/apps/PlayerSheet.mjs +++ b/module/apps/PlayerSheet.mjs @@ -42,23 +42,36 @@ export class PlayerSheet extends HandlebarsApplicationMixin(ActorSheetV2) { // #region Lifecycle _initializeApplicationOptions(options) { const sizing = getProperty(options.document, `flags.${__ID__}.PlayerSheet.size`) ?? {}; + const setting = { + width: game.settings.get(__ID__, `sheetDefaultWidth`), + height: game.settings.get(__ID__, `sheetDefaultHeight`), + resizable: game.settings.get(__ID__, `sheetDefaultResizable`), + }; options.window ??= {}; - switch (sizing.resizable) { - case `false`: - options.window.resizable ??= false; - break; - case `true`: - options.window.resizable ??= true; - break; + if (sizing.resizable !== ``) { + options.window.resizable ??= sizing.resizable === `true`; + } + else if (setting.resizable !== ``) { + options.window.resizable ??= setting.resizable === `true`; }; options.position ??= {}; + + // Set width if (sizing.width) { options.position.width ??= sizing.width; + } + else if (setting.width) { + options.position.width ??= setting.width; }; + + // Set height if (sizing.height) { options.position.height ??= sizing.height; + } + else if (setting.height) { + options.position.height ??= setting.height; }; return super._initializeApplicationOptions(options); diff --git a/module/settings/world.mjs b/module/settings/world.mjs index 78462d7..705ed22 100644 --- a/module/settings/world.mjs +++ b/module/settings/world.mjs @@ -1,5 +1,7 @@ import { __ID__ } from "../consts.mjs"; +const { NumberField, StringField } = foundry.data.fields; + export function registerWorldSettings() { game.settings.register(__ID__, `canPlayersManageAttributes`, { name: `taf.settings.canPlayersManageAttributes.name`, @@ -9,4 +11,42 @@ export function registerWorldSettings() { default: false, scope: `world`, }); + + game.settings.register(__ID__, `sheetDefaultWidth`, { + name: `taf.settings.sheetDefaultWidth.name`, + hint: `taf.settings.sheetDefaultWidth.hint`, + config: true, + type: new NumberField({ + min: 0, + nullable: true, + }), + scope: `world`, + }); + + game.settings.register(__ID__, `sheetDefaultHeight`, { + name: `taf.settings.sheetDefaultHeight.name`, + hint: `taf.settings.sheetDefaultHeight.hint`, + config: true, + type: new NumberField({ + min: 0, + nullable: true, + }), + scope: `world`, + }); + + game.settings.register(__ID__, `sheetDefaultResizable`, { + name: `taf.settings.sheetDefaultResizable.name`, + hint: `taf.settings.sheetDefaultResizable.hint`, + config: true, + type: new StringField({ + blank: true, + initial: ``, + choices: { + "": `taf.settings.sheetDefaultResizable.choices.default`, + "false": `taf.settings.sheetDefaultResizable.choices.false`, + "true": `taf.settings.sheetDefaultResizable.choices.true`, + }, + }), + scope: `world`, + }); }; diff --git a/module/utils/getSizing.mjs b/module/utils/getSizing.mjs index 63e6822..bb5e09a 100644 --- a/module/utils/getSizing.mjs +++ b/module/utils/getSizing.mjs @@ -1,3 +1,4 @@ +import { __ID__ } from "../consts.mjs"; import { PlayerSheet } from "../apps/PlayerSheet.mjs"; /** @@ -21,12 +22,17 @@ export function getDefaultSizing() { resizable: undefined, }; - // TODO: defaults from world settings + sizing.height ||= game.settings.get(__ID__, `sheetDefaultHeight`); + sizing.width ||= game.settings.get(__ID__, `sheetDefaultWidth`); + const globalResizable = game.settings.get(__ID__, `sheetDefaultResizable`); + if (globalResizable !== ``) { + sizing.resizable = globalResizable == `true`; + }; // Defaults from the sheet class itself sizing.height ||= PlayerSheet.DEFAULT_OPTIONS.position.height; sizing.width ||= PlayerSheet.DEFAULT_OPTIONS.position.width; - sizing.resizable ||= PlayerSheet.DEFAULT_OPTIONS.window.resizable; + sizing.resizable ??= PlayerSheet.DEFAULT_OPTIONS.window.resizable; return sizing; };