@@ -75,12 +75,34 @@ const { POST_RENDER } = Phaser.Core.Events;
7575const { ENTER_FULLSCREEN , FULLSCREEN_FAILED , FULLSCREEN_UNSUPPORTED , LEAVE_FULLSCREEN , ORIENTATION_CHANGE , RESIZE } = Phaser . Scale . Events ;
7676
7777class DebugGameScalePlugin extends Phaser . Plugins . BasePlugin {
78+ constructor ( pluginManager ) {
79+ super ( pluginManager ) ;
80+
81+ this . x = null ;
82+ this . y = null ;
83+ this . width = 512 ;
84+ this . height = 128 ;
85+ this . font = '12px system-ui, sans-serif' ;
86+ this . lineHeight = 16 ;
87+ this . color = 'white' ;
88+ this . shadowBlur = 0 ;
89+ this . shadowOffsetX = 1 ;
90+ this . shadowOffsetY = 1 ;
91+ this . shadowColor = 'black' ;
92+ }
93+
7894 init ( data ) {
7995 if ( ! this . game . renderer . gameCanvas ) {
8096 throw new Error ( 'CANVAS renderer only' )
8197 }
8298
8399 console . info ( 'device.fullscreen.available' , this . game . device . fullscreen . available ) ;
100+
101+ for ( const dataKey in data ) {
102+ if ( this . hasOwnProperty ( dataKey ) ) {
103+ this [ dataKey ] = data [ dataKey ] ;
104+ }
105+ }
84106 }
85107
86108 start ( ) {
@@ -123,17 +145,20 @@ class DebugGameScalePlugin extends Phaser.Plugins.BasePlugin {
123145 const { scale } = this . game ;
124146 const { devicePixelRatio, screen, visualViewport } = window ;
125147 const { gameContext : c } = this . game . renderer ;
148+ const { activePointer } = this . game . input ;
126149 const cx = 0.5 * scale . width ;
127150 const cy = 0.5 * scale . height ;
128- const w = 512 ;
129- const h = 128 ;
130- let x = ~ ~ Math . max ( 0 , cx - 0.5 * w ) ;
131- let y = ~ ~ Math . max ( 0 , cy - 0.5 * h ) ;
132- const dy = 15 ;
151+ const w = this . width ;
152+ const h = this . height ;
153+ const x = this . x ?? ~ ~ Math . max ( 0 , cx - 0.5 * w ) ;
154+ let y = this . y ?? ~ ~ Math . max ( 0 , cy - 0.5 * h ) ;
155+ const dy = this . lineHeight ;
133156 const sx = 1 / scale . displayScale . x ;
134157 const sy = 1 / scale . displayScale . y ;
135158
136- c . strokeStyle = 'white' ;
159+ c . save ( ) ;
160+
161+ c . strokeStyle = this . color ;
137162 c . beginPath ( ) ;
138163 c . moveTo ( 0 , 0 ) ;
139164 c . lineTo ( scale . width , scale . height ) ;
@@ -142,28 +167,50 @@ class DebugGameScalePlugin extends Phaser.Plugins.BasePlugin {
142167 c . moveTo ( 0 , scale . height ) ;
143168 c . lineTo ( scale . width , 0 ) ;
144169 c . stroke ( ) ;
145- c . fillStyle = 'rgba(0,0,0,0.8)' ;
146- c . fillRect ( x , y , w , h ) ;
147- c . fillStyle = 'white' ;
148- c . font = 'caption' ;
149170
150- x += 8 ;
171+ strokeCircle ( c , cx , cy , 0.5 * scale . width ) ;
172+ strokeCircle ( c , cx , cy , 0.5 * scale . height ) ;
173+
174+ c . fillStyle = this . color ;
175+ c . font = this . font ;
176+ c . textBaseline = 'top' ;
177+ c . shadowBlur = this . shadowBlur ;
178+ c . shadowOffsetX = this . shadowOffsetX ;
179+ c . shadowOffsetY = this . shadowOffsetY ;
180+ c . shadowColor = this . shadowColor ;
151181
152- c . fillText ( `${ scale . width } ×${ scale . height } @ ${ xyToString ( sx , sy , 3 ) } mode=${ aspectModeToString ( scale . scaleMode ) } zoom=${ scale . zoom } ` , x , ( y += dy ) ) ;
182+ c . fillText ( `${ scale . width } ×${ scale . height } @ ${ xyToString ( sx , sy , 3 ) } mode=${ aspectModeToString ( scale . scaleMode ) } zoom=${ scale . zoom } ` , x , y ) ;
153183 c . fillText ( `game: ${ sizeToString ( scale . gameSize ) } ` , x , ( y += dy ) ) ;
154184 c . fillText ( `display: ${ sizeToString ( scale . displaySize ) } ` , x , ( y += dy ) ) ;
155- c . fillText ( `parent: ${ sizeToString ( scale . parentSize ) } ${ scale . parent } ` , x , ( y += dy ) ) ;
185+ c . fillText ( `parent: ${ sizeToString ( scale . parentSize ) } ${ scale . parent } isWindow= ${ scale . parentIsWindow } ` , x , ( y += dy ) ) ;
156186 c . fillText ( `canvas: ${ rectToString ( scale . canvasBounds ) } ` , x , ( y += dy ) ) ;
157187 c . fillText ( `orientation: ${ scale . orientation } ` , x , ( y += dy ) ) ;
188+
158189 if ( screen ) {
159190 c . fillText ( `screen: ${ screen . width } ×${ screen . height } [${ ( screen . width / screen . height ) . toFixed ( 3 ) } ] DPR=${ devicePixelRatio } ` , x , ( y += dy ) ) ;
160191 }
192+
161193 if ( visualViewport ) {
162194 const { offsetLeft, offsetTop, width, height, scale } = visualViewport ;
163195
164- c . fillText ( `visualViewport: offsetLeft =${ offsetLeft } offsetTop =${ offsetTop } width=${ width } , height=${ height } scale=${ scale } ` , x , ( y += dy ) ) ;
196+ c . fillText ( `viewport: oLeft =${ offsetLeft } oTop =${ offsetTop } width=${ width } , height=${ height } scale=${ scale } ` , x , ( y += dy ) ) ;
165197 }
198+
199+ if ( activePointer . active ) {
200+ const { x, y} = activePointer ;
201+
202+ c . fillRect ( x - 2 , y - 2 , 4 , 4 ) ;
203+ c . fillText ( vectorToString ( activePointer , 3 ) , x , y ) ;
204+ }
205+
206+ c . restore ( ) ;
166207 }
167208}
168209
210+ function strokeCircle ( c , x , y , r ) {
211+ c . beginPath ( ) ;
212+ c . arc ( x , y , r , 0 , 2 * Math . PI ) ;
213+ c . stroke ( ) ;
214+ }
215+
169216export { DebugGameScalePlugin as default } ;
0 commit comments