diff --git a/src/module/actor/actor-sheet.ts b/src/module/actor/actor-sheet.ts index 779f5c8a..ee1860a2 100644 --- a/src/module/actor/actor-sheet.ts +++ b/src/module/actor/actor-sheet.ts @@ -62,12 +62,7 @@ export class DS4ActorSheet extends ActorSheet this.render(false)); }); - html.find(".item-equip").on("click", (ev) => { - const id = $(ev.currentTarget).parents(".item").data("itemId"); - const item = duplicate(this.actor.getOwnedItem(id)); // getOwnedItem is typed incorrectly, it actually returns a ItemData, not an Item - setProperty(item, "data.equipped", !getProperty(item, "data.equipped")); // TODO: use "."" accessors instead, once typing has been fixed - this.actor.updateOwnedItem(item); - }); + html.find(".item-change").on("change", this._onItemChange.bind(this)); // Rollable abilities. html.find(".rollable").click(this._onRoll.bind(this)); @@ -102,6 +97,67 @@ export class DS4ActorSheet extends ActorSheet): void { + ev.preventDefault(); + console.log("Current target:", $(ev.currentTarget).get(0)["name"]); + const el: HTMLFormElement = $(ev.currentTarget).get(0); + const id = $(ev.currentTarget).parents(".item").data("itemId"); + const item = duplicate(this.actor.getOwnedItem(id)); // getOwnedItem is typed incorrectly, it actually returns a ItemData, not an Item + const property: string = $(ev.currentTarget).data("property"); + let newValue; + + // Early return: + // Disabled => do nothing + if (el.disabled || el.getAttribute("disabled")) return; + // name not given => raise + if (property === undefined) { + throw TypeError("HTML element does not provide 'data-property' attribute"); + } + + // One needs to differentiate between e.g. checkboxes (value="on") and select boxes etc. + // Checkbox: + if (el.type === "checkbox") { + newValue = el.checked; //!getProperty(item, property); + } + + // Text input: + else if (el.type === "text") { + newValue = el.value; + } + + // Numbers and ranges: + else if (["number", "range"].includes(el.type)) { + newValue = el.value.trim(); + } + + // // Radio Checkboxes (untested, cf. FormDataExtended.process) + // else if (el.type === "radio") { + // const chosen: HTMLFormElement = el.find((r: HTMLFormElement) => r["checked"]); + // newValue = chosen ? chosen.value : null; + // } + + // // Multi-Select (untested, cf. FormDataExtended.process) + // else if (el.type === "select-multiple") { + // newValue = []; + // el.options.array.forEach((opt: HTMLOptionElement) => { + // if (opt.selected) newValue.push(opt.value); + // }); + + // unsupported: + else { + throw TypeError("Binding of item property to this type of HTML element not supported; given: " + el); + } + setProperty(item, property, newValue); + this.actor.updateOwnedItem(item); + } + /** * Handle clickable rolls. * @param {Event} event The originating click event diff --git a/src/scss/components/_items.scss b/src/scss/components/_items.scss index 3f089ca3..fe3370ab 100644 --- a/src/scss/components/_items.scss +++ b/src/scss/components/_items.scss @@ -36,6 +36,7 @@ .item-num-val { text-align: center; + max-width: 2.5em; } .item-description { diff --git a/src/templates/actor/partials/items.hbs b/src/templates/actor/partials/items.hbs index cda5f1e4..52349781 100644 --- a/src/templates/actor/partials/items.hbs +++ b/src/templates/actor/partials/items.hbs @@ -16,10 +16,12 @@
{{localize 'DS4.ItemName'}}
{{localize 'DS4.AttackTypeAbbr'}}
{{!-- SPECIFIC --}}
-
{{localize 'DS4.WeaponBonusAbbr'}} +
+ {{localize 'DS4.WeaponBonusAbbr'}} +
{{!-- SPECIFIC --}} +
+ {{localize 'DS4.OpponentDefenseAbbr'}}
{{!-- SPECIFIC --}} -
{{localize - 'DS4.OpponentDefenseAbbr'}}
{{!-- SPECIFIC --}}
{{localize 'DS4.Description'}}
{{!-- add button --}} @@ -34,18 +36,19 @@
  • {{!-- equipped? --}} - {{#if itemData.equipped}} - {{else}} - {{/if}} {{!--SPECIFIC --}} + {{!--SPECIFIC --}} {{!-- image --}}
    {{!-- amount --}} -
    {{itemData.quantity}}
    +
    {{!-- name --}} -

    {{item.name}}

    + {{!-- item specifics --}}
    {{!-- equipped? --}} - {{#if itemData.equipped}} - {{else}} - {{/if}} {{!--SPECIFIC --}} + {{!--SPECIFIC --}} {{!-- image --}}
    {{!-- amount --}} -
    {{itemData.quantity}}
    +
    {{!-- name --}} -

    {{item.name}}

    + {{!-- item specifics --}}
    {{lookup ../../config.armorMaterialTypesAbbr itemData.armorMaterialType}} @@ -154,18 +158,19 @@
  • {{!-- equipped? --}} - {{#if itemData.equipped}} - {{else}} - {{/if}} {{!--SPECIFIC --}} + {{!--SPECIFIC --}} {{!-- image --}}
    {{!-- amount --}} -
    {{itemData.quantity}}
    +
    {{!-- name --}} -

    {{item.name}}

    + {{!-- item specifics --}}
    {{itemData.armorValue}}
    {{!-- SPECIFIC --}} {{!-- description --}} @@ -204,20 +209,22 @@
  • {{!-- equipped? --}} - {{#if itemData.equipped}} - {{else}} - {{/if}} {{!--SPECIFIC --}} + {{!--SPECIFIC --}} {{!-- image --}}
    {{!-- amount --}} -
    {{itemData.quantity}}
    +
    {{!-- name --}} -

    {{item.name}}

    + {{!-- storage location --}} -
    {{{itemData.storageLocation}}}
    {{!-- SPECIFIC --}} + {{!-- SPECIFIC --}} {{!-- description --}}
    {{{itemData.description}}}
    {{!-- edit & delete buttons --}} @@ -257,12 +264,15 @@
  • {{!-- amount --}} -
    {{itemData.quantity}}
    + {{!-- name --}} -

    {{item.name}}

    + {{!-- storage location --}} -
    {{{itemData.storageLocation}}}
    {{!-- SPECIFIC --}} + {{!-- SPECIFIC --}} {{!-- description --}}
    {{{itemData.description}}}
    {{!-- edit & delete buttons --}}