1
- var ref = Phaser . Scale ;
2
- var ScaleModes = ref . ScaleModes ;
3
- var MAX_VALUE = Number . MAX_VALUE ;
1
+ const { ScaleModes } = Phaser . Scale ;
2
+ const { MAX_VALUE } = Number ;
4
3
5
- var aspectModeNames = { } ;
4
+ const aspectModeNames = { } ;
6
5
7
- for ( var name in ScaleModes ) {
6
+ for ( const name in ScaleModes ) {
8
7
aspectModeNames [ ScaleModes [ name ] ] = name ;
9
8
}
10
9
11
- var orientationNames = { } ;
12
- orientationNames [ Phaser . Scale . Orientation . LANDSCAPE ] = 'landscape' ;
13
- orientationNames [ Phaser . Scale . Orientation . PORTRAIT ] = 'portrait' ;
10
+ const orientationNames = {
11
+ [ Phaser . Scale . Orientation . LANDSCAPE ] : 'landscape' ,
12
+ [ Phaser . Scale . Orientation . PORTRAIT ] : 'portrait'
13
+ } ;
14
14
15
- var getSizeMaxString = function ( size ) {
16
- return ( size . maxWidth < MAX_VALUE || size . maxHeight < MAX_VALUE ) ? ( " max=" + ( size . maxWidth ) + "×" + ( size . maxHeight ) ) : ''
15
+ const getSizeMaxString = function ( size ) {
16
+ return ( size . maxWidth < MAX_VALUE || size . maxHeight < MAX_VALUE ) ? ` max=${ size . maxWidth } × ${ size . maxHeight } ` : ''
17
17
} ;
18
18
19
- var getSizeMinString = function ( size ) {
20
- return ( size . minWidth > 0 || size . minHeight > 0 ) ? ( " min=" + ( size . minWidth ) + "×" + ( size . minHeight ) ) : ''
19
+ const getSizeMinString = function ( size ) {
20
+ return ( size . minWidth > 0 || size . minHeight > 0 ) ? ` min=${ size . minWidth } × ${ size . minHeight } ` : ''
21
21
} ;
22
22
23
- var getSizeSnapString = function ( size , precision ) {
24
- var ref = size . snapTo ;
25
- var x = ref . x ;
26
- var y = ref . y ;
23
+ const getSizeSnapString = function ( size , precision ) {
24
+ const { x, y } = size . snapTo ;
27
25
28
- return ( x === 0 && y === 0 ) ? '' : ( " snap=" + ( vectorToString ( size . snapTo , precision ) ) )
26
+ return ( x === 0 && y === 0 ) ? '' : ` snap=${ vectorToString ( size . snapTo , precision ) } `
29
27
} ;
30
28
31
- var aspectModeToString = function ( mode ) {
29
+ const aspectModeToString = function ( mode ) {
32
30
return aspectModeNames [ mode ]
33
31
} ;
34
32
35
- var vectorToString = function ( vec , precision ) {
36
- if ( precision === void 0 ) precision = 3 ;
37
-
38
- return ( "(" + ( vec . x . toFixed ( precision ) ) + ", " + ( vec . y . toFixed ( precision ) ) + ")" )
33
+ const vectorToString = function ( vec , precision = 3 ) {
34
+ return `(${ vec . x . toFixed ( precision ) } , ${ vec . y . toFixed ( precision ) } )`
39
35
} ;
40
36
41
- var xyToString = function ( x , y , precision ) {
42
- if ( precision === void 0 ) precision = 3 ;
43
-
44
- return ( "(" + ( x . toFixed ( precision ) ) + ", " + ( y . toFixed ( precision ) ) + ")" )
37
+ const xyToString = function ( x , y , precision = 3 ) {
38
+ return `(${ x . toFixed ( precision ) } , ${ y . toFixed ( precision ) } )`
45
39
} ;
46
40
47
- var sizeToString = function ( size ) {
48
- return ( ( size . width . toFixed ( 1 ) ) + "×" + ( size . height . toFixed ( 1 ) ) + " [" + ( size . aspectRatio . toFixed ( 3 ) ) + " ] mode=" + ( aspectModeToString ( size . aspectMode ) ) + ( getSizeMaxString ( size ) ) + ( getSizeMinString ( size ) ) + ( getSizeSnapString ( size , 1 ) ) + ( size . _parent ? ( ' ← ' + sizeToString ( size . _parent ) ) : '' ) )
41
+ const sizeToString = function ( size ) {
42
+ return ` ${ size . width . toFixed ( 1 ) } × ${ size . height . toFixed ( 1 ) } [ ${ size . aspectRatio . toFixed ( 3 ) } ] mode=${ aspectModeToString ( size . aspectMode ) } ${ getSizeMaxString ( size ) } ${ getSizeMinString ( size ) } ${ getSizeSnapString ( size , 1 ) } ${ size . _parent ? ( ` ← ${ sizeToString ( size . _parent ) } ` ) : '' } `
49
43
} ;
50
44
51
- var rectToString = function ( rect , precision ) {
52
- if ( precision === void 0 ) precision = 1 ;
53
-
54
- return ( "x=" + ( rect . x . toFixed ( precision ) ) + " y=" + ( rect . y . toFixed ( precision ) ) + " w=" + ( rect . width . toFixed ( precision ) ) + " h=" + ( rect . height . toFixed ( precision ) ) )
45
+ const rectToString = function ( rect , precision = 1 ) {
46
+ return `x=${ rect . x . toFixed ( precision ) } y=${ rect . y . toFixed ( precision ) } w=${ rect . width . toFixed ( precision ) } h=${ rect . height . toFixed ( precision ) } `
55
47
} ;
56
48
57
- var logEnterFullscreen = function ( ) {
49
+ const logEnterFullscreen = function ( ) {
58
50
console . info ( 'enter fullscreen' ) ;
59
51
} ;
60
52
61
- var logFullscreenFailed = function ( ) {
53
+ const logFullscreenFailed = function ( ) {
62
54
console . info ( 'fullscreen failed' ) ;
63
55
} ;
64
56
65
- var logFullscreenUnsupported = function ( ) {
57
+ const logFullscreenUnsupported = function ( ) {
66
58
console . info ( 'fullscreen unsupported' ) ;
67
59
} ;
68
60
69
- var logLeaveFullscreen = function ( ) {
61
+ const logLeaveFullscreen = function ( ) {
70
62
console . info ( 'leave fullscreen' ) ;
71
63
} ;
72
64
73
- var logOrientationChange = function ( orientation ) {
65
+ const logOrientationChange = function ( orientation ) {
74
66
console . info ( 'orientation change' , orientationNames [ orientation ] ) ;
75
67
} ;
76
68
77
- var logResize = function ( game , base , display , prevWidth , prevHeight ) {
69
+ const logResize = function ( game , base , display , prevWidth , prevHeight ) {
78
70
console . debug ( 'resize' , sizeToString ( display ) ) ;
79
71
} ;
80
72
81
- var ref$1 = Phaser . Core . Events ;
82
- var POST_RENDER = ref$1 . POST_RENDER ;
83
-
84
- var ref$1$1 = Phaser . Scale . Events ;
85
- var ENTER_FULLSCREEN = ref$1$1 . ENTER_FULLSCREEN ;
86
- var FULLSCREEN_FAILED = ref$1$1 . FULLSCREEN_FAILED ;
87
- var FULLSCREEN_UNSUPPORTED = ref$1$1 . FULLSCREEN_UNSUPPORTED ;
88
- var LEAVE_FULLSCREEN = ref$1$1 . LEAVE_FULLSCREEN ;
89
- var ORIENTATION_CHANGE = ref$1$1 . ORIENTATION_CHANGE ;
90
- var RESIZE = ref$1$1 . RESIZE ;
91
-
92
- var DebugGameScalePlugin = /*@__PURE__ */ ( function ( superclass ) {
93
- function DebugGameScalePlugin ( ) {
94
- superclass . apply ( this , arguments ) ;
95
- }
73
+ const { POST_RENDER } = Phaser . Core . Events ;
96
74
97
- if ( superclass ) DebugGameScalePlugin . __proto__ = superclass ;
98
- DebugGameScalePlugin . prototype = Object . create ( superclass && superclass . prototype ) ;
99
- DebugGameScalePlugin . prototype . constructor = DebugGameScalePlugin ;
75
+ const { ENTER_FULLSCREEN , FULLSCREEN_FAILED , FULLSCREEN_UNSUPPORTED , LEAVE_FULLSCREEN , ORIENTATION_CHANGE , RESIZE } = Phaser . Scale . Events ;
100
76
101
- DebugGameScalePlugin . prototype . init = function init ( data ) {
77
+ class DebugGameScalePlugin extends Phaser . Plugins . BasePlugin {
78
+ init ( data ) {
102
79
if ( ! this . game . renderer . gameCanvas ) {
103
80
throw new Error ( 'CANVAS renderer only' )
104
81
}
105
82
106
83
console . info ( 'device.fullscreen.available' , this . game . device . fullscreen . available ) ;
107
- } ;
84
+ }
108
85
109
- DebugGameScalePlugin . prototype . start = function start ( ) {
86
+ start ( ) {
110
87
this . game . events . on ( POST_RENDER , this . render , this ) ;
111
88
112
- var ref = this . game . scale ;
113
- var parent = ref . parent ;
89
+ const { parent } = this . game . scale ;
114
90
115
91
if ( parent ) {
116
92
parent . style . outline = 'thick solid rgba(255,0,0,0.5)' ;
@@ -123,13 +99,12 @@ var DebugGameScalePlugin = /*@__PURE__*/(function (superclass) {
123
99
. on ( LEAVE_FULLSCREEN , logLeaveFullscreen )
124
100
. on ( ORIENTATION_CHANGE , logOrientationChange )
125
101
. on ( RESIZE , logResize ) ;
126
- } ;
102
+ }
127
103
128
- DebugGameScalePlugin . prototype . stop = function stop ( ) {
104
+ stop ( ) {
129
105
this . game . events . off ( POST_RENDER , this . render , this ) ;
130
106
131
- var ref = this . game . scale ;
132
- var parent = ref . parent ;
107
+ const { parent } = this . game . scale ;
133
108
134
109
if ( parent ) {
135
110
parent . style . outline = '' ;
@@ -142,25 +117,21 @@ var DebugGameScalePlugin = /*@__PURE__*/(function (superclass) {
142
117
. off ( LEAVE_FULLSCREEN , logLeaveFullscreen )
143
118
. off ( ORIENTATION_CHANGE , logOrientationChange )
144
119
. off ( RESIZE , logResize ) ;
145
- } ;
146
-
147
- DebugGameScalePlugin . prototype . render = function render ( ) {
148
- var ref = this . game ;
149
- var scale = ref . scale ;
150
- var devicePixelRatio = window . devicePixelRatio ;
151
- var screen = window . screen ;
152
- var visualViewport = window . visualViewport ;
153
- var ref$1 = this . game . renderer ;
154
- var c = ref$1 . gameContext ;
155
- var cx = 0.5 * scale . width ;
156
- var cy = 0.5 * scale . height ;
157
- var w = 512 ;
158
- var h = 128 ;
159
- var x = ~ ~ Math . max ( 0 , cx - 0.5 * w ) ;
160
- var y = ~ ~ Math . max ( 0 , cy - 0.5 * h ) ;
161
- var dy = 15 ;
162
- var sx = 1 / scale . displayScale . x ;
163
- var sy = 1 / scale . displayScale . y ;
120
+ }
121
+
122
+ render ( ) {
123
+ const { scale } = this . game ;
124
+ const { devicePixelRatio, screen, visualViewport } = window ;
125
+ const { gameContext : c } = this . game . renderer ;
126
+ const cx = 0.5 * scale . width ;
127
+ 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 ;
133
+ const sx = 1 / scale . displayScale . x ;
134
+ const sy = 1 / scale . displayScale . y ;
164
135
165
136
c . strokeStyle = 'white' ;
166
137
c . beginPath ( ) ;
@@ -178,27 +149,21 @@ var DebugGameScalePlugin = /*@__PURE__*/(function (superclass) {
178
149
179
150
x += 8 ;
180
151
181
- c . fillText ( ( ( scale . width ) + "×" + ( scale . height ) + " @ " + ( xyToString ( sx , sy , 3 ) ) + " mode=" + ( aspectModeToString ( scale . scaleMode ) ) + " zoom=" + ( scale . zoom ) ) , x , ( y += dy ) ) ;
182
- c . fillText ( ( " game: " + ( sizeToString ( scale . gameSize ) ) ) , x , ( y += dy ) ) ;
183
- c . fillText ( ( " display: " + ( sizeToString ( scale . displaySize ) ) ) , x , ( y += dy ) ) ;
184
- c . fillText ( ( " parent: " + ( sizeToString ( scale . parentSize ) ) + " " + ( scale . parent ) ) , x , ( y += dy ) ) ;
185
- c . fillText ( ( " canvas: " + ( rectToString ( scale . canvasBounds ) ) ) , x , ( y += dy ) ) ;
186
- c . fillText ( ( " orientation: " + ( scale . orientation ) ) , x , ( y += dy ) ) ;
152
+ c . fillText ( ` ${ scale . width } × ${ scale . height } @ ${ xyToString ( sx , sy , 3 ) } mode=${ aspectModeToString ( scale . scaleMode ) } zoom=${ scale . zoom } ` , x , ( y += dy ) ) ;
153
+ c . fillText ( ` game: ${ sizeToString ( scale . gameSize ) } ` , x , ( y += dy ) ) ;
154
+ c . fillText ( ` display: ${ sizeToString ( scale . displaySize ) } ` , x , ( y += dy ) ) ;
155
+ c . fillText ( ` parent: ${ sizeToString ( scale . parentSize ) } ${ scale . parent } ` , x , ( y += dy ) ) ;
156
+ c . fillText ( ` canvas: ${ rectToString ( scale . canvasBounds ) } ` , x , ( y += dy ) ) ;
157
+ c . fillText ( ` orientation: ${ scale . orientation } ` , x , ( y += dy ) ) ;
187
158
if ( screen ) {
188
- c . fillText ( ( " screen: " + ( screen . width ) + "×" + ( screen . height ) + " [" + ( ( screen . width / screen . height ) . toFixed ( 3 ) ) + " ] DPR=" + devicePixelRatio ) , x , ( y += dy ) ) ;
159
+ c . fillText ( ` screen: ${ screen . width } × ${ screen . height } [ ${ ( screen . width / screen . height ) . toFixed ( 3 ) } ] DPR=${ devicePixelRatio } ` , x , ( y += dy ) ) ;
189
160
}
190
161
if ( visualViewport ) {
191
- var offsetLeft = visualViewport . offsetLeft ;
192
- var offsetTop = visualViewport . offsetTop ;
193
- var width = visualViewport . width ;
194
- var height = visualViewport . height ;
195
- var scale$1 = visualViewport . scale ;
162
+ const { offsetLeft, offsetTop, width, height, scale } = visualViewport ;
196
163
197
- c . fillText ( ( " visualViewport: offsetLeft=" + offsetLeft + " offsetTop=" + offsetTop + " width=" + width + " , height=" + height + " scale=" + scale$1 ) , x , ( y += dy ) ) ;
164
+ c . fillText ( ` visualViewport: offsetLeft=${ offsetLeft } offsetTop=${ offsetTop } width=${ width } , height=${ height } scale=${ scale } ` , x , ( y += dy ) ) ;
198
165
}
199
- } ;
200
-
201
- return DebugGameScalePlugin ;
202
- } ( Phaser . Plugins . BasePlugin ) ) ;
166
+ }
167
+ }
203
168
204
- export default DebugGameScalePlugin ;
169
+ export { DebugGameScalePlugin as default } ;
0 commit comments