Merge remote-tracking branch 'origin/master' into 013-rollLibRefinements

This commit is contained in:
Oliver Rümpelein 2021-01-04 21:21:54 +01:00
commit 1af51b3917
35 changed files with 8137 additions and 7733 deletions

View file

@ -62,6 +62,8 @@ export class DS4ActorSheet extends ActorSheet<DS4ActorDataType, DS4Actor, DS4Ite
li.slideUp(200, () => this.render(false));
});
html.find(".item-change").on("change", this._onItemChange.bind(this));
// Rollable abilities.
html.find(".rollable").click(this._onRoll.bind(this));
}
@ -70,7 +72,7 @@ export class DS4ActorSheet extends ActorSheet<DS4ActorDataType, DS4Actor, DS4Ite
/**
* Handle creating a new Owned Item for the actor using initial data defined in the HTML dataset
* @param {Event} event The originating click event
* @param {JQuery.ClickEvent} event The originating click event
* @private
*/
private _onItemCreate(event: JQuery.ClickEvent): Promise<Item> {
@ -95,9 +97,93 @@ export class DS4ActorSheet extends ActorSheet<DS4ActorDataType, DS4Actor, DS4Ite
return this.actor.createOwnedItem(itemData);
}
/**
* Handle changes to properties of an Owned Item from within character sheet.
* Can currently properly bind: see getValue().
* Assumes the item property is given as the value of the HTML element property 'data-property'.
* @param {JQuery.ChangeEvent<HTMLFormElement>} ev The originating change event
* @private
*/
private _onItemChange(ev: JQuery.ChangeEvent<HTMLFormElement>): 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<DS4ItemDataType>, not an Item
const property: string | undefined = $(ev.currentTarget).data("property");
// 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");
}
// Set new value
const newValue = this.getValue(el);
setProperty(item, property, newValue);
this.actor.updateOwnedItem(item);
}
/**
* Collect the value of a form element depending on the element's type
* The value is parsed to:
* - Checkbox: boolean
* - Text input: string
* - Number: number
* @param el the input element to collect the value of
*/
private getValue(el: HTMLFormElement): 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;
}
// Text input:
else if (el.type === "text") {
const value: string = el.value;
return value;
}
// Numbers:
else if (el.type === "number") {
const value = Number(el.value.trim());
return value;
}
// // Ranges:
// else if (el.type === "range") {
// const value: string = el.value.trim();
// return value;
// }
// // Radio Checkboxes (untested, cf. FormDataExtended.process)
// else if (el.type === "radio") {
// const chosen: HTMLFormElement = el.find((r: HTMLFormElement) => r["checked"]);
// const value: string = chosen ? chosen.value : null;
// return value;
// }
// // Multi-Select (untested, cf. FormDataExtended.process)
// else if (el.type === "select-multiple") {
// const value: Array<string> = [];
// el.options.array.forEach((opt: HTMLOptionElement) => {
// if (opt.selected) value.push(opt.value);
// });
// return value;
// unsupported:
else {
throw TypeError("Binding of item property to this type of HTML element not supported; given: " + el);
}
}
/**
* Handle clickable rolls.
* @param {Event} event The originating click event
* @param {JQuery.ClickEvent} event The originating click event
* @private
*/
private _onRoll(event: JQuery.ClickEvent): void {

View file

@ -21,9 +21,9 @@ export const DS4 = {
* Define the file paths to icon images
*/
attackTypesIcons: {
melee: "systems/ds4/assets/DS4-MAT.png",
meleeRanged: "systems/ds4/assets/DS4-MRA.png",
ranged: "systems/ds4/assets/DS4-RAT.png",
melee: "systems/ds4/assets/official/DS4-MAT.png",
meleeRanged: "systems/ds4/assets/official/DS4-MRA.png",
ranged: "systems/ds4/assets/official/DS4-RAT.png",
},
/**
@ -106,10 +106,10 @@ export const DS4 = {
*/
traits: {
strength: "DS4.TraitStrength",
constitution: "DS4.TraitConstitution",
agility: "DS4.TraitAgility",
dexterity: "DS4.TraitDexterity",
intellect: "DS4.TraitIntellect",
constitution: "DS4.TraitConstitution",
dexterity: "DS4.TraitDexterity",
aura: "DS4.TraitAura",
},

View file

@ -36,7 +36,9 @@ async function registerHandlebarsPartials() {
"systems/ds4/templates/item/partials/details.hbs",
"systems/ds4/templates/item/partials/effects.hbs",
"systems/ds4/templates/item/partials/body.hbs",
"systems/ds4/templates/actor/partials/items.hbs",
"systems/ds4/templates/actor/partials/items-overview.hbs",
"systems/ds4/templates/actor/partials/attributes-traits.hbs",
"systems/ds4/templates/actor/partials/combat-values.hbs",
];
return loadTemplates(templatePaths);
}
@ -67,7 +69,7 @@ Hooks.once("setup", function () {
];
// Exclude some from sorting where the default order matters
const noSort = [];
const noSort = ["attributes", "traits", "combatValues"];
// Localize and sort CONFIG objects
for (const o of toLocalize) {