first commit
This commit is contained in:
35
module/helpers/item-helpers.js
Normal file
35
module/helpers/item-helpers.js
Normal file
@@ -0,0 +1,35 @@
|
||||
export default class ItemHelpers {
|
||||
static async itemUpdate(event, formData) {
|
||||
formData = expandObject(formData);
|
||||
|
||||
if (this.object.isOwned && this.object.actor?.compendium?.metadata) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle the free-form modifications list
|
||||
const formAttrs = expandObject(formData)?.data?.modifications || {};
|
||||
|
||||
const modifications = Object.values(formAttrs).reduce((obj, v) => {
|
||||
let k = v["key"].trim();
|
||||
delete v["key"];
|
||||
obj[k] = v;
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
// Remove modifications which are no longer used
|
||||
if (this.object.data?.data?.modifications) {
|
||||
for (let k of Object.keys(this.object.data.data.modifications)) {
|
||||
if (!modifications.hasOwnProperty(k)) modifications[`-=${k}`] = null;
|
||||
}
|
||||
}
|
||||
|
||||
// recombine modifications to formData
|
||||
if (Object.keys(modifications).length > 0) {
|
||||
setProperty(formData, `data.modifications`, modifications);
|
||||
}
|
||||
|
||||
// Update the Item
|
||||
this.item.data.flags.loaded = false;
|
||||
this.object.update(formData);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user