Work on custom checks
This commit is contained in:
parent
3d999c4cf9
commit
26e22ed3cf
5 changed files with 42 additions and 1 deletions
|
@ -23,6 +23,7 @@ interface DS4ActorPreparedDataDataBase {
|
||||||
combatValues: DS4ActorPreparedDataDataCombatValues;
|
combatValues: DS4ActorPreparedDataDataCombatValues;
|
||||||
rolling: DS4ActorPreparedDataDataRolling;
|
rolling: DS4ActorPreparedDataDataRolling;
|
||||||
checks: DS4ActorPreparedDataDataChecks;
|
checks: DS4ActorPreparedDataDataChecks;
|
||||||
|
customChecks: DS4ActorPreparedDataDataCustomChecks;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DS4ActorPreparedDataDataAttributes {
|
interface DS4ActorPreparedDataDataAttributes {
|
||||||
|
@ -66,6 +67,8 @@ type DS4ActorPreparedDataDataChecks = {
|
||||||
[key in Check]: number;
|
[key in Check]: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type DS4ActorPreparedDataDataCustomChecks = Record<string, number>;
|
||||||
|
|
||||||
// types
|
// types
|
||||||
|
|
||||||
interface DS4CharacterPreparedDataData extends DS4ActorPreparedDataDataBase {
|
interface DS4CharacterPreparedDataData extends DS4ActorPreparedDataDataBase {
|
||||||
|
|
|
@ -110,6 +110,7 @@ export class DS4Actor extends Actor<DS4ActorData, DS4Item, DS4ActorPreparedData>
|
||||||
prepareDerivedData(): void {
|
prepareDerivedData(): void {
|
||||||
this._prepareCombatValues();
|
this._prepareCombatValues();
|
||||||
this._prepareChecks();
|
this._prepareChecks();
|
||||||
|
this._prepareCustomChecks();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -122,7 +123,10 @@ export class DS4Actor extends Actor<DS4ActorData, DS4Item, DS4ActorPreparedData>
|
||||||
const checkProperties = Object.keys(DS4.i18n.checks)
|
const checkProperties = Object.keys(DS4.i18n.checks)
|
||||||
.filter((check) => check !== "defend")
|
.filter((check) => check !== "defend")
|
||||||
.map((check) => `data.checks.${check}`);
|
.map((check) => `data.checks.${check}`);
|
||||||
return combatValueProperties.concat(checkProperties);
|
const customCheckProperties = Object.keys(game.settings.get("ds4", "customChecks")).map(
|
||||||
|
(check) => `data.customChecks.${check}`,
|
||||||
|
);
|
||||||
|
return combatValueProperties.concat(checkProperties).concat(customCheckProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -251,6 +255,25 @@ export class DS4Actor extends Actor<DS4ActorData, DS4Item, DS4ActorPreparedData>
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected _prepareCustomChecks(): void {
|
||||||
|
const customChecksSettings = game.settings.get("ds4", "customChecks");
|
||||||
|
const data = this.data.data;
|
||||||
|
data.customChecks = {};
|
||||||
|
Object.entries(customChecksSettings).forEach(([identifier, check]) => {
|
||||||
|
const replacedFormula = this._replaceFormulaData(check.formula);
|
||||||
|
console.log(replacedFormula);
|
||||||
|
data.customChecks[identifier] = Roll.MATH_PROXY.safeEval(replacedFormula);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected _replaceFormulaData(formula: string): string {
|
||||||
|
const dataRgx = new RegExp(/@([a-z.0-9_\-]+)/gi);
|
||||||
|
return formula.replace(dataRgx, (match, term) => {
|
||||||
|
const value = getProperty(this.data, term);
|
||||||
|
return value !== undefined ? String(value).trim() : match;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle how changes to a Token attribute bar are applied to the Actor.
|
* Handle how changes to a Token attribute bar are applied to the Actor.
|
||||||
* This only differs from the base implementation by also allowing negative values.
|
* This only differs from the base implementation by also allowing negative values.
|
||||||
|
|
1
src/module/global.d.ts
vendored
1
src/module/global.d.ts
vendored
|
@ -2,5 +2,6 @@ declare namespace ClientSettings {
|
||||||
interface Values {
|
interface Values {
|
||||||
"ds4.systemMigrationVersion": number;
|
"ds4.systemMigrationVersion": number;
|
||||||
"ds4.useSlayingDiceForAutomatedChecks": boolean;
|
"ds4.useSlayingDiceForAutomatedChecks": boolean;
|
||||||
|
"ds4.customChecks": Record<string, { label: string; formula: string }>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,4 +18,14 @@ export function registerSystemSettings(): void {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
game.settings.register("ds4", "customChecks", {
|
||||||
|
name: "DS4.SettingsCustomChecks",
|
||||||
|
scope: "world",
|
||||||
|
config: false,
|
||||||
|
// eslint-disable-next-line
|
||||||
|
//@ts-ignore
|
||||||
|
type: Object,
|
||||||
|
default: {},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,4 +3,8 @@
|
||||||
{{> systems/ds4/templates/sheets/actor/components/check.hbs check-key=check-key check-target-number=(lookup
|
{{> systems/ds4/templates/sheets/actor/components/check.hbs check-key=check-key check-target-number=(lookup
|
||||||
../data.checks check-key) check-label=check-label}}
|
../data.checks check-key) check-label=check-label}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
{{#each data.customChecks as |check-target-number check-key|}}
|
||||||
|
{{> systems/ds4/templates/sheets/actor/components/check.hbs check-key=check-key
|
||||||
|
check-target-number=check-target-number check-label=check-key}}
|
||||||
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue