Add possibility to enable / disable effects in the actor sheet

This commit is contained in:
Johannes Loher 2021-07-22 02:50:16 +02:00
parent bb67788abc
commit 2ef58012c6
2 changed files with 22 additions and 4 deletions

View file

@ -131,6 +131,7 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
html.find(".item-change").on("change", this.onItemChange.bind(this));
html.find(".control-effect").on("click", this.onControlEffect.bind(this));
html.find(".change-effect").on("change", this.onChangeEffect.bind(this));
html.find(".rollable-item").on("click", this.onRollItem.bind(this));
@ -196,13 +197,14 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
* - Text input: string
* - Number: number
* @param el - The input element to collect the value of
* @param inverted - Whether or not the value should be inverted
*/
private getValue(el: HTMLFormElement): boolean | string | number {
private getValue(el: HTMLFormElement, inverted = false): boolean | string | number {
// One needs to differentiate between e.g. checkboxes (value="on") and select boxes etc.
// Checkbox:
if (el.type === "checkbox") {
const value: boolean = el.checked;
return value;
return inverted ? !value : value;
}
// Text input:
@ -282,6 +284,22 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
li.slideUp(200, () => this.render(false));
}
protected onChangeEffect(event: JQuery.ChangeEvent): void {
event.preventDefault();
const currentTarget = $(event.currentTarget);
const element: HTMLFormElement = currentTarget.get(0);
const id = currentTarget.parents(".effect").data("effectId");
const property: string | undefined = currentTarget.data("property");
const inverted = Boolean(currentTarget.data("inverted"));
if (element.disabled || element.getAttribute("disabled")) return;
if (property === undefined) {
throw TypeError("HTML element does not provide 'data-property' attribute");
}
const newValue = this.getValue(element, inverted);
this.actor.updateEmbeddedDocuments("ActiveEffect", [{ _id: id, [property]: newValue }]);
}
/**
* Handle clickable item rolls.
* @param event - The originating click event

View file

@ -11,8 +11,8 @@ SPDX-License-Identifier: MIT
--}}
<li class="ds4-effect-list__row effect" data-effect-id="{{effectData._id}}">
{{!-- enabled --}}
<input class="ds4-effect-list__editable ds4-effect-list__editable--checkbox effect-change" type="checkbox" {{checked
(ne effectData.disabled)}} data-dtype="Boolean" data-property="disabled"
<input class="ds4-effect-list__editable ds4-effect-list__editable--checkbox change-effect" type="checkbox" {{checked
(ne effectData.disabled true)}} data-dtype="Boolean" data-property="disabled" data-inverted="true"
title="{{localize 'DS4.EffectEnabled'}}">
{{!-- icon --}}