From f1d0d781d89bc024d19706602475c1f9e8a3b9e3 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Sat, 28 Dec 2024 23:19:51 -0700 Subject: [PATCH] Guts Data Un-saving Don't save guts max to database since we don't need it, but make sure that it still shows up as a token bar that can be chosen rather than a single value --- module/data/Actor/Hero.mjs | 33 +++++++++++++++++++++++++++++++-- module/hooks/init.mjs | 3 +++ module/utils/sumReduce.mjs | 3 +++ 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 module/utils/sumReduce.mjs diff --git a/module/data/Actor/Hero.mjs b/module/data/Actor/Hero.mjs index 723c512..b41a1d4 100644 --- a/module/data/Actor/Hero.mjs +++ b/module/data/Actor/Hero.mjs @@ -1,9 +1,27 @@ -import { barAttribute } from "../helpers.mjs"; import { gameTerms } from "../../gameTerms.mjs"; +import { sumReduce } from "../../utils/sumReduce.mjs"; const { fields } = foundry.data; export class HeroData extends foundry.abstract.TypeDataModel { + + static get trackableAttributes() { + return { + bar: [ + `guts`, + ], + value: [ + `ability.grit`, + `ability.gait`, + `ability.grip`, + `ability.glim`, + `level.glory`, + `level.step`, + `level.rank`, + ], + }; + }; + static defineSchema() { return { ability: new fields.SchemaField({ @@ -36,7 +54,14 @@ export class HeroData extends foundry.abstract.TypeDataModel { nullable: false, }), }), - guts: barAttribute(0, 5), + guts: new fields.SchemaField({ + value: new fields.NumberField({ + min: 0, + initial: 5, + integer: true, + nullable: false, + }), + }), coin: new fields.SchemaField({ gold: new fields.NumberField({ initial: 5, @@ -97,6 +122,8 @@ export class HeroData extends foundry.abstract.TypeDataModel { prepareBaseData() { super.prepareBaseData(); + this.guts.max = 0; + // The limitations imposed on things like inventory spaces and equipped // weapon count this.limit = { @@ -108,6 +135,8 @@ export class HeroData extends foundry.abstract.TypeDataModel { prepareDerivedData() { super.prepareDerivedData(); + this.guts.max += Object.values(this.ability).reduce(sumReduce); + // Movement speeds this.speed = { move: this.ability.gait + 3, diff --git a/module/hooks/init.mjs b/module/hooks/init.mjs index e20931a..e4ed9fa 100644 --- a/module/hooks/init.mjs +++ b/module/hooks/init.mjs @@ -41,5 +41,8 @@ Hooks.once(`init`, () => { // #endregion // #endregion + // #region Token Attrs + CONFIG.Actor.trackableAttributes.hero = HeroData.trackableAttributes; + Handlebars.registerHelper(helpers); }); diff --git a/module/utils/sumReduce.mjs b/module/utils/sumReduce.mjs new file mode 100644 index 0000000..d174ffa --- /dev/null +++ b/module/utils/sumReduce.mjs @@ -0,0 +1,3 @@ +export function sumReduce(sum, val) { + return sum + val; +};