Add settings for sheet sizing global defaults
This commit is contained in:
parent
42697ea9d2
commit
b417e827df
4 changed files with 85 additions and 9 deletions
|
|
@ -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": {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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`,
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue