[Feature] Countdown Rols And Randomzie (#1329)

* .

* .

* .

* Raised system version
This commit is contained in:
WBHarry 2025-11-25 00:36:43 +01:00 committed by GitHub
parent 9e0bc3cff1
commit d137e33c3d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
37 changed files with 281 additions and 87 deletions

View file

@ -8,7 +8,10 @@ export default class DhCountdownAction extends DHBaseAction {
...super.defaultValues,
countdown: {
name: this.parent.parent.name,
img: this.img
img: this.img,
progress: {
startFormula: '1'
}
}
};
}
@ -21,10 +24,26 @@ export default class DhCountdownAction extends DHBaseAction {
{
...game.system.api.data.countdowns.DhCountdown.defaultCountdown(),
name: parent.parent.name,
img: parent.parent.img
img: parent.parent.img,
progress: {
startFormula: '1'
}
}
];
return updateSource;
}
/** @inheritDoc */
static migrateData(source) {
for (const countdown of source.countdown) {
if (countdown.progress.max) {
countdown.progress.startFormula = countdown.progress.max;
countdown.progress.start = 1;
countdown.progress.max = null;
}
}
return super.migrateData(source);
}
}

View file

@ -167,10 +167,15 @@ export class DhCountdown extends foundry.abstract.DataModel {
initial: 1,
label: 'DAGGERHEART.APPLICATIONS.Countdown.FIELDS.countdowns.element.progress.current.label'
}),
max: new FormulaField({
start: new fields.NumberField({
required: true,
integer: true,
initial: 1,
label: 'DAGGERHEART.APPLICATIONS.Countdown.FIELDS.countdowns.element.progress.max.label',
label: 'DAGGERHEART.APPLICATIONS.Countdown.FIELDS.countdowns.element.progress.start.label',
deterministic: false
}),
startFormula: new FormulaField({
label: 'DAGGERHEART.APPLICATIONS.Countdown.FIELDS.countdowns.element.progress.startFormula.label',
deterministic: false
}),
looping: new fields.StringField({
@ -206,7 +211,7 @@ export class DhCountdown extends foundry.abstract.DataModel {
ownership: ownership,
progress: {
current: 1,
max: 1
start: 1
}
};
}
@ -225,4 +230,15 @@ export class DhCountdown extends foundry.abstract.DataModel {
return acc;
}, {});
}
/** @inheritDoc */
static migrateData(source) {
if (source.progress.max) {
source.progress.start = Number(source.progress.max);
source.progress.max = null;
source.progress.startFormula = null;
}
return super.migrateData(source);
}
}

View file

@ -40,18 +40,40 @@ export default class CountdownField extends fields.ArrayField {
}
const data = { countdowns: {} };
const countdownMessages = [];
for (let countdown of config.countdowns) {
const { total: max } = await new Roll(countdown.progress.max).evaluate();
let startFormula = countdown.progress.startFormula ? countdown.progress.startFormula : null;
let countdownStart = startFormula ?? '1';
if (startFormula) {
const roll = await new Roll(startFormula).roll();
if (roll.dice.length > 0) {
countdownStart = roll.total;
const message = await roll.toMessage();
countdownMessages.push(message);
} else {
startFormula = null;
}
}
data.countdowns[foundry.utils.randomID()] = {
...countdown,
progress: {
...countdown.progress,
current: max,
max: max
current: countdownStart,
start: countdownStart,
startFormula
}
};
}
if (game.modules.get('dice-so-nice')?.active) {
await Promise.all(
countdownMessages.map(message => {
return game.dice3d.waitFor3DAnimationByMessageID(message.id);
})
);
}
await emitAsGM(
GMUpdateEvent.UpdateCountdowns,
async () => {