From 504a91bb9c5e3dc0ce24484b8d8815f3875be4e5 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 2 May 2026 20:51:05 -0600 Subject: [PATCH] Add way to set default attributes now that we no longer have the AttributeManager (closes #83) --- langs/en-ca.json | 1 + module/apps/PlayerSheet.mjs | 18 ++++++++++++++++++ module/documents/Actor.mjs | 26 ++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/langs/en-ca.json b/langs/en-ca.json index ce47b7a..149bb72 100644 --- a/langs/en-ca.json +++ b/langs/en-ca.json @@ -91,6 +91,7 @@ "invalid-input-type": "Invalid input type provided: {type}" }, "PlayerSheet": { + "save-attributes-as-defaults": "Save Attributes as Defaults", "create-item": "Create Embedded Item", "current-value": "Current value", "max-value": "Maximum value", diff --git a/module/apps/PlayerSheet.mjs b/module/apps/PlayerSheet.mjs index 1565f92..74830d6 100644 --- a/module/apps/PlayerSheet.mjs +++ b/module/apps/PlayerSheet.mjs @@ -4,6 +4,7 @@ import { config } from "../config.mjs"; import { Logger } from "../utils/Logger.mjs"; import { TAFDocumentSheetConfig } from "./TAFDocumentSheetConfig.mjs"; import { TAFDocumentSheetMixin } from "./mixins/TAFDocumentSheetMixin.mjs"; +import { TAFActor } from "../documents/Actor.mjs"; const { HandlebarsApplicationMixin } = foundry.applications.api; const { ActorSheetV2 } = foundry.applications.sheets; @@ -38,6 +39,7 @@ export class PlayerSheet extends configureSheet: this.#configureSheet, toggleExpand: this.#toggleExpand, executeTrigger: this.#executeTrigger, + saveDefaultAttrs: this.#saveDefaultAttrs, }, }; @@ -193,6 +195,12 @@ export class PlayerSheet extends const controls = super._getHeaderControls(); controls.push( + { + icon: `fa-solid fa-globe`, + label: `taf.Apps.PlayerSheet.save-attributes-as-defaults`, + action: `saveDefaultAttrs`, + visible: () => game.user.isGM, + }, { icon: `fa-solid fa-suitcase`, label: `taf.Apps.PlayerSheet.create-item`, @@ -475,5 +483,15 @@ export class PlayerSheet extends const item = await fromUuid(itemUuid); await item?.system.execute?.(); }; + + /** + * Saves the Actor's current attribute items into the world setting for newly + * created Actors to have the same attribute list. + * + * @this {PlayerSheet} + */ + static async #saveDefaultAttrs() { + TAFActor.setDefaultAttributes(this.actor); + }; // #endregion Actions }; diff --git a/module/documents/Actor.mjs b/module/documents/Actor.mjs index e99108e..1bfa0ea 100644 --- a/module/documents/Actor.mjs +++ b/module/documents/Actor.mjs @@ -155,4 +155,30 @@ export class TAFActor extends Actor { }; }; // #endregion Data Migration + + // #region Static API + /** + * Sets the default attributes that are created when a new Actor is created, + * this uses all of the existing values that are a part of the items, it does + * not prompt for default values. + */ + static async setDefaultAttributes(actor) { + if (!game.user.isGM) { return }; + const minifiedData = []; + + const attrs = actor.itemTypes.attribute ?? []; + for (const attr of attrs) { + const raw = attr.toObject(); + minifiedData.push({ + img: raw.img, // doesn't really matter but ¯\_(ツ)_/¯ + name: raw.name, + type: raw.type, + system: raw.system, + }); + }; + + game.settings.set(__ID__, `actorDefaultAttributes`, minifiedData); + ui.notifications.success(_loc(`taf.notifs.success.saved-default-attributes`)); + }; + // #endregion Static API };