Skip to content

Commit

Permalink
Provide a subtitle with actions when using lores
Browse files Browse the repository at this point in the history
Current it will show a subtitle like "Lie (PF2E.ActionsCheck.legal-lore)" when
trying to use a skill that doesn't have a translation, which no lore will.

Detect the lack of translation and fall back to the "PF2E.ActionsCheck.x"
translation format using the label of the skill.  This will result in "Lie
(Legal Lore Check)" if the skill was labeled in that way.
  • Loading branch information
xyzzy42 committed Nov 7, 2024
1 parent 6bb0bba commit 7353ad0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/module/system/action-macros/basic/escape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function escapeCheckContext<ItemType extends ItemPF2e<ActorPF2e>>(
);

if (highest) {
const { checkType, stat: slug, subtitle } = ActionMacroHelpers.resolveStat(highest.statistic.slug);
const { checkType, stat: slug, subtitle } = ActionMacroHelpers.resolveStat(highest.statistic.slug, opts.actor);
return {
modifiers: data.modifiers,
rollOptions: highest.rollOptions,
Expand Down
12 changes: 9 additions & 3 deletions src/module/system/action-macros/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ import type {
} from "./types.ts";

class ActionMacroHelpers {
static resolveStat(stat: string): {
static resolveStat(
stat: string,
actor: ActorPF2e,
): {
checkType: CheckType;
property: string;
stat: string;
Expand All @@ -54,11 +57,14 @@ class ActionMacroHelpers {
default: {
const slug = sluggify(stat);
const property = `skills.${slug}`;
let subtitle = `PF2E.ActionsCheck.${stat}`;
if (!game.i18n.has(subtitle))
subtitle = game.i18n.format("PF2E.ActionsCheck.x", { type: actor.skills?.[stat]?.label ?? null });
return {
checkType: "skill-check",
property,
stat,
subtitle: `PF2E.ActionsCheck.${stat}`,
subtitle,
};
}
}
Expand All @@ -68,7 +74,7 @@ class ActionMacroHelpers {
options: CheckContextOptions<ItemType>,
data: CheckContextData<ItemType>,
): CheckMacroContext<ItemType> | undefined {
const { checkType: type, property, stat: slug, subtitle } = this.resolveStat(data.slug);
const { checkType: type, property, stat: slug, subtitle } = this.resolveStat(data.slug, options.actor);
const statistic =
options.actor.getStatistic(data.slug) ?? (fu.getProperty(options.actor, property) as StrikeData);
if (!statistic) {
Expand Down

0 comments on commit 7353ad0

Please sign in to comment.