-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] New Tidy 5e Sheets Compatibility #63
Comments
hello @kgar , thanks for writing up, didn't know about the API, and that's awesome. I think I will need that for this and another module https://github.com/misthero/dnd5e-custom-skills. That module adds skills and abilities and has been a litte hard to integrate it with tidy. If you can throw a couple of hints at me, about where to start I hope I can figure out the rest. |
Thanks for working with me on this. Acquiring the API InstanceFirst, you acquire the API through a Tidy custom hook: Hooks.once("tidy5e-sheet.ready", (api) => {
// TODO: Add some awesome stuff!
}); Alternatively, and this is usually for the World Scripter crowd, the API can be acquired from the module, but there are caveats to this approach: const api = game.modules.get('tidy5e-sheet')?.api ?? game.modules.get('tidy5e-sheet-kgar')?.api; Caveats:
|
Injecting Standalone ContentIf you have content that is meant to be placed in one location, you can use the content registration functions. Here is an example of registering content for a character: Hooks.once("tidy5e-sheet.ready", (api) => {
api.registerCharacterContent(
new api.models.HtmlContent({
html: `<a title="Example Button" class="my-custom-icon"><i class="fas fa-user"></i></a>`,
injectParams: {
selector: `[data-tidy-sheet-part="${api.constants.SHEET_PARTS.NAME_CONTAINER}"]`,
position: "beforebegin",
},
onRender: (params) => {
params.element
.querySelector(".my-custom-icon")
.addEventListener("click", () => alert("Clicked custom PC icon"));
},
})
);
}); When you register content in this way, Tidy knows to clear this content and refresh it any time the default sheets would normally have re-rendered the entire sheet. If your content has HTML inputs with the I have deliberately chosen to use |
Sheet PartsI'm on a quest to provide With that said, it's a work in progress. You'll see sheet parts throughout the sheets in the DOM: Meanwhile, I also have a consolidated list of the sheet parts with general explanations in the API docs here: https://kgar.github.io/foundry-vtt-tidy-5e-sheets/classes/Tidy5eSheetsApi.html#constants Below the constants section, each sheet part that currently exists in the wild has an explanation attached to it. Need Specific Sheet Parts, Let Me Know 🙏I'm in the business of adding more sheet parts. I'm on a fairly short release cycle (multiple per day if I have to, but usually 1 release every 2-4 days). I will make a special effort if a module developer needs API stuff and I'm certain how to provide it. |
That's what I have for you for now. Let me know if you have any questions, comments, ideas, etc. |
Thanks for the heads up, I tried the implementation, and the tidy5e-sheet.ready works well, but I think in my case I should keep using the .renderActorSheet hook, since I need the current actor document before adding the html. I need to know if the sheet is for a player character and read the actor flags to change the icon. Any idea? |
I see what you mean. You can use a callback function when registering HTML content, which should give you the flexibility you need: Hooks.once("tidy5e-sheet.ready", (api) => {
api.registerCharacterContent(
new api.models.HtmlContent({
html: (data) => { // 👈 `data` is the actor sheet context data that comes with `renderActorSheet`
const myFlag = data.actor.flags['my-module.my-flag'];
return myFlag ? `<span class="my-content">👍</span>` : `<span class="my-content">😱</span>`;
},
injectParams: {
selector: `[data-tidy-sheet-part="${api.constants.SHEET_PARTS.NAME_CONTAINER}"]`,
position: "beforebegin",
},
enabled: (data) => true, // 👈 If you only show this content based on a setting, you can check that here; `data` is the actor sheet context data
onRender: (params) => {
params.element
.querySelector(".my-content")
?.addEventListener("click", () => alert("Clicked custom PC icon"));
},
})
);
}); In the previous example with using |
Was there any update on this? I would love to see it work with tidy5e sheets |
If it helps, Tidy has a Hooks.on('tidy5e-sheet.renderActorSheet', (app, element, data) => {
const someHtml = `<h1 data-tidy-render-scheme="handlebars">Hello</h1>`;
$('.some-class').append(someHtml);
}); If you want to reuse your template without putting Tidy attributes on it, you can wrap your result template code as follows: let rendered_html = '<p>rendered template here</p>';
// When type is "tidy", wrap it
if (type === 'tidy') {
rendered_html = `<div style="display: contents;" data-tidy-render-scheme="handlebars">${rendered_html}</div>`
} I realize the API approach is a lot, so these days, I encourage using the tidy hook and the |
the module works on tidy (by my testing) just the fancy spell points tracking bar of the dndv3 character sheet is not there, but functionally it should calculate spell points correctly, make sure you updated to version 2.2.1 of the spell points module. for now you can just flag as favourite the spell points item to see it in the first page of the character sheet. |
The user who reported this on my repo retested and is good to go. |
Hello, I am the author of the new Tidy 5e Sheets rewrite. The new sheets are using svelte and have their own rendering rules and HTML structure, so they do not integrate automatically the way default and default-like sheets do.
As a result, I have been going from module to module to request the opportunity to establish intentional compatibility with my sheets. I have an API for injecting content, and I will gladly volunteer a pull request and/or sample code for integrating.
Recently, I had a github issue requesting compatibility between our modules: kgar/foundry-vtt-tidy-5e-sheets#247
If there is any content that is injected into the sheet during rendering, that would be what needs the API to be injected successfully.
Also, I have special selectors available for injecting things.
For now, I just wanted to start the discussion, as I'm doing some compatibility work elsewhere, but I can provide you some neat options for where to put things like the "This character uses Spell Points" toggle.
Wherever possible, I try to make integration out-of-the-way and minimal, and my integration API / offerings are under active development and evolving based on module author needs.
I hope to work together. Our mutual users would love for us to team up.
The text was updated successfully, but these errors were encountered: