Skip to content

Commit

Permalink
Pass actor or item in the context of macro.execute
Browse files Browse the repository at this point in the history
  • Loading branch information
farling42 committed Jan 14, 2025
1 parent 276ab19 commit 4310e4e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 1.5.5

- When a macro is triggered from some text (see 1.5.0) pass `actor` or `item` within the scope of the macro so it can be referenced by the macro code.

## 1.5.4

- Mark as NOT compatible with Foundry V13.
Expand Down
11 changes: 9 additions & 2 deletions scripts/pdf-editable.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ export async function initEditor(html, id_to_display) {
add_clickable_text(span, macrouuid, span_click_edit, (document instanceof Actor) ? LABEL_DOCTYPE_ACTOR : LABEL_DOCTYPE_ITEM);
} else {
// Only highlight the fields which have macros mapped to them.
if (macrouuid) add_clickable_text(span, macrouuid, span_click);
if (macrouuid) add_clickable_text(span, macrouuid, span_click.bind(document) );
}
}
}
Expand Down Expand Up @@ -857,7 +857,14 @@ async function span_click(event) {
// FVTT 10 has actor and token fields.
// FVTT 12 has actor, token, speaker, event fields.
// Invoke _executeScript ourselves!
macro.execute({ event, label: span.textContent.trim() });
let context = {
event,
label: span.textContent.trim()
}
if (this instanceof Actor) context.actor = this;
if (this instanceof Item) context.item = this;

macro.execute(context);
}

async function span_click_edit(event) {
Expand Down

0 comments on commit 4310e4e

Please sign in to comment.