Add way to set default attributes now that we no longer have the AttributeManager (closes #83)
This commit is contained in:
parent
a9567c200a
commit
504a91bb9c
3 changed files with 45 additions and 0 deletions
|
|
@ -91,6 +91,7 @@
|
||||||
"invalid-input-type": "Invalid input type provided: {type}"
|
"invalid-input-type": "Invalid input type provided: {type}"
|
||||||
},
|
},
|
||||||
"PlayerSheet": {
|
"PlayerSheet": {
|
||||||
|
"save-attributes-as-defaults": "Save Attributes as Defaults",
|
||||||
"create-item": "Create Embedded Item",
|
"create-item": "Create Embedded Item",
|
||||||
"current-value": "Current value",
|
"current-value": "Current value",
|
||||||
"max-value": "Maximum value",
|
"max-value": "Maximum value",
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import { config } from "../config.mjs";
|
||||||
import { Logger } from "../utils/Logger.mjs";
|
import { Logger } from "../utils/Logger.mjs";
|
||||||
import { TAFDocumentSheetConfig } from "./TAFDocumentSheetConfig.mjs";
|
import { TAFDocumentSheetConfig } from "./TAFDocumentSheetConfig.mjs";
|
||||||
import { TAFDocumentSheetMixin } from "./mixins/TAFDocumentSheetMixin.mjs";
|
import { TAFDocumentSheetMixin } from "./mixins/TAFDocumentSheetMixin.mjs";
|
||||||
|
import { TAFActor } from "../documents/Actor.mjs";
|
||||||
|
|
||||||
const { HandlebarsApplicationMixin } = foundry.applications.api;
|
const { HandlebarsApplicationMixin } = foundry.applications.api;
|
||||||
const { ActorSheetV2 } = foundry.applications.sheets;
|
const { ActorSheetV2 } = foundry.applications.sheets;
|
||||||
|
|
@ -38,6 +39,7 @@ export class PlayerSheet extends
|
||||||
configureSheet: this.#configureSheet,
|
configureSheet: this.#configureSheet,
|
||||||
toggleExpand: this.#toggleExpand,
|
toggleExpand: this.#toggleExpand,
|
||||||
executeTrigger: this.#executeTrigger,
|
executeTrigger: this.#executeTrigger,
|
||||||
|
saveDefaultAttrs: this.#saveDefaultAttrs,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -193,6 +195,12 @@ export class PlayerSheet extends
|
||||||
const controls = super._getHeaderControls();
|
const controls = super._getHeaderControls();
|
||||||
|
|
||||||
controls.push(
|
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`,
|
icon: `fa-solid fa-suitcase`,
|
||||||
label: `taf.Apps.PlayerSheet.create-item`,
|
label: `taf.Apps.PlayerSheet.create-item`,
|
||||||
|
|
@ -475,5 +483,15 @@ export class PlayerSheet extends
|
||||||
const item = await fromUuid(itemUuid);
|
const item = await fromUuid(itemUuid);
|
||||||
await item?.system.execute?.();
|
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
|
// #endregion Actions
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -155,4 +155,30 @@ export class TAFActor extends Actor {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
// #endregion Data Migration
|
// #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
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue