11import { SETTINGS } from '../settings.js' ;
2- import { SystemControls } from '../helpers/system-controls.mjs' ;
32import { SYSTEM } from '../helpers/config.mjs' ;
43import { FUHooks } from '../hooks.mjs' ;
54import { FUCombat } from './combat.mjs' ;
65import { FUPartySheet } from '../sheets/actor-party-sheet.mjs' ;
76import { systemTemplatePath } from '../helpers/system-utils.mjs' ;
87
98Hooks . once ( 'setup' , ( ) => {
10- if ( game . settings . get ( SYSTEM , SETTINGS . experimentalCombatHud ) ) {
11- Hooks . on ( SystemControls . HOOK_GET_SYSTEM_TOOLS , ( tools ) => {
12- tools [ 'projectfu-combathud-toggle' ] = CombatHUD . getToggleControlButton ( ) ;
13- tools [ 'projectfu-combathud-saved-toggle' ] = CombatHUD . getSavedControlButton ( ) ;
14- tools [ 'projectfu-combathud-reset' ] = CombatHUD . getResetControlButton ( ) ;
15- } ) ;
9+ /**
10+ * @typedef HudButtonData
11+ * @property {string } name
12+ * @property {string } icon
13+ * @property {boolean } [visible]
14+ * @property {boolean } [toggle]
15+ * @property {boolean } [active]
16+ * @property {(event: Event, active: boolean) => void } [onClick] A callback invoked when the tool is activated
17+ * or deactivated
18+ */
19+
20+ /**
21+ * @param {HTMLElement } containerElement
22+ * @param {HudButtonData } buttonData
23+ */
24+ function createButton ( containerElement , buttonData ) {
25+ const button = document . createElement ( 'button' ) ;
26+ button . type = 'button' ;
27+ button . classList . add ( 'control' , 'ui-control' ) ;
28+ button . innerHTML = `<i class="${ buttonData . icon } "></i>` ;
29+ button . dataset . tooltip = game . i18n . localize ( buttonData . name ) ;
30+
31+ if ( buttonData . toggle ) {
32+ let active = buttonData . active ;
33+ button . classList . add ( 'toggle' ) ;
34+ button . ariaPressed = active ;
35+ button . addEventListener ( 'click' , ( e ) => {
36+ active = ! active ;
37+ button . ariaPressed = active ;
38+ if ( buttonData . onClick ) {
39+ buttonData . onClick ( e , active ) ;
40+ }
41+ } ) ;
42+ } else {
43+ if ( buttonData . onClick ) {
44+ button . addEventListener ( 'click' , ( e ) => {
45+ buttonData . onClick ( e , false ) ;
46+ } ) ;
47+ }
48+ }
49+
50+ containerElement . appendChild ( button ) ;
1651 }
52+
53+ Hooks . on ( 'renderCombatTracker' , ( app , element ) => {
54+ if ( game . settings . get ( SYSTEM , SETTINGS . experimentalCombatHud ) ) {
55+ const containerElement = document . createElement ( 'div' ) ;
56+ containerElement . id = 'combat-hud-controls' ;
57+ createButton ( containerElement , CombatHUD . getToggleControlButton ( ) ) ;
58+ createButton ( containerElement , CombatHUD . getSavedControlButton ( ) ) ;
59+ createButton ( containerElement , CombatHUD . getResetControlButton ( ) ) ;
60+
61+ const combatTrackerSection = element . querySelector ( '#combat-tracker' ) . parentElement ;
62+ combatTrackerSection . prepend ( containerElement ) ;
63+ }
64+ } ) ;
1765} ) ;
1866
1967export class CombatHUD extends foundry . applications . api . HandlebarsApplicationMixin ( foundry . applications . api . ApplicationV2 ) {
@@ -433,7 +481,7 @@ export class CombatHUD extends foundry.applications.api.HandlebarsApplicationMix
433481 /**
434482 * Determine whether or not the current user has sufficient permission to edit
435483 * @param {HTMLElement } elem - The HTMLElement (or jQuery wrapper) for the ActiveEffect in question
436- * @param {" update" | " delete" } op - The operation to check -- either "update" or "delete"
484+ * @param {' update' | ' delete' } op - The operation to check -- either "update" or "delete"
437485 * @returns
438486 */
439487 _canModifyEffectContextMenu ( elem , op = 'update' ) {
@@ -918,7 +966,7 @@ export class CombatHUD extends foundry.applications.api.HandlebarsApplicationMix
918966 this . render ( true ) ;
919967 }
920968
921- _onUpdateCombatant ( combatant , changes ) {
969+ _onUpdateCombatant ( ) {
922970 this . _onUpdateHUD ( ) ;
923971 }
924972
@@ -1161,17 +1209,18 @@ export class CombatHUD extends foundry.applications.api.HandlebarsApplicationMix
11611209 CombatHUD . update ( ) ;
11621210 }
11631211
1212+ /**
1213+ * @return {HudButtonData }
1214+ */
11641215 static getToggleControlButton ( ) {
11651216 return {
1166- name : 'projectfu-combathud-toggle' ,
1167- title : game . i18n . localize ( 'FU.CombatHudControlButtonTitle' ) ,
1217+ name : game . i18n . localize ( 'FU.CombatHudControlButtonTitle' ) ,
11681218 icon : 'fas fa-thumbtack' ,
1169- button : false ,
11701219 toggle : true ,
11711220 visible : game . combat ? game . combat . isActive : false ,
11721221 active : ! game . settings . get ( SYSTEM , SETTINGS . optionCombatHudMinimized ) ,
11731222
1174- onChange : ( ) => {
1223+ onClick : ( ) => {
11751224 console . log ( 'Click toggle' ) ;
11761225 if ( game . settings . get ( SYSTEM , SETTINGS . optionCombatHudMinimized ) ) {
11771226 CombatHUD . restore ( ) ;
@@ -1182,32 +1231,34 @@ export class CombatHUD extends foundry.applications.api.HandlebarsApplicationMix
11821231 } ;
11831232 }
11841233
1234+ /**
1235+ * @return {HudButtonData }
1236+ */
11851237 static getSavedControlButton ( ) {
11861238 return {
1187- name : 'projectfu-combathud-saved-toggle' ,
1188- title : game . i18n . localize ( 'FU.CombatHudSaveButtonTitle' ) ,
1239+ name : game . i18n . localize ( 'FU.CombatHudSaveButtonTitle' ) ,
11891240 icon : 'fas fa-lock' ,
1190- button : false ,
11911241 toggle : true ,
11921242 visible : game . combat ? game . combat . isActive : false ,
11931243 active : game . settings . get ( SYSTEM , SETTINGS . optionCombatHudSaved ) ,
1194- onChange : ( ) => {
1244+ onClick : ( ) => {
11951245 console . log ( 'Click save' ) ;
11961246 const isSaved = game . settings . get ( SYSTEM , SETTINGS . optionCombatHudSaved ) ;
11971247 game . settings . set ( SYSTEM , SETTINGS . optionCombatHudSaved , ! isSaved ) ;
11981248 } ,
11991249 } ;
12001250 }
12011251
1252+ /**
1253+ * @return {HudButtonData }
1254+ */
12021255 static getResetControlButton ( ) {
12031256 return {
1204- name : 'projectfu-combathud-reset' ,
1205- title : game . i18n . localize ( 'FU.CombatHudResetButtonTitle' ) ,
1257+ name : game . i18n . localize ( 'FU.CombatHudResetButtonTitle' ) ,
12061258 icon : 'fas fa-undo' ,
1207- button : true ,
12081259 // visible: game.combat ? game.combat.isActive : false,
12091260 visible : true ,
1210- onChange : ( ) => {
1261+ onClick : ( ) => {
12111262 console . log ( 'Click reset' ) ;
12121263 CombatHUD . reset ( ) ;
12131264 } ,
@@ -1224,7 +1275,10 @@ export class CombatHUD extends foundry.applications.api.HandlebarsApplicationMix
12241275 async _getCombatantThumbnail ( combatant ) {
12251276 if ( combatant . _videoSrc && ! combatant . img ) {
12261277 if ( combatant . _thumb ) return combatant . _thumb ;
1227- return ( combatant . _thumb = await game . video . createThumbnail ( combatant . _videoSrc , { width : 200 , height : 200 } ) ) ;
1278+ return ( combatant . _thumb = await game . video . createThumbnail ( combatant . _videoSrc , {
1279+ width : 200 ,
1280+ height : 200 ,
1281+ } ) ) ;
12281282 }
12291283 return combatant . img ?? CONST . DEFAULT_TOKEN ;
12301284 }
0 commit comments