@@ -22,6 +22,9 @@ import ABFFoundryRoll from '../rolls/ABFFoundryRoll';
2222import { openModDialog } from '../utils/dialogs/openSimpleInputDialog' ;
2323import ABFItem from '../items/ABFItem' ;
2424import { FormulaEvaluator } from '../../utils/formulaEvaluator.js' ;
25+ import { inflateSystemFromTypeMarkers } from './types/inflateSystemFromTypeMarkers.js' ;
26+ import { TYPED_PATHS } from './types/typedTemplateIndex.js' ;
27+ import { buildTypedNodes } from './types/runtimeTypedNodes.js' ;
2528
2629export class ABFActor extends Actor {
2730 i18n = game . i18n ;
@@ -42,14 +45,31 @@ export class ABFActor extends Actor {
4245 }
4346 }
4447
48+ async _preCreate ( data , options , user ) {
49+ // Ensure system exists + template defaults
50+ data . system = foundry . utils . mergeObject ( data . system ?? { } , INITIAL_ACTOR_DATA , {
51+ overwrite : false
52+ } ) ;
53+
54+ // Inflate typed nodes from __type and remove markers
55+ data . system = inflateSystemFromTypeMarkers ( data . system ) ;
56+
57+ return super . _preCreate ( data , options , user ) ;
58+ }
59+
4560 async prepareDerivedData ( ) {
4661 super . prepareDerivedData ( ) ;
4762
48- this . system = foundry . utils . mergeObject ( this . system , INITIAL_ACTOR_DATA , {
49- overwrite : false
50- } ) ;
63+ // this.system = foundry.utils.mergeObject(this.system, INITIAL_ACTOR_DATA, {
64+ // overwrite: false
65+ // });
66+
67+ // Safety: if some actor came without inflation (old data / imports)
68+ this . system = inflateSystemFromTypeMarkers ( this . system ) ;
5169
70+ buildTypedNodes ( this , TYPED_PATHS ) ;
5271 await prepareActor ( this ) ;
72+ // applyTypedDerived(this);
5373 }
5474
5575 getRollData ( ) {
@@ -871,40 +891,10 @@ export class ABFActor extends Actor {
871891 getItem ( itemId ) {
872892 return this . getEmbeddedDocument ( 'Item' , itemId ) ;
873893 }
874-
875894 applyActiveEffects ( ) {
876- const originals = new Map ( ) ;
877-
878- try {
879- for ( const effect of this . effects . contents ) {
880- if ( ! effect . active ) continue ;
881-
882- const changes = effect . changes ;
883- if ( ! Array . isArray ( changes ) || changes . length === 0 ) continue ;
884-
885- // Save originals
886- originals . set (
887- effect ,
888- changes . map ( c => c . value )
889- ) ;
890-
891- // Patch values (in-memory only)
892- for ( const change of changes ) {
893- change . value = this . _applyDynamicEffectValue ( change . value ) ;
894- }
895- }
896-
897- // Let Foundry core do the real AE logic (modes, priority, etc.)
898- return super . applyActiveEffects ( ) ;
899- } finally {
900- // Restore original values so nothing "sticks" on the document
901- for ( const [ effect , values ] of originals . entries ( ) ) {
902- const changes = effect . changes ;
903- for ( let i = 0 ; i < changes . length ; i ++ ) {
904- changes [ i ] . value = values [ i ] ;
905- }
906- }
907- }
895+ // Active Effects are applied in prepareActor using the flow ordering (per-change).
896+ // We keep _applyDynamicEffectValue for evaluating dynamic change values.
897+ return this ;
908898 }
909899
910900 _applyDynamicEffectValue ( value ) {
0 commit comments