From 7804c3d0923588ca4f935eded6fa5c32459f04d2 Mon Sep 17 00:00:00 2001 From: Chris Seieroe Date: Wed, 9 Mar 2022 18:11:51 -0800 Subject: [PATCH 1/7] initial POC with hard-coded roll --- src/module.js | 11 +++++++++++ templates/roll-dialog-messages.hbs | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/src/module.js b/src/module.js index bd38c98..8c0215e 100644 --- a/src/module.js +++ b/src/module.js @@ -266,6 +266,17 @@ function addMessageHook(dialog, html, data) { // add message at the end const formGroups = html.find(".form-group:last"); formGroups.after(message); + // add onClick for inline rolls + html.on("click", "a.dialog-roll", (event) => { + // get the formula from the button + const button = event.currentTarget; + const formula = button.dataset.formula; + debug("adding to input:", formula); + // add the formula to the bonus input + const dialogContent = button.closest(".dialog-content"); + const input = dialogContent.querySelector('input[name="bonus"]'); + input.value = !!input.value ? `${input.value} + ${formula}` : formula; + }); // reset dialog height const position = dialog.position; position.height = "auto"; diff --git a/templates/roll-dialog-messages.hbs b/templates/roll-dialog-messages.hbs index 714af89..391c70e 100644 --- a/templates/roll-dialog-messages.hbs +++ b/templates/roll-dialog-messages.hbs @@ -2,4 +2,8 @@ {{#each messages}}
{{{this}}}
{{/each}} +
+ + 1d6+2 +
From 039d94ea67edf7f967912935acaa3c16fd5a6b91 Mon Sep 17 00:00:00 2001 From: Chris Seieroe Date: Thu, 10 Mar 2022 02:05:32 -0800 Subject: [PATCH 2/7] use TextEditor.enrichHTML to create the deferred roll buttons for us --- src/messages.js | 13 ++++++++++++- src/module.js | 7 +++++++ templates/roll-dialog-messages.hbs | 4 ---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/messages.js b/src/messages.js index f430811..e56afc6 100644 --- a/src/messages.js +++ b/src/messages.js @@ -2,6 +2,8 @@ import { debug } from "./util.js"; class BaseMessage { constructor(actor) { + /** @type {Actor5e} */ + this.actor = actor; /** @type {EffectChangeData[]} */ this.changes = actor.effects .filter((effect) => !effect.isSuppressed && !effect.data.disabled) @@ -25,7 +27,16 @@ class BaseMessage { "modules/adv-reminder/templates/roll-dialog-messages.hbs", { messages } ); - setProperty(options, "dialogOptions.adv-reminder.message", message); + // enrich message, specifically replacing rolls + const enriched = TextEditor.enrichHTML(message, { + secrets: true, + documents: false, + links: false, + rolls: true, + rollData: this.actor.getRollData(), + }); + debug("message", message, "enriched", enriched); + setProperty(options, "dialogOptions.adv-reminder.message", enriched); } return messages; diff --git a/src/module.js b/src/module.js index 8c0215e..32b22ca 100644 --- a/src/module.js +++ b/src/module.js @@ -266,6 +266,13 @@ function addMessageHook(dialog, html, data) { // add message at the end const formGroups = html.find(".form-group:last"); formGroups.after(message); + // swap "inline-roll" class for "dialog-roll" + const inlineRolls = html.find("a.inline-roll"); + if (inlineRolls) { + debug("found inline-roll", inlineRolls); + inlineRolls.removeClass("inline-roll"); + inlineRolls.addClass("dialog-roll"); + } // add onClick for inline rolls html.on("click", "a.dialog-roll", (event) => { // get the formula from the button diff --git a/templates/roll-dialog-messages.hbs b/templates/roll-dialog-messages.hbs index 391c70e..714af89 100644 --- a/templates/roll-dialog-messages.hbs +++ b/templates/roll-dialog-messages.hbs @@ -2,8 +2,4 @@ {{#each messages}}
{{{this}}}
{{/each}} -
- - 1d6+2 -
From 78e6d47cf8fbd8a8733681c2b058d247ec6b0fcd Mon Sep 17 00:00:00 2001 From: Chris Seieroe Date: Thu, 10 Mar 2022 03:04:45 -0800 Subject: [PATCH 3/7] add styling for dialog-roll Copied styling from inline-roll. Left out some things that we don't need, so not everything that has inline-roll was copied over. Also added some comments to define the different blocks of styling --- css/adv-reminder.css | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/css/adv-reminder.css b/css/adv-reminder.css index 96aa2fb..4d03c8c 100644 --- a/css/adv-reminder.css +++ b/css/adv-reminder.css @@ -1,15 +1,15 @@ +/* Style the default buttons that aren't normal */ .dialog .dialog-buttons button.default.advantage { font-weight: bold; } - .dialog .dialog-buttons button.default.disadvantage { font-weight: bold; } - .dialog .dialog-buttons button.default.critical { font-weight: bold; } +/* Style the messages */ .dialog .dialog-content .adv-reminder-messages { background: rgba(0, 0, 0, 0.05); padding: 3px 5px; @@ -18,7 +18,19 @@ border: 1px solid #7a7971; border-radius: 3px; } - .adv-reminder-messages > div:not(:last-child) { margin-bottom: 10px; } + +/* Copy the style from "inline-roll" to "dialog-roll" */ +a.dialog-roll { + background: #ddd; + padding: 1px 4px; + border: 1px solid var(--color-border-dark-tertiary); + border-radius: 2px; + white-space: nowrap; + word-break: break-all; +} +a.dialog-roll i { + color: var(--color-text-dark-inactive); +} From 756882721a5138d1d2e6e8cfc1da4a0104a12bb6 Mon Sep 17 00:00:00 2001 From: Chris Seieroe Date: Thu, 10 Mar 2022 14:45:05 -0800 Subject: [PATCH 4/7] fix unit tests --- test/messages.test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/messages.test.js b/test/messages.test.js index 914c36b..5c7270e 100644 --- a/test/messages.test.js +++ b/test/messages.test.js @@ -22,6 +22,9 @@ globalThis.setProperty = (object, key, value) => { // set the value using the last key part lastObj[lastProp] = value; }; +globalThis.TextEditor = { + enrichHTML: (content, options) => content, +}; function createActorWithEffects(...keyValuePairs) { const effects = keyValuePairs.map(createEffect); @@ -87,6 +90,7 @@ function createActorWithEffects(...keyValuePairs) { }, }, effects, + getRollData: () => {}, }; } From e4185246fd051a5f51be54d8ddab642282498487 Mon Sep 17 00:00:00 2001 From: Chris Seieroe Date: Sun, 10 Apr 2022 18:17:19 -0700 Subject: [PATCH 5/7] add documentation with short video --- README.md | 4 ++++ button-in-message.webm | Bin 0 -> 72744 bytes 2 files changed, 4 insertions(+) create mode 100644 button-in-message.webm diff --git a/README.md b/README.md index 83251db..877151a 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,10 @@ In addition to active effects adding advantage or disadvantage, you can also add You have control over when the message appears and what it contains, including HTML formatting. In the screenshot above it just reminds you to roll with advantage on saving throws against poison. You are free to change it to just include `Dwarven Resilience` if that's all the reminder you need or `Advantage against poison` that doesn't mention saving throws since it only appears on CON saving throws. +You can also place deferred inline rolls (e.g. `[[/r 1d6]]`) in the messages that you can click on to add it to the Situational Bonus field. For example, if you want a reminder about Divine Fury damage, you can create a message, `[[/r 1d6+3]]{Divine Fury} damage on first hit`, to easily add that damage. + +![](button-in-message.webm) + The active effects keys are listed below and should be set with the change mode of `Custom`. - `flags.adv-reminder.message.all` for all rolls diff --git a/button-in-message.webm b/button-in-message.webm new file mode 100644 index 0000000000000000000000000000000000000000..991beaea7ff3baa7607d8aa3d813fc088e82ef1c GIT binary patch literal 72744 zcmcG#^OG+;@GdyEZQJ%4+qP}nwr$(CZQHiac;?K^XW#Gct-E{wfbAqz{ZywrPbWX6 zQ^65CC@ByQ4+0i`|8G16feAkcK?w(kdYBp82}cBh2!{oMV5tOJ00aFez_=gCayhO& zay>CBHKFKIRpu(SK}G)$!ceWZ`44T%^~C;XLs1>EP^k?DW|!-U`w!x&^!#TG0mePP z{l5bN0crkEy#GJse^@osY&3-+3Jb~w#>pDFo3nE zKlC^2{}(xhjUZr`u}C|Yg;UM}pYYruAd%Utt$xle|AGK-^JyB&80LM478a1UjRp}BtlGH zL_t(cSv2DRr1!raOiTu2O#WX!|J#@1|LdFeU#cemrOM38_CL82*;*O9J9^T)J91l0 z7K@ccimE9KsY)rxi$r@;GqEkNLf^d2r${ zAoBb032^WaxcfdR`5d_T&$0zDSpG7I0=WDYkk~m$xix_NeK-Y}9Qhjz0pLIRG5`5v z9{ny5*)*KI5{f~P6jnL{tXtmN; zy!w{M{cd$|K|8>SajwHv8Xq;=O}X~fKljBia6ME1LrC~yuJCE__R9nz>e*lNxhdj4 z!r4{xy5Ca;Ods>#$sJHd~)`KCR_+; zhtTR$z#b2#RjXHvHVR11S>jA6XNgeDiV&*(xOAuCk6b<-d?eEzR>G%)8o)zdJj>L! z1A)~o3{7enMmH5gjkCwwek6jW<;^bu=Ca*iDU?o`z?@`_TjV~h&>RAiir&i4&@f9) zTf9&{VDg@d^Ddy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