Removed itemLogic calls, as we're using ActiveEffects now and they were breaking things.

This commit is contained in:
Justin Ross 2021-10-08 14:56:29 -07:00
parent 749707a434
commit 3baa28d6ef
2 changed files with 0 additions and 133 deletions

View file

@ -25,111 +25,6 @@ export class BladesHelpers {
return dupe_list;
}
/**
* Add item modification if logic exists.
* @param {Object} item_data
* @param {Document} entity
*/
static async callItemLogic(item_data, entity) {
if ('logic' in item_data.data && item_data.data.logic !== '') {
let logic = JSON.parse(item_data.data.logic);
// Should be an array to support multiple expressions
if (!Array.isArray(logic)) {
logic = [logic];
}
if (logic) {
let logic_update = { "_id": entity.id };
logic.forEach(expression => {
// Different logic behav. dep on operator.
switch (expression.operator) {
// Add when creating.
case "addition":
foundry.utils.mergeObject(
logic_update,
{[expression.attribute]: Number(BladesHelpers.getNestedProperty(entity, prefix + expression.attribute)) + expression.value},
{insertKeys: true}
);
break;
// Change name property.
case "attribute_change":
foundry.utils.mergeObject(
logic_update,
{[expression.attribute]: expression.value},
{insertKeys: true}
);
break;
}
});
await Actor.updateDocuments( logic_update );
}
}
}
/**
* Undo Item modifications when item is removed.
* @todo
* - Remove all items and then Add them back to
* sustain the logic mods
* @param {Object} item_data
* @param {Document} entity
*/
static async undoItemLogic(item_data, entity) {
if ('logic' in item_data.data && item_data.data.logic !== '') {
let logic = JSON.parse(item_data.data.logic)
// Should be an array to support multiple expressions
if (!Array.isArray(logic)) {
logic = [logic];
}
if (logic) {
let logic_update = { "_id": entity.id };
var entity_data = entity.data;
logic.forEach(expression => {
// Different logic behav. dep on operator.
switch (expression.operator) {
// Subtract when removing.
case "addition":
foundry.utils.mergeObject(
logic_update,
{[expression.attribute]: Number(BladesHelpers.getNestedProperty(entity, expression.attribute)) - expression.value},
{insertKeys: true}
);
break;
// Change name back to default.
case "attribute_change":
// Get the array path to take data.
let default_expression_attribute_path = expression.attribute + '_default';
let default_name = default_expression_attribute_path.split(".").reduce((o, i) => o[i], entity_data);
foundry.utils.mergeObject(
logic_update,
{[expression.attribute]: default_name},
{insertKeys: true}
);
break;
}
});
await Actor.updateDocuments( logic_update );
}
}
}
/**
* Get a nested dynamic attribute.
* @param {Object} obj

View file

@ -24,34 +24,6 @@ export class BladesItem extends Item {
/* -------------------------------------------- */
/** @override */
async _onCreate( data, options, userId ) {
super._onCreate( data, options, userId );
if( userId === game.user.id ) {
let actor = this.parent ? this.parent : null;
if( ( actor?.documentName === "Actor" ) && ( actor?.permission >= CONST.ENTITY_PERMISSIONS.OWNER ) ) {
await BladesHelpers.callItemLogic( data, actor );
}
}
}
/* -------------------------------------------- */
/** @override */
async _onDelete( options, userId ) {
super._onDelete( options, userId );
let actor = this.parent ? this.parent : null;
let data = this.data;
if ( ( actor?.documentName === "Actor" ) && ( actor?.permission >= CONST.ENTITY_PERMISSIONS.OWNER ) ) {
await BladesHelpers.undoItemLogic( data, actor );
}
}
/* -------------------------------------------- */
/* override */
prepareData() {