mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-16 13:41:07 +01:00
.
This commit is contained in:
parent
de9a66e1bc
commit
38868fdab6
23 changed files with 86 additions and 104 deletions
|
|
@ -59,9 +59,7 @@ export default class CountdownEdit extends HandlebarsApplicationMixin(Applicatio
|
||||||
? 'DAGGERHEART.UI.Countdowns.decreasingLoop'
|
? 'DAGGERHEART.UI.Countdowns.decreasingLoop'
|
||||||
: 'DAGGERHEART.UI.Countdowns.loop'
|
: 'DAGGERHEART.UI.Countdowns.loop'
|
||||||
: null;
|
: null;
|
||||||
const randomizeValid = Roll.parse(countdown.progress.startFormula ?? '').some(
|
const randomizeValid = !new Roll(countdown.progress.startFormula ?? '').isDeterministic;
|
||||||
x => x instanceof foundry.dice.terms.Die
|
|
||||||
);
|
|
||||||
acc[key] = {
|
acc[key] = {
|
||||||
...countdown,
|
...countdown,
|
||||||
typeName: game.i18n.localize(CONFIG.DH.GENERAL.countdownBaseTypes[countdown.type].label),
|
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 countdown = this.data.countdowns[button.dataset.countdownId];
|
||||||
const roll = await new Roll(countdown.progress.startFormula).roll();
|
const roll = await new Roll(countdown.progress.startFormula).roll();
|
||||||
const message = await roll.toMessage({ title: 'Countdown' });
|
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) {
|
static async #removeCountdown(event, button) {
|
||||||
|
|
|
||||||
|
|
@ -200,20 +200,16 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
|
||||||
? Math.max(Number(progressMax) - 1, 0)
|
? Math.max(Number(progressMax) - 1, 0)
|
||||||
: progressMax;
|
: progressMax;
|
||||||
|
|
||||||
const update = async () => {
|
await waitForDiceSoNice(message);
|
||||||
await settings.updateSource({
|
await settings.updateSource({
|
||||||
[`countdowns.${target.id}.progress`]: {
|
[`countdowns.${target.id}.progress`]: {
|
||||||
current: newMax,
|
current: newMax,
|
||||||
start: newMax
|
start: newMax
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await emitAsGM(GMUpdateEvent.UpdateCountdowns, DhCountdowns.gmSetSetting.bind(settings), settings, null, {
|
await emitAsGM(GMUpdateEvent.UpdateCountdowns, DhCountdowns.gmSetSetting.bind(settings), settings, null, {
|
||||||
refreshType: RefreshType.Countdown
|
refreshType: RefreshType.Countdown
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
if (message) waitForDiceSoNice(message, update);
|
|
||||||
else update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static async editCountdown(increase, target) {
|
static async editCountdown(increase, target) {
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ export default class DhCountdownAction extends DHBaseAction {
|
||||||
|
|
||||||
/** @inheritDoc */
|
/** @inheritDoc */
|
||||||
static migrateData(source) {
|
static migrateData(source) {
|
||||||
for (let countdown of source.countdown) {
|
for (const countdown of source.countdown) {
|
||||||
if (countdown.progress.max) {
|
if (countdown.progress.max) {
|
||||||
countdown.progress.startFormula = countdown.progress.max;
|
countdown.progress.startFormula = countdown.progress.max;
|
||||||
countdown.progress.start = 1;
|
countdown.progress.start = 1;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import { waitForDiceSoNice } from '../../../helpers/utils.mjs';
|
|
||||||
import { emitAsGM, GMUpdateEvent, RefreshType, socketEvent } from '../../../systemRegistration/socket.mjs';
|
import { emitAsGM, GMUpdateEvent, RefreshType, socketEvent } from '../../../systemRegistration/socket.mjs';
|
||||||
|
|
||||||
const fields = foundry.data.fields;
|
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) {
|
if (game.modules.get('dice-so-nice')?.active) {
|
||||||
Promise.all(
|
await Promise.all(
|
||||||
countdownMessages.map(message => {
|
countdownMessages.map(message => {
|
||||||
return game.dice3d.waitFor3DAnimationByMessageID(message.id);
|
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
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -446,10 +446,8 @@ export function itemIsIdentical(a, b) {
|
||||||
return compendiumSource && name & description;
|
return compendiumSource && name & description;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function waitForDiceSoNice(message, update) {
|
export async function waitForDiceSoNice(message) {
|
||||||
if (game.modules.get('dice-so-nice')?.active) {
|
if (message && game.modules.get('dice-so-nice')?.active) {
|
||||||
game.dice3d.waitFor3DAnimationByMessageID(message.id).then(async () => await update());
|
await game.dice3d.waitFor3DAnimationByMessageID(message.id);
|
||||||
} else {
|
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -476,8 +476,8 @@
|
||||||
"progress": {
|
"progress": {
|
||||||
"looping": "looping",
|
"looping": "looping",
|
||||||
"type": "custom",
|
"type": "custom",
|
||||||
"start": 6,
|
"start": 1,
|
||||||
"startFormula": null,
|
"startFormula": "6",
|
||||||
"current": 1
|
"current": 1
|
||||||
},
|
},
|
||||||
"ownership": {}
|
"ownership": {}
|
||||||
|
|
|
||||||
|
|
@ -623,8 +623,8 @@
|
||||||
"progress": {
|
"progress": {
|
||||||
"looping": "decreasing",
|
"looping": "decreasing",
|
||||||
"type": "actionRoll",
|
"type": "actionRoll",
|
||||||
"start": 8,
|
"start": 1,
|
||||||
"startFormula": null,
|
"startFormula": "8",
|
||||||
"current": 1
|
"current": 1
|
||||||
},
|
},
|
||||||
"ownership": {}
|
"ownership": {}
|
||||||
|
|
|
||||||
|
|
@ -630,8 +630,8 @@
|
||||||
"progress": {
|
"progress": {
|
||||||
"looping": "noLooping",
|
"looping": "noLooping",
|
||||||
"type": "custom",
|
"type": "custom",
|
||||||
"start": 4,
|
"start": 1,
|
||||||
"startFormula": null,
|
"startFormula": "4",
|
||||||
"current": 1
|
"current": 1
|
||||||
},
|
},
|
||||||
"ownership": {}
|
"ownership": {}
|
||||||
|
|
|
||||||
|
|
@ -361,8 +361,8 @@
|
||||||
"progress": {
|
"progress": {
|
||||||
"looping": "noLooping",
|
"looping": "noLooping",
|
||||||
"type": "characterAttack",
|
"type": "characterAttack",
|
||||||
"start": 5,
|
"start": 1,
|
||||||
"startFormula": null,
|
"startFormula": "5",
|
||||||
"current": 1
|
"current": 1
|
||||||
},
|
},
|
||||||
"ownership": {}
|
"ownership": {}
|
||||||
|
|
|
||||||
|
|
@ -376,8 +376,8 @@
|
||||||
"progress": {
|
"progress": {
|
||||||
"looping": "noLooping",
|
"looping": "noLooping",
|
||||||
"type": "custom",
|
"type": "custom",
|
||||||
"start": 8,
|
"start": 1,
|
||||||
"startFormula": null,
|
"startFormula": "8",
|
||||||
"current": 1
|
"current": 1
|
||||||
},
|
},
|
||||||
"ownership": {}
|
"ownership": {}
|
||||||
|
|
|
||||||
|
|
@ -488,8 +488,8 @@
|
||||||
"progress": {
|
"progress": {
|
||||||
"looping": "noLooping",
|
"looping": "noLooping",
|
||||||
"type": "custom",
|
"type": "custom",
|
||||||
"start": 6,
|
"start": 1,
|
||||||
"startFormula": null,
|
"startFormula": "6",
|
||||||
"current": 1
|
"current": 1
|
||||||
},
|
},
|
||||||
"ownership": {}
|
"ownership": {}
|
||||||
|
|
|
||||||
|
|
@ -543,8 +543,8 @@
|
||||||
"progress": {
|
"progress": {
|
||||||
"looping": "noLooping",
|
"looping": "noLooping",
|
||||||
"type": "custom",
|
"type": "custom",
|
||||||
"start": 8,
|
"start": 1,
|
||||||
"startFormula": null,
|
"startFormula": "8",
|
||||||
"current": 1
|
"current": 1
|
||||||
},
|
},
|
||||||
"ownership": {}
|
"ownership": {}
|
||||||
|
|
|
||||||
|
|
@ -63,8 +63,8 @@
|
||||||
"progress": {
|
"progress": {
|
||||||
"looping": "noLooping",
|
"looping": "noLooping",
|
||||||
"type": "custom",
|
"type": "custom",
|
||||||
"start": 8,
|
"start": 1,
|
||||||
"startFormula": null,
|
"startFormula": "8",
|
||||||
"current": 1
|
"current": 1
|
||||||
},
|
},
|
||||||
"ownership": {}
|
"ownership": {}
|
||||||
|
|
|
||||||
|
|
@ -545,8 +545,8 @@
|
||||||
"progress": {
|
"progress": {
|
||||||
"looping": "looping",
|
"looping": "looping",
|
||||||
"type": "actionRoll",
|
"type": "actionRoll",
|
||||||
"start": 6,
|
"start": 1,
|
||||||
"startFormula": null,
|
"startFormula": "6",
|
||||||
"current": 1
|
"current": 1
|
||||||
},
|
},
|
||||||
"ownership": {}
|
"ownership": {}
|
||||||
|
|
|
||||||
|
|
@ -291,8 +291,8 @@
|
||||||
"progress": {
|
"progress": {
|
||||||
"looping": "noLooping",
|
"looping": "noLooping",
|
||||||
"type": "custom",
|
"type": "custom",
|
||||||
"start": 6,
|
"start": 1,
|
||||||
"startFormula": null,
|
"startFormula": "6",
|
||||||
"current": 1
|
"current": 1
|
||||||
},
|
},
|
||||||
"ownership": {}
|
"ownership": {}
|
||||||
|
|
@ -305,8 +305,8 @@
|
||||||
"progress": {
|
"progress": {
|
||||||
"looping": "noLooping",
|
"looping": "noLooping",
|
||||||
"type": "custom",
|
"type": "custom",
|
||||||
"max": 4,
|
"start": 1,
|
||||||
"startFormula": null,
|
"startFormula": "4",
|
||||||
"current": 1
|
"current": 1
|
||||||
},
|
},
|
||||||
"ownership": {}
|
"ownership": {}
|
||||||
|
|
|
||||||
|
|
@ -283,8 +283,8 @@
|
||||||
"progress": {
|
"progress": {
|
||||||
"looping": "noLooping",
|
"looping": "noLooping",
|
||||||
"type": "custom",
|
"type": "custom",
|
||||||
"start": 6,
|
"start": 1,
|
||||||
"startFormula": null,
|
"startFormula": "6",
|
||||||
"current": 1
|
"current": 1
|
||||||
},
|
},
|
||||||
"ownership": {}
|
"ownership": {}
|
||||||
|
|
|
||||||
|
|
@ -225,8 +225,8 @@
|
||||||
"progress": {
|
"progress": {
|
||||||
"looping": "noLooping",
|
"looping": "noLooping",
|
||||||
"type": "custom",
|
"type": "custom",
|
||||||
"start": 8,
|
"start": 1,
|
||||||
"startFormula": null,
|
"startFormula": "8",
|
||||||
"current": 1
|
"current": 1
|
||||||
},
|
},
|
||||||
"ownership": {}
|
"ownership": {}
|
||||||
|
|
|
||||||
|
|
@ -174,8 +174,8 @@
|
||||||
"progress": {
|
"progress": {
|
||||||
"looping": "noLooping",
|
"looping": "noLooping",
|
||||||
"type": "custom",
|
"type": "custom",
|
||||||
"start": 12,
|
"start": 1,
|
||||||
"startFormula": null,
|
"startFormula": "12",
|
||||||
"current": 1
|
"current": 1
|
||||||
},
|
},
|
||||||
"ownership": {}
|
"ownership": {}
|
||||||
|
|
|
||||||
|
|
@ -374,8 +374,8 @@
|
||||||
"progress": {
|
"progress": {
|
||||||
"looping": "noLooping",
|
"looping": "noLooping",
|
||||||
"type": "fear",
|
"type": "fear",
|
||||||
"start": 6,
|
"start": 1,
|
||||||
"startFormula": null,
|
"startFormula": "6",
|
||||||
"current": 1
|
"current": 1
|
||||||
},
|
},
|
||||||
"ownership": {}
|
"ownership": {}
|
||||||
|
|
|
||||||
|
|
@ -197,8 +197,8 @@
|
||||||
"progress": {
|
"progress": {
|
||||||
"looping": "noLooping",
|
"looping": "noLooping",
|
||||||
"type": "custom",
|
"type": "custom",
|
||||||
"start": 8,
|
"start": 1,
|
||||||
"startFormula": null,
|
"startFormula": "8",
|
||||||
"current": 1
|
"current": 1
|
||||||
},
|
},
|
||||||
"ownership": {}
|
"ownership": {}
|
||||||
|
|
|
||||||
|
|
@ -361,8 +361,8 @@
|
||||||
"progress": {
|
"progress": {
|
||||||
"looping": "noLooping",
|
"looping": "noLooping",
|
||||||
"type": "custom",
|
"type": "custom",
|
||||||
"start": 5,
|
"start": 1,
|
||||||
"startFormula": null,
|
"startFormula": "5",
|
||||||
"current": 1
|
"current": 1
|
||||||
},
|
},
|
||||||
"ownership": {}
|
"ownership": {}
|
||||||
|
|
|
||||||
|
|
@ -404,8 +404,8 @@
|
||||||
"progress": {
|
"progress": {
|
||||||
"looping": "looping",
|
"looping": "looping",
|
||||||
"type": "actionRoll",
|
"type": "actionRoll",
|
||||||
"start": 4,
|
"start": 1,
|
||||||
"startFormula": null,
|
"startFormula": "4",
|
||||||
"current": 1
|
"current": 1
|
||||||
},
|
},
|
||||||
"ownership": {}
|
"ownership": {}
|
||||||
|
|
|
||||||
|
|
@ -183,8 +183,8 @@
|
||||||
"progress": {
|
"progress": {
|
||||||
"looping": "noLooping",
|
"looping": "noLooping",
|
||||||
"type": "custom",
|
"type": "custom",
|
||||||
"start": 4,
|
"start": 1,
|
||||||
"startFormula": null,
|
"startFormula": "4",
|
||||||
"current": 1
|
"current": 1
|
||||||
},
|
},
|
||||||
"ownership": {}
|
"ownership": {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue