Working on 0.8.x
- Added hook on preCreateChatMessage for the inlineRoll/chatmessage bug
This commit is contained in:
@@ -33,6 +33,7 @@ export class L5rBaseDie extends DiceTerm {
|
||||
|
||||
/**
|
||||
* Return a standardized representation for the displayed formula associated with this DiceTerm
|
||||
* @return {string}
|
||||
* @override
|
||||
*/
|
||||
get formula() {
|
||||
@@ -53,6 +54,8 @@ export class L5rBaseDie extends DiceTerm {
|
||||
|
||||
/**
|
||||
* Return the url of the result face
|
||||
* @param {string|number} result
|
||||
* @return {string}
|
||||
*/
|
||||
static getResultSrc(result) {
|
||||
return `${CONFIG.l5r5e.paths.assets}dices/default/${this.FACES[result].image}.svg`;
|
||||
@@ -62,13 +65,18 @@ export class L5rBaseDie extends DiceTerm {
|
||||
* Return the total result of the DiceTerm if it has been evaluated
|
||||
* Always zero for L5R dices to not count in total for regular dices
|
||||
* @override
|
||||
* @return {number|string}
|
||||
*/
|
||||
get total() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate the roll term, populating the results Array
|
||||
* Evaluate the term, processing its inputs and finalizing its total.
|
||||
* @param {boolean} minimize Minimize the result, obtaining the smallest possible value.
|
||||
* @param {boolean} maximize Maximize the result, obtaining the largest possible value.
|
||||
* @param {boolean} async Evaluate the term asynchronously, receiving a Promise as the returned value. This will become the default behavior in version 10.x
|
||||
* @return {L5rBaseDie} The evaluated RollTerm
|
||||
* @override
|
||||
*/
|
||||
evaluate({ minimize = false, maximize = false, async = false } = {}) {
|
||||
@@ -78,7 +86,7 @@ export class L5rBaseDie extends DiceTerm {
|
||||
|
||||
// Roll the initial number of dice
|
||||
for (let n = 1; n <= this.number; n++) {
|
||||
this.roll({ minimize, maximize, async });
|
||||
this.roll({ minimize, maximize, async }); // TODO async/await in v10.x currently the inline roll is sync
|
||||
}
|
||||
|
||||
// Apply modifiers
|
||||
@@ -112,15 +120,22 @@ export class L5rBaseDie extends DiceTerm {
|
||||
|
||||
/**
|
||||
* Roll the DiceTerm by mapping a random uniform draw against the faces of the dice term
|
||||
* @param {Object} options
|
||||
* @return {DiceTermResult}
|
||||
* @override
|
||||
*/
|
||||
roll(options) {
|
||||
roll(options = { minimize: false, maximize: false }) {
|
||||
const roll = super.roll(options);
|
||||
//roll.l5r5e = this.l5r5e;
|
||||
return roll;
|
||||
}
|
||||
|
||||
/** @override */
|
||||
/**
|
||||
* Construct a DiceTerm from a provided data object
|
||||
* @param {object} data Provided data from an un-serialized term
|
||||
* @return {DiceTerm} The constructed RollTerm
|
||||
* @override
|
||||
*/
|
||||
static fromData(data) {
|
||||
const roll = super.fromData(data);
|
||||
roll.l5r5e = data.l5r5e;
|
||||
@@ -128,7 +143,8 @@ export class L5rBaseDie extends DiceTerm {
|
||||
}
|
||||
|
||||
/**
|
||||
* Represent the data of the Roll as an object suitable for JSON serialization
|
||||
* Represent the data of the DiceTerm as an object suitable for JSON serialization
|
||||
* @return {string}
|
||||
* @override
|
||||
*/
|
||||
toJSON() {
|
||||
|
||||
@@ -577,7 +577,7 @@ export class RollnKeepDialog extends FormApplication {
|
||||
};
|
||||
|
||||
// Fill the data
|
||||
roll.evaluate();
|
||||
roll.evaluate({ async: false });
|
||||
|
||||
// Modify results
|
||||
roll.terms.map((term) => {
|
||||
|
||||
@@ -151,8 +151,6 @@ export class RollL5r5e extends Roll {
|
||||
this.l5r5e.summary[props] += parseInt(term.l5r5e[props]);
|
||||
});
|
||||
this.l5r5e.summary.totalSuccess += term.totalSuccess;
|
||||
|
||||
// TODO Others advantage/disadvantage
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,31 +158,28 @@ export class RollL5r5e extends Roll {
|
||||
* @override
|
||||
*/
|
||||
get total() {
|
||||
return null; // TODO Bug 0.8.x : If not returning a null/0 value the chat ignore the template. If i do this, no inline but "/r 1dr" work fine :'(
|
||||
if (!this._evaluated) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// if (!this._evaluated) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// let total = "";
|
||||
//
|
||||
// // Regular dices total (eg 6)
|
||||
// if (this.l5r5e.dicesTypes.std) {
|
||||
// total = this._total;
|
||||
// }
|
||||
//
|
||||
// // Add L5R summary
|
||||
// if (this.l5r5e.dicesTypes.l5r) {
|
||||
// const summary = this.l5r5e.summary;
|
||||
// total +=
|
||||
// (this.l5r5e.dicesTypes.std ? " | " : "") +
|
||||
// ["success", "explosive", "opportunity", "strife"]
|
||||
// .map((props) => (summary[props] > 0 ? `<i class="i_${props}"></i> ${summary[props]}` : null))
|
||||
// .filter((c) => !!c)
|
||||
// .join(" | ");
|
||||
// }
|
||||
//
|
||||
// return total;
|
||||
let total = "";
|
||||
|
||||
// Regular dices total (eg 6)
|
||||
if (this.l5r5e.dicesTypes.std) {
|
||||
total = this._total;
|
||||
}
|
||||
|
||||
// Add L5R summary
|
||||
if (this.l5r5e.dicesTypes.l5r) {
|
||||
const summary = this.l5r5e.summary;
|
||||
total +=
|
||||
(this.l5r5e.dicesTypes.std ? " | " : "") +
|
||||
["success", "explosive", "opportunity", "strife"]
|
||||
.map((props) => (summary[props] > 0 ? `<i class="i_${props}"></i> ${summary[props]}` : null))
|
||||
.filter((c) => !!c)
|
||||
.join(" | ");
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -302,18 +297,13 @@ export class RollL5r5e extends Roll {
|
||||
async toMessage(messageData = {}, { rollMode = null, create = true } = {}) {
|
||||
// Perform the roll, if it has not yet been rolled
|
||||
if (!this._evaluated) {
|
||||
this.evaluate();
|
||||
this.evaluate({ async: false });
|
||||
}
|
||||
|
||||
// RollMode
|
||||
const rMode = rollMode || messageData.rollMode || game.settings.get("core", "rollMode");
|
||||
if (["gmroll", "blindroll"].includes(rMode)) {
|
||||
messageData.whisper = ChatMessage.getWhisperRecipients("GM");
|
||||
}
|
||||
if (rMode === "blindroll") {
|
||||
messageData.blind = true;
|
||||
}
|
||||
if (rMode === "selfroll") {
|
||||
messageData.whisper = [game.user.id];
|
||||
if (rollMode) {
|
||||
ChatMessage.applyRollMode(messageData, rMode);
|
||||
}
|
||||
|
||||
// Prepare chat data
|
||||
@@ -334,7 +324,11 @@ export class RollL5r5e extends Roll {
|
||||
messageData.roll = this;
|
||||
|
||||
// Either create the message or just return the chat data
|
||||
const message = await ChatMessage.implementation.create(messageData, { rollMode: rMode, temporary: !create });
|
||||
const message = await ChatMessage.implementation.create(messageData, {
|
||||
rollMode: rMode,
|
||||
temporary: !create,
|
||||
isL5r5eTemplate: true,
|
||||
});
|
||||
return create ? message : message.data;
|
||||
}
|
||||
|
||||
@@ -369,8 +363,8 @@ export class RollL5r5e extends Roll {
|
||||
toJSON() {
|
||||
const json = super.toJSON();
|
||||
|
||||
json.data = duplicate(this.data);
|
||||
json.l5r5e = duplicate(this.l5r5e);
|
||||
json.data = foundry.utils.duplicate(this.data);
|
||||
json.l5r5e = foundry.utils.duplicate(this.l5r5e);
|
||||
|
||||
// lightweight the Actor
|
||||
if (json.l5r5e.actor) {
|
||||
|
||||
Reference in New Issue
Block a user