Skip to content

Commit

Permalink
[#4942] Ignore parentheses when slugifying names, slugify save
Browse files Browse the repository at this point in the history
Changes the slugify method used by enrichers to remove
parentheses, allowing entering check enrichers in a format that
matches the books: `[[/check DC 15 Strength (Athletics)]]`.

Also slugifies values passed to the save enricher to allow for
capitalization in ability names.

Fixes a bug if the lookup enricher is used on journal pages that
don't provide the `getRollData` method.

Closes #4942
  • Loading branch information
arbron committed Dec 30, 2024
1 parent 3e8c981 commit 6035882
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions module/enrichers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import simplifyRollFormula from "./dice/simplify-roll-formula.mjs";
import * as Trait from "./documents/actor/trait.mjs";
import { rollItem } from "./documents/macro.mjs";

const slugify = value => value?.slugify().replaceAll("-", "");
const slugify = value => value?.slugify().replaceAll("-", "").replaceAll("(", "").replaceAll(")", "");

/**
* Set up custom text enrichers.
Expand Down Expand Up @@ -333,10 +333,10 @@ async function enrichAward(config, label, options) {
*/
async function enrichCheck(config, label, options) {
for ( let value of config.values ) {
value = foundry.utils.getType(value) === "string" ? slugify(value) : value;
if ( value in CONFIG.DND5E.enrichmentLookup.abilities ) config.ability = value;
else if ( value in CONFIG.DND5E.enrichmentLookup.skills ) config.skill = value;
else if ( value in CONFIG.DND5E.enrichmentLookup.tools ) config.tool = value;
const slug = foundry.utils.getType(value) === "string" ? slugify(value) : value;
if ( slug in CONFIG.DND5E.enrichmentLookup.abilities ) config.ability = slug;
else if ( slug in CONFIG.DND5E.enrichmentLookup.skills ) config.skill = slug;
else if ( slug in CONFIG.DND5E.enrichmentLookup.tools ) config.tool = slug;
else if ( Number.isNumeric(value) ) config.dc = Number(value);
else config[value] = true;
}
Expand Down Expand Up @@ -419,8 +419,9 @@ async function enrichCheck(config, label, options) {
* ```
*/
async function enrichSave(config, label, options) {
for ( const value of config.values ) {
if ( value in CONFIG.DND5E.enrichmentLookup.abilities ) config.ability = value;
for ( let value of config.values ) {
const slug = foundry.utils.getType(value) === "string" ? slugify(value) : value;
if ( slug in CONFIG.DND5E.enrichmentLookup.abilities ) config.ability = slug;
else if ( Number.isNumeric(value) ) config.dc = Number(value);
else config[value] = true;
}
Expand Down Expand Up @@ -689,7 +690,8 @@ function enrichLookup(config, fallback, options) {
return null;
}

const data = activity ? activity.getRollData().activity : options.rollData ?? options.relativeTo?.getRollData();
const data = activity ? activity.getRollData().activity : options.rollData
?? options.relativeTo?.getRollData?.() ?? {};
let value = foundry.utils.getProperty(data, keyPath.substring(1)) ?? fallback;
if ( value && style ) {
if ( style === "capitalize" ) value = value.capitalize();
Expand Down

0 comments on commit 6035882

Please sign in to comment.