FIX: Attack counters

master
U~man 2020-07-30 15:26:47 +02:00
parent 48e1d8eb95
commit ade4cd7d40
1 changed files with 14 additions and 35 deletions

View File

@ -136,41 +136,20 @@ export class OseActorSheetMonster extends OseActorSheet {
}); });
} }
async _onCountChange(event) { async _resetCounters(event) {
event.preventDefault(); const weapons = this.actor.data.items.filter(i => i.type === 'weapon');
const itemId = event.currentTarget.closest(".item").dataset.itemId; for (let wp of weapons) {
const item = this.actor.getOwnedItem(itemId); const item = this.actor.getOwnedItem(wp._id);
if (event.target.dataset.field == "value") { await item.update({
return item.update({ data: {
"data.counter.value": parseInt(event.target.value), counter: {
}); value: parseInt(wp.data.counter.max),
} else if (event.target.dataset.field == "max") { },
return item.update({ },
"data.counter.max": parseInt(event.target.value),
}); });
} }
} }
async _resetCounters(event) {
$(event.currentTarget)
.closest(".abilities")
.find(".item")
.each(async (_, el) => {
let itemId = el.dataset.itemId;
const item = this.actor.getOwnedItem(itemId);
if (item.data.type == "weapon") {
await item.update({
_id: item.id,
data: {
counter: {
value: parseInt(item.data.data.counter.max),
},
},
});
}
});
}
/** /**
* Activate event listeners using the prepared sheet HTML * Activate event listeners using the prepared sheet HTML
* @param html {HTML} The prepared HTML object ready to be rendered into the DOM * @param html {HTML} The prepared HTML object ready to be rendered into the DOM
@ -242,10 +221,10 @@ export class OseActorSheetMonster extends OseActorSheet {
actorObject.rollAppearing({ event: event, check: check }); actorObject.rollAppearing({ event: event, check: check });
}); });
html // html
.find(".counter input") // .find(".counter input")
.click((ev) => ev.target.select()) // .click((ev) => ev.target.select())
.change(this._onCountChange.bind(this)); // .change(this._onCountChange.bind(this));
html.find(".hp-roll").click((ev) => { html.find(".hp-roll").click((ev) => {
let actorObject = this.actor; let actorObject = this.actor;