@@ -142,13 +142,11 @@ export class CombatHUD extends Application {
142
142
data . cssClasses = this . options . classes . join ( ' ' ) ;
143
143
data . cssId = this . options . id ;
144
144
data . isCompact = game . settings . get ( SYSTEM , SETTINGS . optionCombatHudCompact ) ;
145
- data . isGM = game . user . isGM ;
146
145
147
146
const opacity = game . settings . get ( SYSTEM , SETTINGS . optionCombatHudOpacity ) / 100 ;
148
147
data . additionalStyle = this . _getAdditionalStyle ( opacity ) ;
149
148
150
149
const ordering = game . settings . get ( SYSTEM , SETTINGS . optionCombatHudActorOrdering ) ;
151
-
152
150
data . npcs = [ ] ;
153
151
data . characters = [ ] ;
154
152
@@ -174,14 +172,9 @@ export class CombatHUD extends Application {
174
172
175
173
const NPCTurnsLeftMode = game . settings . get ( SYSTEM , SETTINGS . optionCombatHudShowNPCTurnsLeftMode ) ;
176
174
177
- const currentTurn = game . combat . getCurrentTurn ( ) ;
178
- const turnsLeft = ui . combat . countTurnsLeft ( game . combat ) ;
179
- // const round = game.combat.round;
180
-
181
175
/** @type FUCombat **/
182
176
const combat = game . combat ;
183
- data . turnStarted = combat . isTurnStarted ;
184
- data . hasCombatStarted = game . combat . started ;
177
+ combat . populateData ( data ) ;
185
178
186
179
for ( const combatant of game . combat . combatants ) {
187
180
if ( ! combatant . actor || ! combatant . token ) continue ;
@@ -191,12 +184,15 @@ export class CombatHUD extends Application {
191
184
id : combatant . id ,
192
185
name : combatant . name ,
193
186
actor : combatant . actor ,
187
+ isOwner : combatant . isOwner ,
188
+ totalTurns : combatant . totalTurns ,
194
189
token : combatant . token ,
195
190
effects : activeEffects ,
196
- img : game . settings . get ( SYSTEM , SETTINGS . optionCombatHudPortrait ) === 'token' ?
197
- // token._source should contain the most current version of the token's texture.
198
- combatant . token . _source . texture . src :
199
- combatant . actor . img ,
191
+ img :
192
+ game . settings . get ( SYSTEM , SETTINGS . optionCombatHudPortrait ) === 'token'
193
+ ? // token._source should contain the most current version of the token's texture.
194
+ combatant . token . _source . texture . src
195
+ : combatant . actor . img ,
200
196
trackedResourcePart1 : trackedResourcePart1 ,
201
197
trackedResourcePart2 : trackedResourcePart2 ,
202
198
trackedResourcePart3 : trackedResourcePart3 ,
@@ -238,7 +234,6 @@ export class CombatHUD extends Application {
238
234
239
235
// Ensure shouldEffectsMarquee is false if effectsMarqueeDuration is over 9000
240
236
actorData . shouldEffectsMarquee = actorData . effects . length > maxEffectsBeforeMarquee && effectsMarqueeDuration < 9000 ;
241
-
242
237
actorData . effectsMarqueeDuration = effectsMarqueeDuration ;
243
238
244
239
const marqueeDirection = game . settings . get ( SYSTEM , SETTINGS . optionCombatHudEffectsMarqueeMode ) ;
@@ -262,29 +257,19 @@ export class CombatHUD extends Application {
262
257
} ) ;
263
258
}
264
259
265
- actorData . isOwner = combatant . isOwner ;
266
260
actorData . order = order ;
267
261
268
- actorData . totalTurns = combatant . totalTurns ;
269
262
if ( NPCTurnsLeftMode === 'never' ) {
270
263
actorData . totalTurns = 1 ;
271
264
} else if ( NPCTurnsLeftMode === 'only-studied' && ! this . _isNPCStudied ( combatant . token ) ) {
272
265
actorData . totalTurns = 1 ;
273
266
}
274
267
275
- actorData . turnsLeft = turnsLeft [ combatant . id ] ?? 0 ;
276
-
277
268
if ( combatant . token . disposition === foundry . CONST . TOKEN_DISPOSITIONS . FRIENDLY ) {
278
- actorData . isCurrentTurn = currentTurn === 'friendly' ;
279
269
data . characters . push ( actorData ) ;
280
270
} else {
281
- actorData . isCurrentTurn = currentTurn === 'hostile' ;
282
271
data . npcs . push ( actorData ) ;
283
272
}
284
-
285
- // Decides whether combatant can (start turn | take turn)
286
- actorData . isCurrentCombatant = combat . isCurrentCombatant ( combatant ) ;
287
- actorData . hasTurns = turnsLeft [ combatant . id ] && actorData . isCurrentTurn ;
288
273
}
289
274
290
275
data . characters . sort ( ( a , b ) => a . order - b . order ) ;
@@ -332,7 +317,7 @@ export class CombatHUD extends Application {
332
317
dragButton . on ( 'drag' , this . _doHudDrag . bind ( this ) ) ;
333
318
dragButton . on ( 'dragend' , this . _doHudDrop . bind ( this ) ) ;
334
319
335
- if ( navigator . userAgent . toLowerCase ( ) . includes ( 'firefox' ) ) {
320
+ if ( navigator . userAgent . toLowerCase ( ) . includes ( 'firefox' ) ) {
336
321
$ ( window . document ) . on ( 'dragover' , this . _fireFoxDragWorkaround . bind ( this ) ) ;
337
322
}
338
323
@@ -395,7 +380,7 @@ export class CombatHUD extends Application {
395
380
396
381
const draggedPosition = {
397
382
x : offset . left ,
398
- y : positionFromTop ? offset . top : $ ( window ) . height ( ) - offset . top - height
383
+ y : positionFromTop ? offset . top : $ ( window ) . height ( ) - offset . top - height ,
399
384
} ;
400
385
game . settings . set ( SYSTEM , SETTINGS . optionCombatHudDraggedPosition , draggedPosition ) ;
401
386
}
@@ -739,33 +724,28 @@ export class CombatHUD extends Application {
739
724
740
725
_onUpdateToken ( token , changes ) {
741
726
// Is the updated token in the current combat?
742
- if ( ! game . combat ?. combatants . some ( c => c . token . uuid === token . uuid ) ) {
727
+ if ( ! game . combat ?. combatants . some ( ( c ) => c . token . uuid === token . uuid ) ) {
743
728
return ;
744
729
}
745
730
746
731
// Are any of the changes relevant to the Combat HUD?
747
732
if (
748
733
foundry . utils . hasProperty ( changes , 'name' ) ||
749
- foundry . utils . hasProperty ( changes , 'actorId' ) ||
750
- foundry . utils . hasProperty ( changes , 'disposition' ) ||
751
- (
752
- game . settings . get ( SYSTEM , 'optionCombatHudPortrait' ) === 'token' &&
753
- foundry . utils . hasProperty ( changes , 'texture.src' )
754
- )
734
+ foundry . utils . hasProperty ( changes , 'actorId' ) ||
735
+ foundry . utils . hasProperty ( changes , 'disposition' ) ||
736
+ ( game . settings . get ( SYSTEM , 'optionCombatHudPortrait' ) === 'token' && foundry . utils . hasProperty ( changes , 'texture.src' ) )
755
737
) {
756
738
this . _onUpdateHUD ( ) ;
757
739
}
758
740
}
759
741
760
742
_onUpdateActor ( actor , changes ) {
761
743
// Is the updated actor in the current combat?
762
- if ( ! game . combat ?. combatants . some ( c => c . actor . uuid === actor . uuid ) ) {
744
+ if ( ! game . combat ?. combatants . some ( ( c ) => c . actor . uuid === actor . uuid ) ) {
763
745
return ;
764
746
}
765
747
766
- const systemResources = [
767
- 'hp' , 'mp' , 'ip' , 'fp' , 'exp' , 'zenit'
768
- ] ;
748
+ const systemResources = [ 'hp' , 'mp' , 'ip' , 'fp' , 'exp' , 'zenit' ] ;
769
749
770
750
const trackedResources = [
771
751
game . settings . get ( SYSTEM , SETTINGS . optionCombatHudTrackedResource1 ) ,
@@ -775,10 +755,7 @@ export class CombatHUD extends Application {
775
755
] ;
776
756
777
757
// Are any of the changes relevant to the Combat HUD?
778
- if (
779
- trackedResources . filter ( r => systemResources . includes ( r ) )
780
- . some ( r => foundry . utils . hasProperty ( changes , `system.resources.${ r } ` ) )
781
- ) {
758
+ if ( trackedResources . filter ( ( r ) => systemResources . includes ( r ) ) . some ( ( r ) => foundry . utils . hasProperty ( changes , `system.resources.${ r } ` ) ) ) {
782
759
this . _onUpdateHUD ( ) ;
783
760
}
784
761
}
@@ -793,10 +770,7 @@ export class CombatHUD extends Application {
793
770
794
771
_onModifyItem ( item , changes ) {
795
772
// Is the item owned by an actor in the current combat?
796
- if (
797
- item . parent ?. documentName !== 'Actor' ||
798
- ! game . combat ?. combatants . some ( c => c . actor . uuid === item . parent . uuid )
799
- ) {
773
+ if ( item . parent ?. documentName !== 'Actor' || ! game . combat ?. combatants . some ( ( c ) => c . actor . uuid === item . parent . uuid ) ) {
800
774
return ;
801
775
}
802
776
@@ -809,20 +783,11 @@ export class CombatHUD extends Application {
809
783
810
784
// Are any of the changes relevant to the combat HUD?
811
785
if (
812
- trackedResources . includes ( 'zeropower' ) &&
813
- item . type === 'optionalFeature' &&
814
- (
815
- item . system . optionalType === 'projectfu.zeroPower' ) ||
816
- // The optionalType can theoretically change, so make sure to check for it.
817
- foundry . utils . hasProperty ( changes , 'system.optionalType'
818
- )
819
- &&
820
- (
786
+ ( trackedResources . includes ( 'zeropower' ) && item . type === 'optionalFeature' && item . system . optionalType === 'projectfu.zeroPower' ) ||
787
+ // The optionalType can theoretically change, so make sure to check for it.
788
+ ( foundry . utils . hasProperty ( changes , 'system.optionalType' ) &&
821
789
// Progress changes aren't relevant during create/delete hooks.
822
- ! changes ||
823
- foundry . utils . hasProperty ( changes , 'system.data.progress.current' ) ||
824
- foundry . utils . hasProperty ( changes , 'system.data.progress.max' )
825
- )
790
+ ( ! changes || foundry . utils . hasProperty ( changes , 'system.data.progress.current' ) || foundry . utils . hasProperty ( changes , 'system.data.progress.max' ) ) )
826
791
) {
827
792
this . _onUpdateHUD ( ) ;
828
793
}
@@ -831,17 +796,13 @@ export class CombatHUD extends Application {
831
796
_onModifyActiveEffect ( activeEffect , changes ) {
832
797
if (
833
798
// Is the active effect targeting an actor in the current combat?
834
- ! (
835
- activeEffect . target &&
836
- game . combat ?. combatants . some ( c => c . actor . uuid === activeEffect . target . uuid )
837
- )
838
- &&
799
+ ! ( activeEffect . target && game . combat ?. combatants . some ( ( c ) => c . actor . uuid === activeEffect . target . uuid ) ) &&
839
800
// Did the transfer property change on an effect on an item owned by an actor in the current combat?
840
801
! (
841
802
activeEffect . parent ?. documentName === 'Item' &&
842
803
activeEffect . parent . parent ?. documentName === 'Actor' &&
843
804
foundry . utils . hasProperty ( changes , 'transfer' ) &&
844
- game . combat ?. combatants . some ( c => c . actor . uuid === activeEffect . parent . parent . uuid )
805
+ game . combat ?. combatants . some ( ( c ) => c . actor . uuid === activeEffect . parent . parent . uuid )
845
806
)
846
807
) {
847
808
return ;
0 commit comments