Skip to content

Commit

Permalink
Fix a DAE related compatibility issue
Browse files Browse the repository at this point in the history
  • Loading branch information
teroparvinen committed Oct 24, 2023
1 parent 2a8df34 commit a25ba92
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 31 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changes by version number

### 0.11.5

Fixes

- Addressed an incompatibility with a recent version of the module "Dynamic effects using Active Effects (DAE)"

### 0.11.4

Fixes
Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"name": "Tero Parvinen (tero.p)"
}
],
"version": "0.11.4",
"version": "0.11.5",
"compatibility": {
"minimum": 11,
"verified": 11
Expand Down
11 changes: 10 additions & 1 deletion module/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export function initHooks() {
"flags.wire.isMasterEffect": true
});
}
if (data.flags.wire?.rollEffects && !data.flags.wire?.changesRolled) {
if (data.flags?.wire?.rollEffects && !data.flags?.wire?.changesRolled) {
const { changes, rolls } = rollChangeValues(substituteEffectConfig(effect.parent, null, null, copyEffectChanges(data)), effect.flags.wire?.rollEffects);
effect.updateSource({
changes,
Expand All @@ -162,6 +162,15 @@ export function initHooks() {
}
});

Hooks.on("preUpdateActiveEffect", (effect, changes, options) => {
const conditions = changes.flags?.wire?.conditions;
if (conditions) {
foundry.utils.setProperty(changes, "flags.wire.conditions", Object.values(conditions));
} else {
foundry.utils.setProperty(changes, "flags.wire.conditions", []);
}
});

Hooks.on("createActiveEffect", async (effect, options, user) => {
if (user === game.user.id && effect.flags.wire?.wasTransferred && isEffectEnabled(effect) && isActorEffect(effect) && getActorToken(effect.parent)) {
await triggerTransferEffect(effect);
Expand Down
27 changes: 0 additions & 27 deletions module/injections/active-effect-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,32 +94,5 @@ export function initActiveEffectSheetHooks() {
`;
html.find('section[data-tab="duration"] .form-group').last().after(durationFields);
});
}

export function setupActiveEffectSheetWrappers() {
if (typeof DAE !== "undefined") {
libWrapper.register("wire", "DAE.DAEActiveEffectConfig.prototype._getSubmitData", onItemSubmit, "MIXED");
} else {
libWrapper.register("wire", "ActiveEffectConfig.prototype._getSubmitData", onItemSubmit, "MIXED");
}
}

function onItemSubmit(wrapped, updateData) {
const submitData = wrapped(updateData);

// Create the expanded update data object
const fd = new FormDataExtended(this.form, {editors: this.editors});
let data = fd.object;
if ( updateData ) data = mergeObject(data, updateData);
else data = expandObject(data);

const conditions = data.flags?.wire?.conditions;
if (conditions) {
submitData['flags.wire.conditions'] = Object.values(conditions);
} else {
submitData['flags.wire.conditions'] = [];
}

return submitData;
}

3 changes: 1 addition & 2 deletions module/wire.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DamageCard, declareDamage, declareHealing } from "./cards/damage-card.j
import { initEffectFlagHooks, setupRollFlagWrappers } from "./game/effect-flags.js";
import { registerHandlebarsHelpers } from "./handlebars.js";
import { initHooks } from "./hooks.js";
import { initActiveEffectSheetHooks, setupActiveEffectSheetWrappers } from "./injections/active-effect-sheet.js";
import { initActiveEffectSheetHooks } from "./injections/active-effect-sheet.js";
import { readyCharacterSheetWrappers } from "./injections/character-sheet.js";
import { initItemSheetHooks, setupItemSheetWrappers } from "./injections/item-sheet.js";
import { setupKeybindings } from "./keybindings.js";
Expand Down Expand Up @@ -72,7 +72,6 @@ Hooks.once("init", () => {
Hooks.once("setup", () => {
setupWrappers();
setupItemSheetWrappers();
setupActiveEffectSheetWrappers();
setupRollFlagWrappers();
setupTemplateWrappers();
setupSocket();
Expand Down

0 comments on commit a25ba92

Please sign in to comment.