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

@@ -3,8 +3,9 @@
## 1.7.0 - DiceRoller for Techniques & Npc Generator ## 1.7.0 - DiceRoller for Techniques & Npc Generator
- NPC Sheet : - NPC Sheet :
- Added a random generator feature (Demeanor, Clan and Families names courteously authorized by Edge). - Added a random generator feature (Demeanor, Clan and Families names courteously authorized by Edge).
- This is random by design, don't expect clan logic in values.
- PC/NPC sheet: - PC/NPC sheet:
- Added the ability to techniques, with a skill set, to open the DicePicker with presets values. - Added the ability for technique with a skill set, to open the DicePicker with presets values.
- Some can interact with targets, but do the default difficulty if none. - Some can interact with targets, but do the default difficulty if none.
- Notes : Techniques in sheet need to be re-imported from the compendium or manually updated for this to work. - Notes : Techniques in sheet need to be re-imported from the compendium or manually updated for this to work.
- Compendiums : - Compendiums :
@@ -13,25 +14,25 @@
- Added TN hidden difficulty visibility for GM (ex: ?2?). - Added TN hidden difficulty visibility for GM (ex: ?2?).
- Added a selection for techniques with skill list. - Added a selection for techniques with skill list.
- RnK : - RnK :
- Added ability to apply the strife to the actor on final step. The chat message show the value taken in gray aside the total strife. - Added ability to directly apply the strife to the actor on final step. The chat message show the value taken in gray aside the total strife.
Syntaxe quick explanation : Technique syntaxe "quick" explanation :
- Difficulty can be : - Difficulty can be :
- Number : 1-9 - Number : 1-9
- Or specific syntaxe "@`S`:`prop1`" or "@`T`:`prop1`|`max`" or "@`T`:`prop1`|`max`(`prop2`)" : - Or specific syntaxe "@`S`:`prop1`" or "@`T`:`prop1`|`max`" or "@`T`:`prop1`|`max`(`prop2`)" :
- `@` fixed, trigger the parser - `@` fixed, trigger the parser
- `T` or `S` : `T`arget or `S`elf, define the actor to get the value. - `T` or `S` : `T`arget or `S`elf, define the actor to get the value.
- `prop1` / `prop2` : Can be any property in `actor` or `actor.data.data`. - `prop1` / `prop2` : Can be any property in `actor` or `actor.data.data`. Limitations: currently no `size` or `distance` (range).
- `|` separator, optional if no min/max. - `|` separator, optional if no min/max.
- `min` or `max` : Between the selected targets search for the min/max of `prop2`. If no `prop2` found, take `prop1` as `prop2` (irrelevant for `@S`). - `min` or `max` : Between the selected targets search for the min/max of `prop2`. If no `prop2` found, take `prop1` as `prop2` (irrelevant for `@S`).
- `(prop2)` : define the property for the actor selection in multiple target, can be omitted if same as `prop1`. - `(prop2)` : define the property for the actor selection in multiple target, can be omitted if same as `prop1`.
- Exemples : - Exemples :
- `@S:vigilance` : Difficulty will be my own vigilance - `@S:vigilance` : Difficulty will be my own vigilance
- `@T:vigilance|min` : Difficulty will be the vigilance from the target with the minimum vigilance (implicit) value. it's the same to wrote `@T:vigilance|min(vigilance)`. - `@T:vigilance|min` : Difficulty will be the vigilance from the target with the minimum vigilance (implicit) value. it's the same to wrote `@T:vigilance|min(vigilance)`.
- `@T:vigilance|max(statusRank)` : Difficulty will be the vigilance from the target with the maximum statusRank value - `@T:vigilance|max(statusRank)` : Difficulty will be the vigilance from the target with the maximum `statusRank` value.
- Skill can be : - Skill can be :
- Skill id : `melee`, `fitness`... - SkillId : `melee`, `fitness`...
- Skill category id : `scholar`, `martial`... - SkillCategoryId : `scholar`, `martial`...
- Or both in list, coma separated. - Or both in list, coma separated.
- Ids are english names in lower case, see `config.js / L5R5E.skills` for the list. - Ids are english names in lower case, see `config.js / L5R5E.skills` for the list.
- Exemples : - Exemples :

View File

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

View File

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

View File

@@ -820,7 +820,6 @@ export class HelpersL5r5e {
// execute a function when someone clicks in the document // execute a function when someone clicks in the document
html.on("focusout", (e) => { html.on("focusout", (e) => {
console.log("aaaaaaaaaa");
closeAllLists(e.target); closeAllLists(e.target);
}); });
} }

View File

@@ -56,39 +56,6 @@ 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 async preCreateChatMessage(document, data, options, userId) {
// Roll from DP have the "isL5r5eTemplate" option set
if (!document.isRoll || options?.isL5r5eTemplate || !document.data?.roll) {
return;
}
// Get the roll object
const roll = game.l5r5e.RollL5r5e.fromJSON(document.data.roll);
// Ignore non l5r roll (std or table)
if (!roll.l5r5e?.dicesTypes?.l5r) {
return;
}
// So now we have our wrong message only, redo it using the roll
await roll.toMessage();
// Return false to let the system known we handled this
return false;
}
/** /**
* Chat Message * Chat Message
*/ */

View File

@@ -248,6 +248,3 @@ 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));
// TODO Seem fixed in v9, remove in v10 if good
// Hooks.on("preCreateChatMessage", (document, data, options, userId) => HooksL5r5e.preCreateChatMessage(document, data, options, userId));

View File

@@ -5,7 +5,7 @@
<div class="l5r5e profil"> <div class="l5r5e profil">
<header class="part-header flexrow chat-profil"> <header class="part-header flexrow chat-profil">
<span class="chat-profil-element"> <span class="chat-profil-element">
<img class="profile-img" src="{{#if l5r5e.actor.img}}{{l5r5e.actor.img}}{{else}}icons/svg/mystery-man.svg{{/if}}" data-edit="img" alt="{{#if l5r5e.actor.name}}{{l5r5e.actor.name}}{{else}}mystery-man{{/if}}" /> <img class="profile-img" src="{{profileImg}}" data-edit="img" alt="{{#if l5r5e.actor.name}}{{l5r5e.actor.name}}{{else}}mystery-man{{/if}}" />
</span> </span>
<span class="chat-profil-element"> <span class="chat-profil-element">
@@ -106,7 +106,7 @@
</div> </div>
{{{tooltip}}} {{{tooltip}}}
<h4 class="l5r5e dice-total dice-total-std">{{total}}</h4> <h4 class="l5r5e dice-total dice-total-std">{{{total}}}</h4>
{{/if}} {{/if}}
</div> </div>

View File

@@ -138,7 +138,7 @@
{{/each}} {{/each}}
</table> </table>
{{!-- Strife selection --}} {{!-- Strife selection --}}
{{#if l5r5e.summary.strife}} {{#if showStrifeBt}}
<div class="form-group" style="width: 100%;"> <div class="form-group" style="width: 100%;">
<div class="form-fields"></div> <div class="form-fields"></div>
<div class="form-fields"> <div class="form-fields">