Add the startSidebarExpanded setting (closes #2)

This commit is contained in:
Eldritch-Oliver 2025-11-22 15:46:30 -07:00
parent d856f7b1c8
commit 529aa72bdf
10 changed files with 71 additions and 5 deletions

View file

@ -4,7 +4,7 @@
"foundry": true "foundry": true
}, },
"search.exclude": { "search.exclude": {
"foundry": true "foundry": false
}, },
"html.customData": [ "html.customData": [
"./.vscode/foundry.html-data.json" "./.vscode/foundry.html-data.json"

View file

@ -75,7 +75,7 @@ export default [
"@stylistic/eol-last": `warn`, "@stylistic/eol-last": `warn`,
"@stylistic/operator-linebreak": [`warn`, `before`], "@stylistic/operator-linebreak": [`warn`, `before`],
"@stylistic/indent": [`warn`, `tab`], "@stylistic/indent": [`warn`, `tab`],
"@stylistic/brace-style": [`warn`, `stroustrup`, { "allowSingleLine": true }], "@stylistic/brace-style": [`off`],
"@stylistic/quotes": [`warn`, `backtick`, { "avoidEscape": true }], "@stylistic/quotes": [`warn`, `backtick`, { "avoidEscape": true }],
"@stylistic/comma-dangle": [`warn`, { arrays: `always-multiline`, objects: `always-multiline`, imports: `always-multiline`, exports: `always-multiline`, functions: `always-multiline` }], "@stylistic/comma-dangle": [`warn`, { arrays: `always-multiline`, objects: `always-multiline`, imports: `always-multiline`, exports: `always-multiline`, functions: `always-multiline` }],
"@stylistic/comma-style": [`warn`, `last`], "@stylistic/comma-style": [`warn`, `last`],

View file

@ -1,3 +1,10 @@
{ {
"OFT": {} "OFT": {
"setting": {
"startSidebarExpanded": {
"name": "Start Sidebar Expanded",
"hint": "(v13+) Starts the right-hand sidebar expanded when logging in."
}
}
}
} }

View file

@ -1,4 +1,4 @@
export const __ID = `otf`; export const __ID = `oft`;
export function inDev() { export function inDev() {
return game.modules.get(__ID).flags.inDev; return game.modules.get(__ID).flags.inDev;

8
module/hooks/init.mjs Normal file
View file

@ -0,0 +1,8 @@
import { __ID } from "../consts.mjs";
import { startSidebarExpanded } from "../settings/startSidebarExpanded.mjs";
Hooks.once(`init`, () => {
console.log(`${__ID} | Initializing`);
startSidebarExpanded.register();
});

View file

@ -1,5 +1,5 @@
import { __ID } from "../consts.mjs"; import { __ID } from "../consts.mjs";
Hooks.on(`ready`, () => { Hooks.once(`ready`, () => {
console.log(`${__ID} | Ready`); console.log(`${__ID} | Ready`);
}); });

View file

@ -0,0 +1,9 @@
import { startSidebarExpanded } from "../settings/startSidebarExpanded.mjs";
Hooks.once(`renderSidebar`, (app, _element, _context, _options) => {
// MARK: Sidebar Expansion
if (startSidebarExpanded.value()) {
app.toggleExpanded(true);
}
});

View file

@ -1,2 +1,4 @@
// Hooks // Hooks
import "./hooks/init.mjs";
import "./hooks/ready.mjs"; import "./hooks/ready.mjs";
import "./hooks/renderSidebar.mjs";

View file

@ -0,0 +1,22 @@
import { __ID } from "../consts.mjs";
const key = `startSidebarExpanded`;
const config = {
name: `OFT.setting.${key}.name`,
hint: `OFT.setting.${key}.hint`,
scope: `user`,
type: Boolean,
default: true,
config: true,
requiresReload: false,
};
export const startSidebarExpanded = {
value() {
return game.settings.get(__ID, key);
},
register() {
game.settings.register(__ID, key, config);
},
};

View file

@ -0,0 +1,18 @@
export function isBetweenVersions(min, target, max) {
if (min) {
const isOlderThanMin = foundry.utils.isNewerVersion(min, target);
if (isOlderThanMin) {
return false;
};
};
if (max) {
const isNewerThanMax = foundry.utils.isNewerVersion(target, max);
if (isNewerThanMax) {
return false;
};
};
return true;
};