RPG Dice Roller Integration

RPG Dice Roller Integration en

Installations 2 Likes 0

This plugin allows you to create dice macros in any entity, and potentially transclude them into other pages (or even sidebars!). Dice rolling logic is handled by the RPG Dice Roller library – please follow the link for instructions and examples of syntax and available features.

Overview

  • Creates an input field where you can specify a detailed dice roll macro. The dice notation can be entered and changed on the fly, or preset and optionally locked. Press Enter or click the Roll button to see the result.
  • A short animation plays before showing your result. This avoids confusion when you roll the same result consecutively and ask yourself whether you correctly clicked the button =)
  • Only your total is displayed, but you can hover it to open a tooltip that details each die rolled and which ones were kept, dropped, exploded, etc. based on the parameters of your macro.

Creating macros

  1. Create an entity of any type to hold a single macro and give it a recognizable name (e.g. "d20 with advantage" or "Cate’s Cone of Cold Damage"). You may want to create a custom module to keep things tidy if you plan to make several.
  2. Fill in the attributes:
    • Macro Name: Optional field. Will be displayed as a title above the dice roller if specified.
    • Dice Notation: Optional field. Will pre-fill the dice roller notation field if provided. Otherwise the field will be blank, which works well for an all-purpose instance of the dice roller.
    • Disable Input: If ticked, this checkbox will prevent editing the notation field, effectively allowing only your specified macro to be rolled in this dice roller instance. Note that this option is ignored if Dice Notation is empty.
  3. Your macro is now ready to be used in the entity’s Attributes page (or you can create a post set to show attributes to have it available on the overview). See further instructions below for ways to transclude it into other entities.

Transcluding a macro into other entities

Transcluding a macro is very easy. Simply create a mention to the macro’s entity using advanced mention syntax (which you can enable in your profile settings under Appearance), then add the field:attributes property like so: [note:12345|field:attributes]. Instead of linking to the entity, the actual dice roller will be rendered in an iframe.

I recommend adding the following CSS rule to your campaign styles to keep the dice roller iframe only as big as needed. This will apply to any entity tagged "Dice Macro" and transcluded with the field:attributes syntax. Unfortunately, this cannot be applied directly via the plugin since its CSS is only loaded inside the iframe, and therefore cannot affect the iframe’s outer dimensions.

/* Dice Macro transclusion iframe */
.entity-attributes-render[data-entity-tags~="dicemacro"] {
  height: 120px;
  max-width: 300px;
}

If you use different kinds of macros and tag them accordingly, you can even create different rules to have custom dimensions based on other tags as well.

Transcluding a macro into a Pins sidebar

Transclusion also works in attribute values, so you can pin a dice roller to any entity’s sidebar using the same method! Simply create a standard attribute, put in the mention with the same syntax as above and click the pin icon to pin the attribute. To account for the much smaller area, you may want to use macros specifically made for this purpose, without a title (the attribute’s name can fulfill that role) and with Disable Input checked to keep only the button and result visible.

Customizing the dice roller

The dice roller’s main container includes the data-entity-tags attribute, allowing you to style various rollers based on their entity’s tags. For example, you could have "Attack Macro" and "Damage Macro" tags on various macros and style rollers differently for each category. These tags are given in slug form, as in other parts of Kanka. For example, to give a much bigger title to those Attack Macros:

.rpg-dice-roller[data-entity-tags~="attackmacro"] h4 { font-size: 20px }

RPG Dice Roller is shared under the MIT license.

Want to show appreciation for my plugins or request one-on-one CSS help? I accept tips on Ko-fi (no account needed): Support me on Ko-fi.com

Latest version 0.1

Released 1 month ago

 Initial release. Testers and feedback wanted! Please expect changes.