Skip to content

Commit

Permalink
feat: Pass the current property as a parameter for trait callbacks (#432
Browse files Browse the repository at this point in the history
)

This allows layout authors to write custom callbacks which can refer
back to the trait for that callback. With the current implementation,
the callback has access to the monster, but no reference to the current
trait being rendered.
  • Loading branch information
miscoined authored Jul 5, 2024
1 parent 5407a97 commit c9475de
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/settings/layout/blocks/ui/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -999,8 +999,10 @@ class TraitsModal extends MarkdownEnabledModal<TraitsItem> {
text: "The callback will receive the "
});
e.createEl("code", { text: "monster" });
e.createSpan({ text: " and " });
e.createEl("code", { text: "property" });
e.createSpan({
text: " parameter. The callback should return a string. For example: "
text: " parameters. The callback should return a string. For example: "
});

e.createEl("code", { text: "return monster.name" });
Expand Down
4 changes: 2 additions & 2 deletions src/view/ui/Traits.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
try {
const frame = document.body.createEl("iframe");
const funct = (frame.contentWindow as any).Function;
const func = new funct("monster", item.callback);
desc = func.call(undefined, monster) ?? desc;
const func = new funct("monster", "property", item.callback);
desc = func.call(undefined, monster, trait) ?? desc;
document.body.removeChild(frame);
} catch (e) {
new Notice(
Expand Down

0 comments on commit c9475de

Please sign in to comment.