fantasy-statblocks
fantasy-statblocks copied to clipboard
Feature Request: Template String Notation Block
This would be very useful for create complex custom layouts. Because it would allow us to run JS to format the data on view.
For example, one could take the normal stats and print only the modifiers without even printing the keys.
A rudimentary version of this should not be difficult to implement. Ideally one could write the template syntax with common readable variable names like such:
${ac} | ${hp}
But that might be a little more difficult than just taking the implementation of subheading and using that as such
${subheading[0]} | ${subheading[1]}
Im not familiar at all with svelte and still learning TS. So im worried im gona break something I don't understand. But on the render side something like this should work right?
<script lang="ts">
import type { Monster } from "@types";
import type { StringTemplateItem } from "src/data/constants";
import { stringify } from "src/util/util";
export let monster: Monster;
export let item: StringTemplateItem;
const templateItems: string[] = [];
for (let property of item.properties) {
if (property in monster) {
templateItems.push(`${stringify(monster[property])}`);
}
}
// it would have access to templateItems
const text = new Function("return " + item.templateString + " ").call(item.templateString);
</script>
{#if templateItems.length}
<div class="subheading">
{text}
</div>
{/if}
You can already supply a callback for the "property" block type in layouts, this would be basically the same thing, right?
You are totally right. I missed that you could do this somehow. Thanks.
Up on further testing. Any particular reason as to why it is not posible to specify a callback for other blocks a part from the property block? For example the heading block