Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deferred inline roll in messages add to situational bonus #23

Merged
merged 7 commits into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

![Inline roll damage button](screenshot3.png?raw=true)

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
Expand Down Expand Up @@ -81,3 +85,5 @@ Notes about other modules.
- Does not show messages if Midi QOL is configured to fast forward rolls

[Minimal Rolling Enhancements for D&D5e](https://foundryvtt.com/packages/mre-dnd5e) This module works with MRE, making rolls with advantage/disadvantage and showing messages if you hold the "Roll Dialog Modifier Key" (an MRE setting).

[Dynamic effects using Active Effects](https://foundryvtt.com/packages/dae) If you're using the message feature to add inline roll formulas, you need to use DAE version 0.10.01 or newer. Earlier versions would evaluate the deferred die roll in the active effect's value, making the button not work.
18 changes: 15 additions & 3 deletions css/adv-reminder.css
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
Binary file added screenshot3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion src/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,24 @@ 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
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";
Expand Down
4 changes: 4 additions & 0 deletions test/messages.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -87,6 +90,7 @@ function createActorWithEffects(...keyValuePairs) {
},
},
effects,
getRollData: () => {},
};
}

Expand Down