v9 - roll now async (sync is removed in v10)
This commit is contained in:
@@ -79,14 +79,14 @@ export class L5rBaseDie extends DiceTerm {
|
|||||||
* @return {L5rBaseDie} The evaluated RollTerm
|
* @return {L5rBaseDie} The evaluated RollTerm
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
evaluate({ minimize = false, maximize = false, async = false } = {}) {
|
async evaluate({ minimize = false, maximize = false, async = true } = {}) {
|
||||||
if (this._evaluated) {
|
if (this._evaluated) {
|
||||||
throw new Error(`This ${this.constructor.name} has already been evaluated and is immutable`);
|
throw new Error(`This ${this.constructor.name} has already been evaluated and is immutable`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Roll the initial number of dice
|
// Roll the initial number of dice
|
||||||
for (let n = 1; n <= this.number; n++) {
|
for (let n = 1; n <= this.number; n++) {
|
||||||
this.roll({ minimize, maximize, async }); // TODO async/await in v10.x currently the inline roll is sync
|
await this.roll({ minimize, maximize, async });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply modifiers
|
// Apply modifiers
|
||||||
|
|||||||
@@ -583,7 +583,7 @@ export class RollnKeepDialog extends FormApplication {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Fill the data
|
// Fill the data
|
||||||
roll.evaluate({ async: false });
|
await roll.evaluate();
|
||||||
|
|
||||||
// Modify results
|
// Modify results
|
||||||
roll.terms.map((term) => {
|
roll.terms.map((term) => {
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ export class RollL5r5e extends Roll {
|
|||||||
* Execute the Roll, replacing dice and evaluating the total result
|
* Execute the Roll, replacing dice and evaluating the total result
|
||||||
* @override
|
* @override
|
||||||
**/
|
**/
|
||||||
evaluate({ minimize = false, maximize = false, async = false } = {}) {
|
async evaluate({ minimize = false, maximize = false, async = true } = {}) {
|
||||||
if (this._evaluated) {
|
if (this._evaluated) {
|
||||||
throw new Error("This Roll object has already been rolled.");
|
throw new Error("This Roll object has already been rolled.");
|
||||||
}
|
}
|
||||||
@@ -71,7 +71,7 @@ export class RollL5r5e extends Roll {
|
|||||||
this._total = 0;
|
this._total = 0;
|
||||||
|
|
||||||
// Roll
|
// Roll
|
||||||
super.evaluate({ minimize, maximize, async });
|
await super.evaluate({ minimize, maximize, async });
|
||||||
this._evaluated = true;
|
this._evaluated = true;
|
||||||
|
|
||||||
// Save initial formula
|
// Save initial formula
|
||||||
@@ -297,7 +297,7 @@ export class RollL5r5e extends Roll {
|
|||||||
async toMessage(messageData = {}, { rollMode = null, create = true } = {}) {
|
async toMessage(messageData = {}, { rollMode = null, create = true } = {}) {
|
||||||
// Perform the roll, if it has not yet been rolled
|
// Perform the roll, if it has not yet been rolled
|
||||||
if (!this._evaluated) {
|
if (!this._evaluated) {
|
||||||
this.evaluate({ async: false });
|
await this.evaluate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// RollMode
|
// RollMode
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ export default class HooksL5r5e {
|
|||||||
* @param {string} userId
|
* @param {string} userId
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
static preCreateChatMessage(document, data, options, userId) {
|
static async preCreateChatMessage(document, data, options, userId) {
|
||||||
// Roll from DP have the "isL5r5eTemplate" option set
|
// Roll from DP have the "isL5r5eTemplate" option set
|
||||||
if (!document.isRoll || options?.isL5r5eTemplate || !document.data?.roll) {
|
if (!document.isRoll || options?.isL5r5eTemplate || !document.data?.roll) {
|
||||||
return;
|
return;
|
||||||
@@ -83,7 +83,7 @@ export default class HooksL5r5e {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// So now we have our wrong message only, redo it using the roll
|
// So now we have our wrong message only, redo it using the roll
|
||||||
roll.toMessage();
|
await roll.toMessage();
|
||||||
|
|
||||||
// Return false to let the system known we handled this
|
// Return false to let the system known we handled this
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -248,6 +248,6 @@ Hooks.on("renderChatMessage", (message, html, data) => HooksL5r5e.renderChatMess
|
|||||||
Hooks.on("renderCombatTracker", (app, html, data) => HooksL5r5e.renderCombatTracker(app, html, data));
|
Hooks.on("renderCombatTracker", (app, html, data) => HooksL5r5e.renderCombatTracker(app, html, data));
|
||||||
Hooks.on("renderCompendium", async (app, html, data) => HooksL5r5e.renderCompendium(app, html, data));
|
Hooks.on("renderCompendium", async (app, html, data) => HooksL5r5e.renderCompendium(app, html, data));
|
||||||
Hooks.on("diceSoNiceRollStart", (messageId, context) => HooksL5r5e.diceSoNiceRollStart(messageId, context));
|
Hooks.on("diceSoNiceRollStart", (messageId, context) => HooksL5r5e.diceSoNiceRollStart(messageId, context));
|
||||||
Hooks.on("preCreateChatMessage", (document, data, options, userId) =>
|
|
||||||
HooksL5r5e.preCreateChatMessage(document, data, options, userId)
|
// TODO Seem fixed in v9, remove in v10 if good
|
||||||
);
|
// Hooks.on("preCreateChatMessage", (document, data, options, userId) => HooksL5r5e.preCreateChatMessage(document, data, options, userId));
|
||||||
|
|||||||
Reference in New Issue
Block a user