Fix issues with companions

This commit is contained in:
Carlos Fernandez 2026-04-25 23:29:29 -04:00
parent 6d09c5504d
commit 899f286def
6 changed files with 25 additions and 13 deletions

View file

@ -80,6 +80,18 @@ class ResourcesField extends fields.TypedObjectField {
value.isReversed = resources[key].reverse;
value.max = typeof resource.max === 'number' ? (value.max ?? resource.max) : null;
}
Object.defineProperty(data, 'clamp', {
value: function () {
for (const key of Object.keys(this)) {
const resource = this[key];
if (typeof resource?.max === 'number') {
resource.value = Math.clamp(resource.value, 0, resource.max);
}
}
},
enumerable: false
});
return data;
}