Merge pull request 'Add settings for sheet sizing global defaults' (#17) from feature/default-sheet-sizing into main
Reviewed-on: #17
This commit is contained in:
commit
587a54c5bd
4 changed files with 85 additions and 9 deletions
|
|
@ -9,6 +9,23 @@
|
||||||
"canPlayersManageAttributes": {
|
"canPlayersManageAttributes": {
|
||||||
"name": "Players Can Manage Attributes",
|
"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"
|
"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": {
|
"sheet-names": {
|
||||||
|
|
|
||||||
|
|
@ -42,23 +42,36 @@ export class PlayerSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
|
||||||
// #region Lifecycle
|
// #region Lifecycle
|
||||||
_initializeApplicationOptions(options) {
|
_initializeApplicationOptions(options) {
|
||||||
const sizing = getProperty(options.document, `flags.${__ID__}.PlayerSheet.size`) ?? {};
|
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 ??= {};
|
options.window ??= {};
|
||||||
switch (sizing.resizable) {
|
if (sizing.resizable !== ``) {
|
||||||
case `false`:
|
options.window.resizable ??= sizing.resizable === `true`;
|
||||||
options.window.resizable ??= false;
|
}
|
||||||
break;
|
else if (setting.resizable !== ``) {
|
||||||
case `true`:
|
options.window.resizable ??= setting.resizable === `true`;
|
||||||
options.window.resizable ??= true;
|
|
||||||
break;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
options.position ??= {};
|
options.position ??= {};
|
||||||
|
|
||||||
|
// Set width
|
||||||
if (sizing.width) {
|
if (sizing.width) {
|
||||||
options.position.width ??= sizing.width;
|
options.position.width ??= sizing.width;
|
||||||
|
}
|
||||||
|
else if (setting.width) {
|
||||||
|
options.position.width ??= setting.width;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Set height
|
||||||
if (sizing.height) {
|
if (sizing.height) {
|
||||||
options.position.height ??= sizing.height;
|
options.position.height ??= sizing.height;
|
||||||
|
}
|
||||||
|
else if (setting.height) {
|
||||||
|
options.position.height ??= setting.height;
|
||||||
};
|
};
|
||||||
|
|
||||||
return super._initializeApplicationOptions(options);
|
return super._initializeApplicationOptions(options);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import { __ID__ } from "../consts.mjs";
|
import { __ID__ } from "../consts.mjs";
|
||||||
|
|
||||||
|
const { NumberField, StringField } = foundry.data.fields;
|
||||||
|
|
||||||
export function registerWorldSettings() {
|
export function registerWorldSettings() {
|
||||||
game.settings.register(__ID__, `canPlayersManageAttributes`, {
|
game.settings.register(__ID__, `canPlayersManageAttributes`, {
|
||||||
name: `taf.settings.canPlayersManageAttributes.name`,
|
name: `taf.settings.canPlayersManageAttributes.name`,
|
||||||
|
|
@ -9,4 +11,42 @@ export function registerWorldSettings() {
|
||||||
default: false,
|
default: false,
|
||||||
scope: `world`,
|
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";
|
import { PlayerSheet } from "../apps/PlayerSheet.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -21,12 +22,17 @@ export function getDefaultSizing() {
|
||||||
resizable: undefined,
|
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
|
// Defaults from the sheet class itself
|
||||||
sizing.height ||= PlayerSheet.DEFAULT_OPTIONS.position.height;
|
sizing.height ||= PlayerSheet.DEFAULT_OPTIONS.position.height;
|
||||||
sizing.width ||= PlayerSheet.DEFAULT_OPTIONS.position.width;
|
sizing.width ||= PlayerSheet.DEFAULT_OPTIONS.position.width;
|
||||||
sizing.resizable ||= PlayerSheet.DEFAULT_OPTIONS.window.resizable;
|
sizing.resizable ??= PlayerSheet.DEFAULT_OPTIONS.window.resizable;
|
||||||
|
|
||||||
return sizing;
|
return sizing;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue