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 a standardized representation for the displayed formula associated with this DiceTerm
|
||||||
|
* @return {string}
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
get formula() {
|
get formula() {
|
||||||
@@ -53,6 +54,8 @@ export class L5rBaseDie extends DiceTerm {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the url of the result face
|
* Return the url of the result face
|
||||||
|
* @param {string|number} result
|
||||||
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
static getResultSrc(result) {
|
static getResultSrc(result) {
|
||||||
return `${CONFIG.l5r5e.paths.assets}dices/default/${this.FACES[result].image}.svg`;
|
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
|
* 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
|
* Always zero for L5R dices to not count in total for regular dices
|
||||||
* @override
|
* @override
|
||||||
|
* @return {number|string}
|
||||||
*/
|
*/
|
||||||
get total() {
|
get total() {
|
||||||
return 0;
|
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
|
* @override
|
||||||
*/
|
*/
|
||||||
evaluate({ minimize = false, maximize = false, async = false } = {}) {
|
evaluate({ minimize = false, maximize = false, async = false } = {}) {
|
||||||
@@ -78,7 +86,7 @@ export class L5rBaseDie extends DiceTerm {
|
|||||||
|
|
||||||
// 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 });
|
this.roll({ minimize, maximize, async }); // TODO async/await in v10.x currently the inline roll is sync
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply modifiers
|
// 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
|
* Roll the DiceTerm by mapping a random uniform draw against the faces of the dice term
|
||||||
|
* @param {Object} options
|
||||||
|
* @return {DiceTermResult}
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
roll(options) {
|
roll(options = { minimize: false, maximize: false }) {
|
||||||
const roll = super.roll(options);
|
const roll = super.roll(options);
|
||||||
//roll.l5r5e = this.l5r5e;
|
//roll.l5r5e = this.l5r5e;
|
||||||
return roll;
|
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) {
|
static fromData(data) {
|
||||||
const roll = super.fromData(data);
|
const roll = super.fromData(data);
|
||||||
roll.l5r5e = data.l5r5e;
|
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
|
* @override
|
||||||
*/
|
*/
|
||||||
toJSON() {
|
toJSON() {
|
||||||
|
|||||||
@@ -577,7 +577,7 @@ export class RollnKeepDialog extends FormApplication {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Fill the data
|
// Fill the data
|
||||||
roll.evaluate();
|
roll.evaluate({ async: false });
|
||||||
|
|
||||||
// Modify results
|
// Modify results
|
||||||
roll.terms.map((term) => {
|
roll.terms.map((term) => {
|
||||||
|
|||||||
@@ -151,8 +151,6 @@ export class RollL5r5e extends Roll {
|
|||||||
this.l5r5e.summary[props] += parseInt(term.l5r5e[props]);
|
this.l5r5e.summary[props] += parseInt(term.l5r5e[props]);
|
||||||
});
|
});
|
||||||
this.l5r5e.summary.totalSuccess += term.totalSuccess;
|
this.l5r5e.summary.totalSuccess += term.totalSuccess;
|
||||||
|
|
||||||
// TODO Others advantage/disadvantage
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -160,31 +158,28 @@ export class RollL5r5e extends Roll {
|
|||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
get total() {
|
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) {
|
let total = "";
|
||||||
// return null;
|
|
||||||
// }
|
// Regular dices total (eg 6)
|
||||||
//
|
if (this.l5r5e.dicesTypes.std) {
|
||||||
// let total = "";
|
total = this._total;
|
||||||
//
|
}
|
||||||
// // Regular dices total (eg 6)
|
|
||||||
// if (this.l5r5e.dicesTypes.std) {
|
// Add L5R summary
|
||||||
// total = this._total;
|
if (this.l5r5e.dicesTypes.l5r) {
|
||||||
// }
|
const summary = this.l5r5e.summary;
|
||||||
//
|
total +=
|
||||||
// // Add L5R summary
|
(this.l5r5e.dicesTypes.std ? " | " : "") +
|
||||||
// if (this.l5r5e.dicesTypes.l5r) {
|
["success", "explosive", "opportunity", "strife"]
|
||||||
// const summary = this.l5r5e.summary;
|
.map((props) => (summary[props] > 0 ? `<i class="i_${props}"></i> ${summary[props]}` : null))
|
||||||
// total +=
|
.filter((c) => !!c)
|
||||||
// (this.l5r5e.dicesTypes.std ? " | " : "") +
|
.join(" | ");
|
||||||
// ["success", "explosive", "opportunity", "strife"]
|
}
|
||||||
// .map((props) => (summary[props] > 0 ? `<i class="i_${props}"></i> ${summary[props]}` : null))
|
return total;
|
||||||
// .filter((c) => !!c)
|
|
||||||
// .join(" | ");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return total;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -302,18 +297,13 @@ 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();
|
this.evaluate({ async: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RollMode
|
||||||
const rMode = rollMode || messageData.rollMode || game.settings.get("core", "rollMode");
|
const rMode = rollMode || messageData.rollMode || game.settings.get("core", "rollMode");
|
||||||
if (["gmroll", "blindroll"].includes(rMode)) {
|
if (rollMode) {
|
||||||
messageData.whisper = ChatMessage.getWhisperRecipients("GM");
|
ChatMessage.applyRollMode(messageData, rMode);
|
||||||
}
|
|
||||||
if (rMode === "blindroll") {
|
|
||||||
messageData.blind = true;
|
|
||||||
}
|
|
||||||
if (rMode === "selfroll") {
|
|
||||||
messageData.whisper = [game.user.id];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare chat data
|
// Prepare chat data
|
||||||
@@ -334,7 +324,11 @@ export class RollL5r5e extends Roll {
|
|||||||
messageData.roll = this;
|
messageData.roll = this;
|
||||||
|
|
||||||
// Either create the message or just return the chat data
|
// 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;
|
return create ? message : message.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,8 +363,8 @@ export class RollL5r5e extends Roll {
|
|||||||
toJSON() {
|
toJSON() {
|
||||||
const json = super.toJSON();
|
const json = super.toJSON();
|
||||||
|
|
||||||
json.data = duplicate(this.data);
|
json.data = foundry.utils.duplicate(this.data);
|
||||||
json.l5r5e = duplicate(this.l5r5e);
|
json.l5r5e = foundry.utils.duplicate(this.l5r5e);
|
||||||
|
|
||||||
// lightweight the Actor
|
// lightweight the Actor
|
||||||
if (json.l5r5e.actor) {
|
if (json.l5r5e.actor) {
|
||||||
|
|||||||
@@ -60,6 +60,32 @@ export default class HooksL5r5e {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modify the content for chat roll command
|
||||||
|
*
|
||||||
|
* The 0.8.x introduce a weird behavior, it get to roll.total as content event if a template was defined.
|
||||||
|
* So we need to intercept a chat roll (/r 1dr) for having them use the right template and not the inline (=total)
|
||||||
|
*
|
||||||
|
* @param {ChatMessage} document
|
||||||
|
* @param {Object} data
|
||||||
|
* @param {Object} options
|
||||||
|
* @param {string} userId
|
||||||
|
* @return {boolean}
|
||||||
|
*/
|
||||||
|
static preCreateChatMessage(document, data, options, userId) {
|
||||||
|
// Roll from DP have the "isL5r5eTemplate" option set
|
||||||
|
if (!document.isRoll || options?.isL5r5eTemplate || !document.data?.roll) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// So now we have our wrong message only, redo it using the roll
|
||||||
|
const roll = game.l5r5e.RollL5r5e.fromJSON(document.data.roll);
|
||||||
|
roll.toMessage();
|
||||||
|
|
||||||
|
// Return false to let the system known we handled this
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Chat Message
|
* Chat Message
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -172,3 +172,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)
|
||||||
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user