fixing some roll template bugs

This commit is contained in:
Vlyan
2022-02-13 17:02:04 +01:00
parent 8c4072d8af
commit f640949016
8 changed files with 28 additions and 61 deletions

View File

@@ -218,24 +218,27 @@ export class RollnKeepDialog extends FormApplication {
* @return {Object}
*/
getData(options = null) {
const rollData = this.roll.l5r5e;
// Disable submit / edition
this.options.classes = this.options.classes.filter((e) => e !== "finalized");
this.object.submitDisabled = false;
if (this._checkKeepCount(this.object.currentStep)) {
const kept = this._getKeepCount(this.object.currentStep);
this.object.submitDisabled = kept < 1 || kept > this.roll.l5r5e.keepLimit;
this.object.submitDisabled = kept < 1 || kept > rollData.keepLimit;
} else if (!this.object.dicesList[this.object.currentStep]) {
this.options.editable = this.roll.l5r5e.summary.strife > 0;
this.options.editable = rollData.summary.strife > 0;
this.options.classes.push("finalized");
}
return {
...super.getData(options),
isGM: game.user.isGM,
showStrifeBt: rollData.summary.strife > 0 && rollData.actor,
cssClass: this.options.classes.join(" "),
data: this.object,
l5r5e: this.roll.l5r5e,
l5r5e: rollData,
};
}
@@ -681,7 +684,7 @@ export class RollnKeepDialog extends FormApplication {
// Apply strife to actor
const strifeApplied = Math.min(this.roll.l5r5e.summary.strife, Math.max(0, formData.strifeApplied));
const actorMod = strifeApplied - this.roll.l5r5e.strifeApplied;
if (actorMod !== 0) {
if (actorMod !== 0 && this.roll.l5r5e.actor) {
await this.roll.l5r5e.actor.update({
data: {
strife: {
@@ -689,12 +692,10 @@ export class RollnKeepDialog extends FormApplication {
},
},
});
// Update the roll & send to chat
this.roll.l5r5e.strifeApplied = strifeApplied;
await this._toChatMessage();
}
// Update the roll & send to chat
this.roll.l5r5e.strifeApplied = strifeApplied;
await this._rebuildRoll(false);
await this._toChatMessage();
return this.close();
}

View File

@@ -252,7 +252,6 @@ export class RollL5r5e extends Roll {
if (!this._evaluated) {
await this.roll();
}
console.log(this.l5r5e);
// Define chat data
const chatData = {
@@ -261,8 +260,9 @@ export class RollL5r5e extends Roll {
user: chatOptions.user,
isPublicRoll: !isPrivate,
tooltip: isPrivate ? "" : await this.getTooltip({ from: "render" }),
total: isPrivate ? "?" : Math.round(this._total * 100) / 100,
data: this.data,
total: isPrivate ? "?" : this.total,
//data: this.data,
profileImg: this.l5r5e.actor?.img ? this.l5r5e.actor?.img : "icons/svg/mystery-man.svg",
l5r5e: isPrivate
? {}
: {
@@ -309,12 +309,15 @@ export class RollL5r5e extends Roll {
messageData = ChatMessage.applyRollMode(messageData, rMode);
}
// Force the content to avoid weird foundry behaviour
const content = this.l5r5e.dicesTypes.l5r ? await this.render({}) : this.total;
// Prepare chat data
messageData = foundry.utils.mergeObject(
{
user: game.user.id,
type: CONST.CHAT_MESSAGE_TYPES.ROLL,
content: this._total,
content,
sound: CONFIG.sounds.dice,
speaker: {
actor: this.l5r5e.actor?.id || null,
@@ -330,7 +333,6 @@ export class RollL5r5e extends Roll {
const message = await ChatMessage.implementation.create(messageData, {
rollMode: rMode,
temporary: !create,
isL5r5eTemplate: true,
});
return create ? message : message.data;
}