@@ -18,6 +18,7 @@ import type {
1818 S2C ,
1919 ShipMovement ,
2020} from '../shared/types' ;
21+ import { clamp } from '../shared/util' ;
2122import {
2223 initAudio ,
2324 isMuted ,
@@ -32,6 +33,7 @@ import {
3233 playWarning ,
3334 setMuted ,
3435} from './audio' ;
36+ import { byId , hide , show } from './dom' ;
3537import { deriveAIActionPlan } from './game/ai-flow' ;
3638import { deriveScenarioBriefingEntries } from './game/briefing' ;
3739import { deriveBurnChangePlan } from './game/burn' ;
@@ -111,12 +113,12 @@ class GameClient {
111113 private timerWarningPlayed = false ;
112114
113115 constructor ( ) {
114- this . canvas = document . getElementById ( 'gameCanvas' ) as HTMLCanvasElement ;
116+ this . canvas = byId < HTMLCanvasElement > ( 'gameCanvas' ) ;
115117 this . renderer = new Renderer ( this . canvas ) ;
116118 this . input = new InputHandler ( this . canvas , this . renderer . camera , this . renderer . planningState ) ;
117119 this . ui = new UIManager ( ) ;
118120 this . tutorial = new Tutorial ( ) ;
119- this . tooltipEl = document . getElementById ( 'shipTooltip' ) ! ;
121+ this . tooltipEl = byId ( 'shipTooltip' ) ;
120122
121123 this . renderer . setMap ( this . map ) ;
122124 this . input . setMap ( this . map ) ;
@@ -170,11 +172,11 @@ class GameClient {
170172 } ) ;
171173
172174 // Help overlay
173- document . getElementById ( 'helpCloseBtn' ) ! . addEventListener ( 'click' , ( ) => this . toggleHelp ( ) ) ;
174- document . getElementById ( 'helpBtn' ) ! . addEventListener ( 'click' , ( ) => this . toggleHelp ( ) ) ;
175+ byId ( 'helpCloseBtn' ) . addEventListener ( 'click' , ( ) => this . toggleHelp ( ) ) ;
176+ byId ( 'helpBtn' ) . addEventListener ( 'click' , ( ) => this . toggleHelp ( ) ) ;
175177
176178 // Sound toggle
177- const soundBtn = document . getElementById ( 'soundBtn' ) ! ;
179+ const soundBtn = byId ( 'soundBtn' ) ;
178180 this . updateSoundButton ( ) ;
179181 soundBtn . addEventListener ( 'click' , ( ) => {
180182 setMuted ( ! isMuted ( ) ) ;
@@ -184,7 +186,7 @@ class GameClient {
184186 // Ship hover tooltip
185187 this . canvas . addEventListener ( 'mousemove' , ( e ) => this . updateTooltip ( e . clientX , e . clientY ) ) ;
186188 this . canvas . addEventListener ( 'mouseleave' , ( ) => {
187- this . tooltipEl . style . display = 'none' ;
189+ hide ( this . tooltipEl ) ;
188190 } ) ;
189191
190192 // Start render loop and audio
@@ -211,7 +213,7 @@ class GameClient {
211213 private setState ( newState : ClientState ) {
212214 this . state = newState ;
213215 // Hide tooltip on state changes
214- this . tooltipEl . style . display = 'none' ;
216+ hide ( this . tooltipEl ) ;
215217
216218 const entryPlan = deriveClientStateEntryPlan ( newState , this . gameState , this . playerId ) ;
217219 const screenPlan = deriveClientScreenPlan (
@@ -837,7 +839,7 @@ class GameClient {
837839 if ( maxStrength <= 0 ) return ;
838840
839841 const current = this . renderer . planningState . combatAttackStrength ?? maxStrength ;
840- this . renderer . planningState . combatAttackStrength = Math . max ( 1 , Math . min ( maxStrength , current + delta ) ) ;
842+ this . renderer . planningState . combatAttackStrength = clamp ( current + delta , 1 , maxStrength ) ;
841843 }
842844
843845 private resetCombatStrengthToMax ( ) {
@@ -1255,12 +1257,12 @@ class GameClient {
12551257 const ship = getTooltipShip ( gameState , this . state , this . playerId , hoverHex ) ;
12561258
12571259 if ( ! ship || ! gameState ) {
1258- this . tooltipEl . style . display = 'none' ;
1260+ hide ( this . tooltipEl ) ;
12591261 return ;
12601262 }
12611263
12621264 this . tooltipEl . innerHTML = buildShipTooltipHtml ( gameState , ship , this . playerId , this . map ) ;
1263- this . tooltipEl . style . display = 'block' ;
1265+ show ( this . tooltipEl , 'block' ) ;
12641266 // Position tooltip offset from cursor
12651267 this . tooltipEl . style . left = `${ screenX + 12 } px` ;
12661268 this . tooltipEl . style . top = `${ screenY - 10 } px` ;
0 commit comments