Skip to content

Commit

Permalink
add skill actions tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
reonZ committed Oct 23, 2024
1 parent 303cb97 commit e3fe325
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
3 changes: 2 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@
"title": "Skills",
"roll": "Roll: {name}",
"proficient": "Proficient",
"follow": "Follow the Expert"
"follow": "Follow the Expert",
"alternate": "[Right Click] Variants Menu"
},
"extras": {
"title": "Extras",
Expand Down
2 changes: 1 addition & 1 deletion src/hud/sidebar/extras.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const EXTRAS_ACTIONS_UUIDS = ACTIONS.map((action) => action.uuid);
let actionsCache: PreparedSkillAction[] | null = null;
function getActions(actor: ActorPF2e) {
actionsCache ??= ACTIONS.map((x) => ({
...prepareStatisticAction(x.statistic, x),
...prepareStatisticAction(x.statistic, x, false),
proficient: true,
}));

Expand Down
24 changes: 21 additions & 3 deletions src/hud/sidebar/skills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,8 @@ const actionLabels: Record<string, string> = {};

function prepareStatisticAction(
statistic: string | undefined,
rawAction: SharedAction | RawSkillAction
rawAction: SharedAction | RawSkillAction,
withAlternate: boolean
) {
const [actionId, action]: [string, Omit<RawSkillAction, "actionId">] =
typeof rawAction === "string"
Expand All @@ -565,27 +566,35 @@ function prepareStatisticAction(

const variants: ActionVariant[] | MapVariant[] | undefined = (() => {
if (action.map) {
const tooltip = createActionTooltip(label, withAlternate);

return [
{
tooltip,
label: game.i18n.localize("PF2E.Roll.Normal"),
},
{
map: 1,
tooltip,
agile: action.agile,
label: getMapLabel(1, !!action.agile),
},
{
map: 2,
tooltip,
agile: !!action.agile,
label: getMapLabel(2, !!action.agile),
},
] satisfies MapVariant[];
}

return action.variants?.map((slug) => {
const label = getSkillVariantName(actionId, slug);

return {
slug,
label: getSkillVariantName(actionId, slug),
label,
tooltip: createActionTooltip(label, withAlternate),
} satisfies ActionVariant;
});
})();
Expand All @@ -606,6 +615,7 @@ function prepareStatisticAction(
actionId,
label,
dataset,
tooltip: createActionTooltip(label, withAlternate),
filterValue: filterValues.join("|"),
dragImg:
ACTION_IMAGES[actionId] ??
Expand All @@ -614,6 +624,11 @@ function prepareStatisticAction(
} satisfies PreparedSkillAction;
}

function createActionTooltip(name: string, withAlternate: boolean) {
let tooltip = localize("sidebars.skills.roll", { name });
return withAlternate ? `${tooltip}<br>${localize("sidebars.skills.alternate")}` : tooltip;
}

let skillsCache: PreparedSkill[] | null = null;
function finalizeSkills(actor: ActorPF2e): FinalizedSkill[] {
if (!skillsCache) {
Expand All @@ -622,7 +637,7 @@ function finalizeSkills(actor: ActorPF2e): FinalizedSkill[] {

skillsCache ??= skills.map((rawSkill) => {
const actions = rawSkill.actions.map((rawAction) =>
prepareStatisticAction(rawSkill.slug, rawAction)
prepareStatisticAction(rawSkill.slug, rawAction, true)
);
const label = game.i18n.localize(
rawSkill.slug === "perception"
Expand Down Expand Up @@ -1051,17 +1066,20 @@ type PreparedSkill = {

type MapVariant = {
label: string;
tooltip: string;
map?: number;
agile?: boolean;
};

type ActionVariant = {
slug: string;
label: string;
tooltip: string;
};

type PreparedSkillAction = Omit<RawSkillAction, "variants"> & {
label: string;
tooltip: string;
filterValue: string;
variants: (MapVariant | ActionVariant)[] | undefined;
dataset: SkillActionDataset;
Expand Down
4 changes: 2 additions & 2 deletions templates/partials/statistic-action.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</div>
<div class="controls">
{{#unless (or action.variants (not action.proficient))}}
<a data-action="roll-statistic-action">
<a data-action="roll-statistic-action" data-tooltip="{{action.tooltip}}">
<i class="fa-solid fa-dice-d20"></i>
</a>
{{/unless}}
Expand All @@ -24,7 +24,7 @@
<div class="variant" data-action="roll-statistic-action" {{#if variant.slug}}
data-variant="{{variant.slug}}" {{/if}} {{#if variant.map}} data-map="{{variant.map}}"
{{/if}} {{#if variant.agile}} data-agile="{{variant.agile}}" {{/if}} draggable="true"
data-drag-parent=".item"
data-drag-parent=".item" data-tooltip="{{variant.tooltip}}"
data-filter-value="{{variant.label}}|{{../action.label}}{{#if ../skill}}|{{../skill}}{{/if}}">
{{{variant.label}}}
</div>
Expand Down
6 changes: 4 additions & 2 deletions templates/sidebars/skills.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
</div>
{{#each skills as |skill|}}
<header data-filter-value="{{skill.filterValue}}">
<a data-action="roll-skill" data-slug="{{skill.slug}}">
<a data-action="roll-skill" data-slug="{{skill.slug}}"
data-tooltip="{{@root.i18n 'roll' name=skill.label}}">
<span>{{signedInteger skill.mod}}</span> {{skill.label}}
</a>
{{#if @root.isCharacter}}
Expand All @@ -40,7 +41,8 @@
<div class="item lore" data-filter-value="{{lore.slug}}" data-action-id="lore"
data-item-uuid="{{lore.uuid}}" draggable="true">
<div class="name">
<a data-action="roll-skill" data-slug="{{lore.slug}}">
<a data-action="roll-skill" data-slug="{{lore.slug}}"
data-tooltip="{{@root.i18n 'roll' name=lore.label}}">
<span style="width: {{@root.lores.modifierWidth}}ch">
{{lore.modifier}}
</span>
Expand Down

0 comments on commit e3fe325

Please sign in to comment.