@@ -114,10 +114,49 @@ public IEnumerable<TraitInfo> TraitsInConstructOrder()
114114 OptionalDependencies = OptionalPrerequisitesOf ( i ) . ToList ( )
115115 } ) . ToList ( ) ;
116116
117+ // DEBUG: Log all traits and their dependencies for world actor
118+ if ( Name == "world" )
119+ {
120+ foreach ( var s in source )
121+ {
122+ var deps = string . Join ( ", " , s . Dependencies . Select ( d => d . FullName ) ) ;
123+ if ( s . Dependencies . Count > 0 )
124+ Log . Write ( "debug" , $ "[DEBUG] world trait: { s . Type . FullName } deps=[{ deps } ]") ;
125+ }
126+
127+ // Check BuildingInfluenceInfo
128+ var buildingInfluenceInfo = source . SelectMany ( s => s . Dependencies ) . FirstOrDefault ( d => d . Name == "BuildingInfluenceInfo" ) ;
129+ if ( buildingInfluenceInfo != null )
130+ {
131+ var matching = source . Where ( s => buildingInfluenceInfo . IsAssignableFrom ( s . Type ) ) . ToList ( ) ;
132+ Log . Write ( "debug" , $ "[DEBUG] Traits matching BuildingInfluenceInfo: { matching . Count } ") ;
133+ foreach ( var m in matching )
134+ Log . Write ( "debug" , $ "[DEBUG] - { m . Type . FullName } ") ;
135+ }
136+
137+ // Check IResourceLayerInfo
138+ var iResourceLayerInfo = source . SelectMany ( s => s . Dependencies ) . FirstOrDefault ( d => d . Name == "IResourceLayerInfo" ) ;
139+ if ( iResourceLayerInfo != null )
140+ {
141+ var matchingTraits = source . Where ( s => iResourceLayerInfo . IsAssignableFrom ( s . Type ) ) . ToList ( ) ;
142+ Log . Write ( "debug" , $ "[DEBUG] Traits matching IResourceLayerInfo: { matchingTraits . Count } ") ;
143+ foreach ( var m in matchingTraits )
144+ Log . Write ( "debug" , $ "[DEBUG] - { m . Type . FullName } ") ;
145+ }
146+ }
147+
117148 var resolved = source . Where ( s => s . Dependencies . Count == 0 && s . OptionalDependencies . Count == 0 ) . ToList ( ) ;
118149 var unresolved = source . ToHashSet ( ) ;
119150 unresolved . ExceptWith ( resolved ) ;
120151
152+ // DEBUG: Log initial state
153+ if ( Name == "world" )
154+ {
155+ Log . Write ( "debug" , $ "[DEBUG] Initial resolved: { resolved . Count } , unresolved: { unresolved . Count } ") ;
156+ foreach ( var u in unresolved . Where ( u => u . Type . Name . Contains ( "Resource" ) || u . Type . Name . Contains ( "Building" ) ) )
157+ Log . Write ( "debug" , $ "[DEBUG] Unresolved: { u . Type . Name } deps=[{ string . Join ( ", " , u . Dependencies . Select ( d => d . Name ) ) } ]") ;
158+ }
159+
121160 static bool AreResolvable ( Type a , Type b ) => a . IsAssignableFrom ( b ) ;
122161
123162 // This query detects which unresolved traits can be immediately resolved as all their direct dependencies are met.
@@ -132,8 +171,42 @@ public IEnumerable<TraitInfo> TraitsInConstructOrder()
132171 // Each time we resolve some traits, this means dependencies for other traits may then be possible to satisfy in the next pass.
133172#pragma warning disable CA1851 // Possible multiple enumerations of 'IEnumerable' collection
134173 var readyToResolve = more . ToList ( ) ;
174+ var iteration = 0 ;
135175 while ( readyToResolve . Count != 0 )
136176 {
177+ iteration ++ ;
178+ if ( Name == "world" && iteration <= 5 )
179+ {
180+ Log . Write ( "debug" , $ "[DEBUG] Iteration { iteration } : resolving { readyToResolve . Count } traits") ;
181+ foreach ( var r in readyToResolve . Where ( r => r . Type . Name . Contains ( "Resource" ) || r . Type . Name . Contains ( "WithResource" ) ) )
182+ Log . Write ( "debug" , $ "[DEBUG] Resolving: { r . Type . Name } ") ;
183+
184+ // Check why WithResourceAnimationInfo is not in readyToResolve
185+ var wra = unresolved . FirstOrDefault ( u => u . Type . Name == "WithResourceAnimationInfo" ) ;
186+ if ( wra != null )
187+ {
188+ var depsMet = wra . Dependencies . All ( d => resolved . Exists ( r => AreResolvable ( d , r . Type ) ) ) ;
189+ var hasUnresolved = wra . Dependencies . Any ( d => unresolved . Any ( u1 => AreResolvable ( d , u1 . Type ) ) ) ;
190+ Log . Write ( "debug" , $ "[DEBUG] WithResourceAnimationInfo: depsMet={ depsMet } hasUnresolved={ hasUnresolved } ") ;
191+ foreach ( var d in wra . Dependencies )
192+ {
193+ var inResolved = resolved . Exists ( r => AreResolvable ( d , r . Type ) ) ;
194+ var inUnresolved = unresolved . Any ( u1 => AreResolvable ( d , u1 . Type ) ) ;
195+ Log . Write ( "debug" , $ "[DEBUG] dep { d . Name } : inResolved={ inResolved } inUnresolved={ inUnresolved } ") ;
196+
197+ // Check each resolved trait
198+ if ( ! inResolved )
199+ {
200+ foreach ( var r in resolved . Where ( r => r . Type . Name . Contains ( "Resource" ) ) )
201+ {
202+ var canAssign = d . IsAssignableFrom ( r . Type ) ;
203+ Log . Write ( "debug" , $ "[DEBUG] { d . Name } .IsAssignableFrom({ r . Type . Name } ) = { canAssign } ") ;
204+ }
205+ }
206+ }
207+ }
208+ }
209+
137210 resolved . AddRange ( readyToResolve ) ;
138211 unresolved . ExceptWith ( readyToResolve ) ;
139212 readyToResolve . Clear ( ) ;
0 commit comments