8: Add rolls to items on actor sheets

- Utilized the revisions made to roll syntax to allow for rollable
  buttons on item lists on actor sheets. Rolls are evaluated using
  `@items.ITEM.KEY`, where ITEM is the item name (slugified), and KEY is
  an attribute key for a formula attribute.
This commit is contained in:
Matt Smith 2020-08-09 16:37:16 -05:00
parent 00dfec6014
commit 786d4095a9
5 changed files with 29 additions and 0 deletions

View file

@ -34,6 +34,12 @@ export class SimpleActorSheet extends ActorSheet {
activateListeners(html) { activateListeners(html) {
super.activateListeners(html); super.activateListeners(html);
// Handle rollable attributes.
html.find('.items .rollable').click(ev => {
let r = new Roll($(ev.currentTarget).data('roll'), this.actor.getRollData());
r.roll().toMessage();
});
// Everything below here is only needed if the sheet is editable // Everything below here is only needed if the sheet is editable
if (!this.options.editable) return; if (!this.options.editable) return;

View file

@ -82,4 +82,11 @@ Hooks.once("init", async function() {
} }
} }
/**
* Slugify a string.
*/
Handlebars.registerHelper('slugify', function(value) {
return value.slugify({strict: true});
});
}); });

View file

@ -94,6 +94,11 @@
.worldbuilding .item-list .item-controls { .worldbuilding .item-list .item-controls {
flex: 0 0 36px; flex: 0 0 36px;
} }
.worldbuilding .item-list .item-button {
height: 100%;
line-height: 1;
font-size: 11px;
}
.worldbuilding .attributes-header { .worldbuilding .attributes-header {
padding: 5px; padding: 5px;
margin: 5px 0; margin: 5px 0;

View file

@ -105,6 +105,12 @@
.item-controls { .item-controls {
flex: 0 0 36px; flex: 0 0 36px;
} }
.item-button {
height: 100%;
line-height: 1;
font-size: 11px;
}
} }
/* Attributes */ /* Attributes */

View file

@ -40,6 +40,11 @@
<li class="item flexrow" data-item-id="{{item._id}}"> <li class="item flexrow" data-item-id="{{item._id}}">
<img src="{{item.img}}" title="{{item.name}}" width="24" height="24"/> <img src="{{item.img}}" title="{{item.name}}" width="24" height="24"/>
<h4 class="item-name">{{item.name}}</h4> <h4 class="item-name">{{item.name}}</h4>
{{#each item.data.attributes as |itemAttr key|}}
{{#if (eq itemAttr.dtype "Formula")}}
<button class="item-button rollable" data-roll="@items.{{slugify item.name}}.{{key}}" title="{{itemAttr.value}}">{{itemAttr.label}}</button>
{{/if}}
{{/each}}
<div class="item-controls"> <div class="item-controls">
<a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a> <a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a>
<a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a> <a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>