Attribute Item Subtype #76

Merged
Oliver merged 50 commits from feature/attribute-items into main 2026-04-27 02:12:56 +00:00
Showing only changes of commit 05dcb9afbd - Show all commits

View file

@ -1,6 +1,7 @@
import { isValidID, toID } from "../../utils/toID.mjs";
import { clamp } from "../../utils/clamp.mjs";
const { hasProperty } = foundry.utils;
const { getProperty, hasProperty, setProperty } = foundry.utils;
export class AttributeItemData extends foundry.abstract.TypeDataModel {
// #region Schema
@ -80,6 +81,17 @@ export class AttributeItemData extends foundry.abstract.TypeDataModel {
delete data.system?.key;
};
// Prevent value going out of the bounds of min/max
if (hasProperty(data, `system.value`)) {
const value = getProperty(data, `system.value`);
const max = getProperty(data, `system.max`) ?? this.max;
let min = getProperty(data, `system.min`) ?? this.min;
if (max != null) { min ??= 0; };
setProperty(data, `system.value`, clamp(min, value, max));
};
return super._preUpdate(data, options, user);
};
// #endregion Lifecycle