Added Colorful/Normal DualityRoll color settings

This commit is contained in:
WBHarry 2025-05-26 11:15:14 +02:00
parent 8795d7e71d
commit 320eec1230
14 changed files with 873 additions and 139 deletions

View file

@ -1,3 +1,5 @@
import { DualityRollColor } from '../config/settingsConfig.mjs';
const fields = foundry.data.fields;
const diceField = () =>
new fields.SchemaField({
@ -6,6 +8,12 @@ const diceField = () =>
});
export default class DhpDualityRoll extends foundry.abstract.TypeDataModel {
static dualityResult = {
hope: 1,
fear: 2,
critical: 3
};
static defineSchema() {
return {
title: new fields.StringField(),
@ -57,19 +65,34 @@ export default class DhpDualityRoll extends foundry.abstract.TypeDataModel {
}
get total() {
const modifiers = this.modifiers.reduce((acc, x) => acc + x.value, 0);
const advantage = this.advantage.value
? this.advantage.value
: this.disadvantage.value
? -this.disadvantage.value
: 0;
return this.diceTotal + advantage + modifiers;
return this.diceTotal + advantage + this.modifierTotal.value;
}
get diceTotal() {
return this.hope.value + this.fear.value;
}
get modifierTotal() {
const total = this.modifiers.reduce((acc, x) => acc + x.value, 0);
return {
value: total,
label: total > 0 ? `+${total}` : total < 0 ? `-${total}` : ''
};
}
get dualityResult() {
return this.hope.value > this.fear.value
? this.constructor.dualityResult.hope
: this.fear.value > this.hope.value
? this.constructor.dualityResult.fear
: this.constructor.dualityResult.critical;
}
get totalLabel() {
const label =
this.hope.value > this.fear.value
@ -81,6 +104,13 @@ export default class DhpDualityRoll extends foundry.abstract.TypeDataModel {
return game.i18n.localize(label);
}
get colorful() {
return (
game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.DualityRollColor) ===
DualityRollColor.colorful.value
);
}
prepareDerivedData() {
const total = this.total;