This commit is contained in:
WBHarry 2025-11-25 00:21:32 +01:00
parent de9a66e1bc
commit 38868fdab6
23 changed files with 86 additions and 104 deletions

View file

@ -59,9 +59,7 @@ export default class CountdownEdit extends HandlebarsApplicationMixin(Applicatio
? 'DAGGERHEART.UI.Countdowns.decreasingLoop'
: 'DAGGERHEART.UI.Countdowns.loop'
: null;
const randomizeValid = Roll.parse(countdown.progress.startFormula ?? '').some(
x => x instanceof foundry.dice.terms.Die
);
const randomizeValid = !new Roll(countdown.progress.startFormula ?? '').isDeterministic;
acc[key] = {
...countdown,
typeName: game.i18n.localize(CONFIG.DH.GENERAL.countdownBaseTypes[countdown.type].label),
@ -208,17 +206,15 @@ export default class CountdownEdit extends HandlebarsApplicationMixin(Applicatio
const countdown = this.data.countdowns[button.dataset.countdownId];
const roll = await new Roll(countdown.progress.startFormula).roll();
const message = await roll.toMessage({ title: 'Countdown' });
const update = async () => {
await this.updateSetting({
[`countdowns.${button.dataset.countdownId}.progress`]: {
start: roll.total,
current: this.getMatchingCurrentValue(countdown, roll.total, countdown.progress.current)
}
});
this.render();
};
waitForDiceSoNice(message, update);
await waitForDiceSoNice(message);
await this.updateSetting({
[`countdowns.${button.dataset.countdownId}.progress`]: {
start: roll.total,
current: this.getMatchingCurrentValue(countdown, roll.total, countdown.progress.current)
}
});
this.render();
}
static async #removeCountdown(event, button) {

View file

@ -200,20 +200,16 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
? Math.max(Number(progressMax) - 1, 0)
: progressMax;
const update = async () => {
await settings.updateSource({
[`countdowns.${target.id}.progress`]: {
current: newMax,
start: newMax
}
});
await emitAsGM(GMUpdateEvent.UpdateCountdowns, DhCountdowns.gmSetSetting.bind(settings), settings, null, {
refreshType: RefreshType.Countdown
});
};
if (message) waitForDiceSoNice(message, update);
else update();
await waitForDiceSoNice(message);
await settings.updateSource({
[`countdowns.${target.id}.progress`]: {
current: newMax,
start: newMax
}
});
await emitAsGM(GMUpdateEvent.UpdateCountdowns, DhCountdowns.gmSetSetting.bind(settings), settings, null, {
refreshType: RefreshType.Countdown
});
}
static async editCountdown(increase, target) {

View file

@ -36,7 +36,7 @@ export default class DhCountdownAction extends DHBaseAction {
/** @inheritDoc */
static migrateData(source) {
for (let countdown of source.countdown) {
for (const countdown of source.countdown) {
if (countdown.progress.max) {
countdown.progress.startFormula = countdown.progress.max;
countdown.progress.start = 1;

View file

@ -1,4 +1,3 @@
import { waitForDiceSoNice } from '../../../helpers/utils.mjs';
import { emitAsGM, GMUpdateEvent, RefreshType, socketEvent } from '../../../systemRegistration/socket.mjs';
const fields = foundry.data.fields;
@ -67,43 +66,36 @@ export default class CountdownField extends fields.ArrayField {
};
}
const update = async () => {
await emitAsGM(
GMUpdateEvent.UpdateCountdowns,
async () => {
const countdownSetting = game.settings.get(
CONFIG.DH.id,
CONFIG.DH.SETTINGS.gameSettings.Countdowns
);
await countdownSetting.updateSource(data);
await game.settings.set(
CONFIG.DH.id,
CONFIG.DH.SETTINGS.gameSettings.Countdowns,
countdownSetting.toObject()
),
game.socket.emit(`system.${CONFIG.DH.id}`, {
action: socketEvent.Refresh,
data: { refreshType: RefreshType.Countdown }
});
Hooks.callAll(socketEvent.Refresh, { refreshType: RefreshType.Countdown });
},
data,
null,
{
refreshType: RefreshType.Countdown
}
);
};
if (game.modules.get('dice-so-nice')?.active) {
Promise.all(
await Promise.all(
countdownMessages.map(message => {
return game.dice3d.waitFor3DAnimationByMessageID(message.id);
})
).then(update);
} else {
update();
);
}
await emitAsGM(
GMUpdateEvent.UpdateCountdowns,
async () => {
const countdownSetting = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns);
await countdownSetting.updateSource(data);
await game.settings.set(
CONFIG.DH.id,
CONFIG.DH.SETTINGS.gameSettings.Countdowns,
countdownSetting.toObject()
),
game.socket.emit(`system.${CONFIG.DH.id}`, {
action: socketEvent.Refresh,
data: { refreshType: RefreshType.Countdown }
});
Hooks.callAll(socketEvent.Refresh, { refreshType: RefreshType.Countdown });
},
data,
null,
{
refreshType: RefreshType.Countdown
}
);
}
/**

View file

@ -446,10 +446,8 @@ export function itemIsIdentical(a, b) {
return compendiumSource && name & description;
}
export function waitForDiceSoNice(message, update) {
if (game.modules.get('dice-so-nice')?.active) {
game.dice3d.waitFor3DAnimationByMessageID(message.id).then(async () => await update());
} else {
update();
export async function waitForDiceSoNice(message) {
if (message && game.modules.get('dice-so-nice')?.active) {
await game.dice3d.waitFor3DAnimationByMessageID(message.id);
}
}

View file

@ -476,8 +476,8 @@
"progress": {
"looping": "looping",
"type": "custom",
"start": 6,
"startFormula": null,
"start": 1,
"startFormula": "6",
"current": 1
},
"ownership": {}

View file

@ -623,8 +623,8 @@
"progress": {
"looping": "decreasing",
"type": "actionRoll",
"start": 8,
"startFormula": null,
"start": 1,
"startFormula": "8",
"current": 1
},
"ownership": {}

View file

@ -630,8 +630,8 @@
"progress": {
"looping": "noLooping",
"type": "custom",
"start": 4,
"startFormula": null,
"start": 1,
"startFormula": "4",
"current": 1
},
"ownership": {}

View file

@ -361,8 +361,8 @@
"progress": {
"looping": "noLooping",
"type": "characterAttack",
"start": 5,
"startFormula": null,
"start": 1,
"startFormula": "5",
"current": 1
},
"ownership": {}

View file

@ -376,8 +376,8 @@
"progress": {
"looping": "noLooping",
"type": "custom",
"start": 8,
"startFormula": null,
"start": 1,
"startFormula": "8",
"current": 1
},
"ownership": {}

View file

@ -488,8 +488,8 @@
"progress": {
"looping": "noLooping",
"type": "custom",
"start": 6,
"startFormula": null,
"start": 1,
"startFormula": "6",
"current": 1
},
"ownership": {}

View file

@ -543,8 +543,8 @@
"progress": {
"looping": "noLooping",
"type": "custom",
"start": 8,
"startFormula": null,
"start": 1,
"startFormula": "8",
"current": 1
},
"ownership": {}

View file

@ -63,8 +63,8 @@
"progress": {
"looping": "noLooping",
"type": "custom",
"start": 8,
"startFormula": null,
"start": 1,
"startFormula": "8",
"current": 1
},
"ownership": {}

View file

@ -545,8 +545,8 @@
"progress": {
"looping": "looping",
"type": "actionRoll",
"start": 6,
"startFormula": null,
"start": 1,
"startFormula": "6",
"current": 1
},
"ownership": {}

View file

@ -291,8 +291,8 @@
"progress": {
"looping": "noLooping",
"type": "custom",
"start": 6,
"startFormula": null,
"start": 1,
"startFormula": "6",
"current": 1
},
"ownership": {}
@ -305,8 +305,8 @@
"progress": {
"looping": "noLooping",
"type": "custom",
"max": 4,
"startFormula": null,
"start": 1,
"startFormula": "4",
"current": 1
},
"ownership": {}

View file

@ -283,8 +283,8 @@
"progress": {
"looping": "noLooping",
"type": "custom",
"start": 6,
"startFormula": null,
"start": 1,
"startFormula": "6",
"current": 1
},
"ownership": {}

View file

@ -225,8 +225,8 @@
"progress": {
"looping": "noLooping",
"type": "custom",
"start": 8,
"startFormula": null,
"start": 1,
"startFormula": "8",
"current": 1
},
"ownership": {}

View file

@ -174,8 +174,8 @@
"progress": {
"looping": "noLooping",
"type": "custom",
"start": 12,
"startFormula": null,
"start": 1,
"startFormula": "12",
"current": 1
},
"ownership": {}

View file

@ -374,8 +374,8 @@
"progress": {
"looping": "noLooping",
"type": "fear",
"start": 6,
"startFormula": null,
"start": 1,
"startFormula": "6",
"current": 1
},
"ownership": {}

View file

@ -197,8 +197,8 @@
"progress": {
"looping": "noLooping",
"type": "custom",
"start": 8,
"startFormula": null,
"start": 1,
"startFormula": "8",
"current": 1
},
"ownership": {}

View file

@ -361,8 +361,8 @@
"progress": {
"looping": "noLooping",
"type": "custom",
"start": 5,
"startFormula": null,
"start": 1,
"startFormula": "5",
"current": 1
},
"ownership": {}

View file

@ -404,8 +404,8 @@
"progress": {
"looping": "looping",
"type": "actionRoll",
"start": 4,
"startFormula": null,
"start": 1,
"startFormula": "4",
"current": 1
},
"ownership": {}

View file

@ -183,8 +183,8 @@
"progress": {
"looping": "noLooping",
"type": "custom",
"start": 4,
"startFormula": null,
"start": 1,
"startFormula": "4",
"current": 1
},
"ownership": {}