From e1f173dde76f4236fdb57e1b9c47810208b6a970 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Sun, 29 Jun 2025 15:56:03 -0600 Subject: [PATCH] Add ability to let players who own a document edit the attributes for it via the UI --- langs/en-ca.json | 6 ++++++ module/apps/PlayerSheet.mjs | 27 +++++++++++++++++---------- module/hooks/init.mjs | 5 +++++ module/settings/world.mjs | 12 ++++++++++++ 4 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 module/settings/world.mjs diff --git a/langs/en-ca.json b/langs/en-ca.json index 2a7d128..99de0b3 100644 --- a/langs/en-ca.json +++ b/langs/en-ca.json @@ -5,6 +5,12 @@ } }, "taf": { + "settings": { + "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" + } + }, "sheet-names": { "PlayerSheet": "Player Sheet" } diff --git a/module/apps/PlayerSheet.mjs b/module/apps/PlayerSheet.mjs index 697d95a..dfcef25 100644 --- a/module/apps/PlayerSheet.mjs +++ b/module/apps/PlayerSheet.mjs @@ -18,16 +18,6 @@ export class PlayerSheet extends HandlebarsApplicationMixin(ActorSheetV2) { }, window: { resizable: true, - controls: [ - { - icon: `fa-solid fa-at`, - label: `Manage Attributes`, - action: `manageAttributes`, - visible: () => { - return game.user.isGM; - }, - }, - ], }, form: { submitOnChange: true, @@ -46,6 +36,23 @@ export class PlayerSheet extends HandlebarsApplicationMixin(ActorSheetV2) { // #endregion Options // #region Lifecycle + _getHeaderControls() { + const controls = super._getHeaderControls(); + + controls.push({ + icon: `fa-solid fa-at`, + label: `Manage Attributes`, + action: `manageAttributes`, + visible: () => { + const isGM = game.user.isGM; + const allowPlayerEdits = game.settings.get(__ID__, `canPlayersManageAttributes`); + const editable = this.isEditable; + return isGM || (allowPlayerEdits && editable); + }, + }); + + return controls; + }; // #endregion Lifecycle // #region Data Prep diff --git a/module/hooks/init.mjs b/module/hooks/init.mjs index cce212b..442d916 100644 --- a/module/hooks/init.mjs +++ b/module/hooks/init.mjs @@ -8,6 +8,9 @@ import { PlayerData } from "../data/Player.mjs"; import { TAFActor } from "../documents/Actor.mjs"; import { TAFTokenDocument } from "../documents/Token.mjs"; +// Settings +import { registerWorldSettings } from "../settings/world.mjs"; + // Utils import { __ID__ } from "../consts.mjs"; import { Logger } from "../utils/Logger.mjs"; @@ -28,4 +31,6 @@ Hooks.on(`init`, () => { label: `taf.sheet-names.PlayerSheet`, }, ); + + registerWorldSettings(); }); diff --git a/module/settings/world.mjs b/module/settings/world.mjs new file mode 100644 index 0000000..78462d7 --- /dev/null +++ b/module/settings/world.mjs @@ -0,0 +1,12 @@ +import { __ID__ } from "../consts.mjs"; + +export function registerWorldSettings() { + game.settings.register(__ID__, `canPlayersManageAttributes`, { + name: `taf.settings.canPlayersManageAttributes.name`, + hint: `taf.settings.canPlayersManageAttributes.hint`, + config: true, + type: Boolean, + default: false, + scope: `world`, + }); +};