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
This commit is contained in:
Oliver-Akins 2024-12-28 23:19:51 -07:00
parent 514a643b32
commit f1d0d781d8
3 changed files with 37 additions and 2 deletions

View file

@ -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,

View file

@ -41,5 +41,8 @@ Hooks.once(`init`, () => {
// #endregion
// #endregion
// #region Token Attrs
CONFIG.Actor.trackableAttributes.hero = HeroData.trackableAttributes;
Handlebars.registerHelper(helpers);
});

View file

@ -0,0 +1,3 @@
export function sumReduce(sum, val) {
return sum + val;
};