DND5e Core 1.3.5

DND5e Core 1.3.5 modded to SW5e System

Combining with DND5e Core 1.3.2 to see one big commit since last core update

DND5e Core 1.3.2 modded to SW5e System
This commit is contained in:
supervj 2021-05-18 09:11:03 -04:00
parent c208552f70
commit b56a074697
147 changed files with 3615 additions and 1875 deletions

View file

@ -1,14 +1,14 @@
/**
* A specialized form used to select from a checklist of attributes, traits, or properties
* @implements {FormApplication}
* @extends {DocumentSheet}
*/
export default class TraitSelector extends FormApplication {
export default class TraitSelector extends DocumentSheet {
/** @override */
/** @inheritdoc */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
return foundry.utils.mergeObject(super.defaultOptions, {
id: "trait-selector",
classes: ["sw5e"],
classes: ["sw5e", "trait-selector", "subconfig"],
title: "Actor Trait Selection",
template: "systems/sw5e/templates/apps/trait-selector.html",
width: 320,
@ -16,7 +16,9 @@ export default class TraitSelector extends FormApplication {
choices: {},
allowCustom: true,
minimum: 0,
maximum: null
maximum: null,
valueKey: "value",
customKey: "custom"
});
}
@ -24,7 +26,7 @@ export default class TraitSelector extends FormApplication {
/**
* Return a reference to the target attribute
* @type {String}
* @type {string}
*/
get attribute() {
return this.options.name;
@ -34,52 +36,50 @@ export default class TraitSelector extends FormApplication {
/** @override */
getData() {
// Get current values
let attr = getProperty(this.object._data, this.attribute);
if ( getType(attr) !== "Object" ) attr = {value: [], custom: ""};
const attr = foundry.utils.getProperty(this.object.data, this.attribute);
const o = this.options;
const value = (o.valueKey) ? attr[o.valueKey] ?? [] : attr;
const custom = (o.customKey) ? attr[o.customKey] ?? "" : "";
// Populate choices
const choices = duplicate(this.options.choices);
for ( let [k, v] of Object.entries(choices) ) {
choices[k] = {
label: v,
chosen: attr ? attr.value.includes(k) : false
}
}
const choices = Object.entries(o.choices).reduce((obj, e) => {
let [k, v] = e;
obj[k] = { label: v, chosen: attr ? value.includes(k) : false };
return obj;
}, {})
// Return data
return {
allowCustom: this.options.allowCustom,
allowCustom: o.allowCustom,
choices: choices,
custom: attr ? attr.custom : ""
custom: custom
}
}
/* -------------------------------------------- */
/** @override */
_updateObject(event, formData) {
const updateData = {};
async _updateObject(event, formData) {
const o = this.options;
// Obtain choices
const chosen = [];
for ( let [k, v] of Object.entries(formData) ) {
if ( (k !== "custom") && v ) chosen.push(k);
}
updateData[`${this.attribute}.value`] = chosen;
// Object including custom data
const updateData = {};
if ( o.valueKey ) updateData[`${this.attribute}.${o.valueKey}`] = chosen;
else updateData[this.attribute] = chosen;
if ( o.allowCustom ) updateData[`${this.attribute}.${o.customKey}`] = formData.custom;
// Validate the number chosen
if ( this.options.minimum && (chosen.length < this.options.minimum) ) {
return ui.notifications.error(`You must choose at least ${this.options.minimum} options`);
if ( o.minimum && (chosen.length < o.minimum) ) {
return ui.notifications.error(`You must choose at least ${o.minimum} options`);
}
if ( this.options.maximum && (chosen.length > this.options.maximum) ) {
return ui.notifications.error(`You may choose no more than ${this.options.maximum} options`);
}
// Include custom
if ( this.options.allowCustom ) {
updateData[`${this.attribute}.custom`] = formData.custom;
if ( o.maximum && (chosen.length > o.maximum) ) {
return ui.notifications.error(`You may choose no more than ${o.maximum} options`);
}
// Update the object