Make a helper function for token bars that only store the current value in the DB

This commit is contained in:
Oliver-Akins 2025-02-22 18:38:57 -07:00
parent de6ded9a39
commit 14b6f85137
2 changed files with 13 additions and 8 deletions

View file

@ -1,3 +1,4 @@
import { derivedMaximumBar } from "../helpers.mjs";
import { gameTerms } from "../../gameTerms.mjs"; import { gameTerms } from "../../gameTerms.mjs";
import { sumReduce } from "../../utils/sumReduce.mjs"; import { sumReduce } from "../../utils/sumReduce.mjs";
@ -59,14 +60,7 @@ export class HeroData extends foundry.abstract.TypeDataModel {
nullable: false, nullable: false,
}), }),
}), }),
guts: new fields.SchemaField({ guts: derivedMaximumBar(0, 5),
value: new fields.NumberField({
min: 0,
initial: 5,
integer: true,
nullable: false,
}),
}),
coin: new fields.SchemaField({ coin: new fields.SchemaField({
gold: new fields.NumberField({ gold: new fields.NumberField({
initial: 5, initial: 5,

View file

@ -19,6 +19,17 @@ export function barAttribute(min, initial, max = undefined) {
}); });
}; };
export function derivedMaximumBar(min, initial) {
return new fields.SchemaField({
value: new fields.NumberField({
min,
initial,
integer: true,
nullable: false,
}),
});
};
export function optionalInteger({min, initial = null, max} = {}) { export function optionalInteger({min, initial = null, max} = {}) {
return new fields.NumberField({ return new fields.NumberField({
min, min,