Skip to content

Commit 5e1810d

Browse files
committed
fix: upgrade/downgrade custom active effect changes not working properly
1 parent f6cfa01 commit 5e1810d

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

module/documents/actors/common/affinity-data-model.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class AffinityDataModel extends foundry.abstract.DataModel {
1717
_initialize(options = {}) {
1818
super._initialize(options);
1919

20-
let current = this.base;
20+
let current = options.current ?? this.base;
2121
Object.defineProperty(this, 'current', {
2222
configurable: false,
2323
enumerable: true,
@@ -45,4 +45,9 @@ export class AffinityDataModel extends foundry.abstract.DataModel {
4545
},
4646
});
4747
}
48+
49+
clone(data = {}, context = {}) {
50+
context.current = this.current;
51+
return super.clone(data, context);
52+
}
4853
}

module/documents/actors/common/attribute-data-model.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ export class AttributeDataModel extends foundry.abstract.DataModel {
2424
_initialize(options = {}) {
2525
super._initialize(options);
2626
let thiz = this;
27+
const { current } = options;
2728
let holder = {
2829
get current() {
29-
return thiz.base;
30+
return current ?? thiz.base;
3031
},
3132
set current(value) {
3233
delete this.current;
@@ -58,4 +59,9 @@ export class AttributeDataModel extends foundry.abstract.DataModel {
5859
},
5960
});
6061
}
62+
63+
clone(data = {}, context = {}) {
64+
context.current = this.current;
65+
return super.clone(data, context);
66+
}
6167
}

module/documents/effects/active-effect.mjs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,20 @@ export function onRenderActiveEffectConfig(sheet, html) {
3232
* @param delta
3333
*/
3434
export function onApplyActiveEffect(actor, change, current, delta) {
35-
if (change.key.startsWith('system.') && current instanceof foundry.abstract.DataModel && Object.hasOwn(current, delta) && current[delta] instanceof Function) {
36-
console.debug(`applying ${delta} to ${change.key}`);
37-
current[delta]();
38-
return false;
35+
if (game.release.isNewer(12)) {
36+
if (change.key.startsWith('system.') && current instanceof foundry.abstract.DataModel && Object.hasOwn(current, change.value) && current[change.value] instanceof Function) {
37+
console.debug(`applying ${change.value} to ${change.key}`);
38+
const newValue = current.clone();
39+
newValue[change.value]();
40+
foundry.utils.setProperty(actor, change.key, newValue);
41+
return false;
42+
}
43+
} else {
44+
if (change.key.startsWith('system.') && current instanceof foundry.abstract.DataModel && Object.hasOwn(current, delta) && current[delta] instanceof Function) {
45+
console.debug(`applying ${delta} to ${change.key}`);
46+
current[delta]();
47+
return false;
48+
}
3949
}
4050
}
4151

0 commit comments

Comments
 (0)