Skip to content

Commit

Permalink
Make items clickable in the end of round dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
juanferrer committed Jan 5, 2024
1 parent 05e568c commit eb0a797
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
27 changes: 27 additions & 0 deletions src/module/dialog/endofround.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,33 @@ export class DLEndOfRound extends FormApplication {
_parent.children[2].style.display = 'none'
}
})

html.find('.item-edit').click(async event => {
const itemId = event.currentTarget.closest("[data-item-id]").dataset.itemId
const actorId = event.currentTarget.closest("[data-actor-id]").dataset.actorId
const actor = this.object.combatants.find(c => c.actor._id === actorId).actor
const item = actor.items.get(itemId)
item.sheet.render(true)
})

html.find('.rollable, .item-roll').click(async event => {
event.preventDefault()
const element = event.currentTarget
const dataset = element.dataset
if (dataset.roll) {
const roll = new Roll(dataset.roll, this.actor.system)
const label = dataset.label ? `Rolling ${dataset.label}` : ''
await roll.roll().toMessage({
speaker: ChatMessage.getSpeaker({actor: this.actor}),
flavor: label,
})
} else {
const itemId = event.currentTarget.closest("[data-item-id]").dataset.itemId
const actorId = event.currentTarget.closest("[data-actor-id]").dataset.actorId
const actor = this.object.combatants.find(c => c.actor._id === actorId).actor
await actor.rollItem(itemId, {event: event})
}
})
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/module/item/item.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {deleteActorNestedItems} from './nested-objects'
import {DemonlordActor} from '../actor/actor'
import { DLEndOfRound } from '../dialog/endofround'

export class DemonlordItem extends Item {
/** @override */
Expand All @@ -22,6 +23,12 @@ export class DemonlordItem extends Item {
openSheets = openSheets.filter(s => ['path', 'ancestry', 'creaturerole', 'item', 'relic'].includes(s.object.type))
openSheets.forEach(s => s.render())
}

// Refresh any open endoftheround dialogs
if (this.type === 'endoftheround') {
const openSheets = Object.entries(ui.windows).map(i => i[1]).filter(i => i instanceof DLEndOfRound)
openSheets.forEach(s => s.render())
}
}

/** @override */
Expand Down
7 changes: 5 additions & 2 deletions src/templates/dialogs/endofround-dialog.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="form-block">
<ol class="creature-list">
{{#each creatures as |creature id|}}
<li class="creature-entry combatant actor">
<li class="creature-entry combatant actor" data-actor-id="{{creature.actor._id}}">
<div class="header">
<img class="token-image" src="{{creature.actor.img}}" title="{{creature.token.name}}"/>
<h3 style="font-weight:bold; border: none">{{creature.token.name}}</h3>
Expand All @@ -16,7 +16,10 @@
<ol class="effects">
{{#each creature.endOfRoundEffects as |endOfRoundEffect id|}}
<li class="effect" style="margin-bottom: 4px">
<div style="font-weight: bold">{{endOfRoundEffect.name}}</div>
<div style="display: flex; align-items: center;" data-item-id="{{endOfRoundEffect._id}}">
<img class='dl-clickable-nored item-edit' src="{{endOfRoundEffect.img}}" title="{{endOfRoundEffect.name}}" width="15" height="15"/>
<label class="dl-clickable item-roll" style="padding-left: 5px;">{{endOfRoundEffect.name}}</label>
</div>
<div>{{{endOfRoundEffect.system.enrichedDescription}}}</div>
</li>
{{/each}}
Expand Down

0 comments on commit eb0a797

Please sign in to comment.