Files
DeltaGreen/module/utils/active-effect-submit.js
T
Aaron Lutomski bf4ca9bf88 Implemented Active Effects.
Used AE to implement exhaustion, stimulants, and rest.
2026-05-29 21:07:33 -07:00

46 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import DG from "../config.js";
import { getStatisticEffectiveValue } from "./derived-actor-data.js";
/**
* Strip form values that match post–AE prepared numbers so persisted data stays at base values.
* @param {Actor} actor
* @param {object} data Update payload (mutated in place).
* @returns {object}
*/
export function sanitizeActiveEffectBackedUpdateData(actor, data) {
if (!data?.system) return data;
const source = actor._source?.system;
if (!source) return data;
sanitizeStatisticValues(actor, data, source);
return data;
}
/**
* @param {Actor} actor
* @param {object} data
* @param {object} source
*/
function sanitizeStatisticValues(actor, data, source) {
for (const key of DG.statistics) {
const submitted = foundry.utils.getProperty(
data,
`system.statistics.${key}.value`,
);
if (submitted === undefined) continue;
const sourceStat = source.statistics?.[key];
const preparedStat = actor.system.statistics?.[key];
if (!sourceStat || !preparedStat) continue;
const base = sourceStat.value;
const effective = getStatisticEffectiveValue(preparedStat, sourceStat);
if (submitted === effective && submitted !== base) {
foundry.utils.setProperty(data, `system.statistics.${key}.value`, base);
}
}
}