11import Phaser from 'phaser' ;
22
3- var Pad = Phaser . Utils . String . Pad ;
4- var ICON_OTHER = ' ' ;
5- var ICON_PAUSED = '.' ;
6- var ICON_RUNNING = '*' ;
7- var ICON_SLEEPING = '-' ;
8- var ICON_ACTIVE = 'a' ;
9- var ICON_VISIBLE = 'v' ;
10- var ICON_TRANSITIONING = 't' ;
11- var ICON_INPUT = 'i' ;
12- var ICON_KEYBOARD = 'k' ;
13- var NEWLINE = '\n' ;
14- var EMPTY = '' ;
15- var PAD_LEFT = 1 ;
16- var PAD_RIGHT = 2 ;
17- var ALIGN_LEFT = PAD_RIGHT ;
18- var ALIGN_RIGHT = PAD_LEFT ;
19- var SCENE_EVENTS = [
3+ const Pad = Phaser . Utils . String . Pad ;
4+ const ICON_OTHER = ' ' ;
5+ const ICON_PAUSED = '.' ;
6+ const ICON_RUNNING = '*' ;
7+ const ICON_SLEEPING = '-' ;
8+ const ICON_ACTIVE = 'a' ;
9+ const ICON_VISIBLE = 'v' ;
10+ const ICON_TRANSITIONING = 't' ;
11+ const ICON_INPUT = 'i' ;
12+ const ICON_KEYBOARD = 'k' ;
13+ const NEWLINE = '\n' ;
14+ const EMPTY = '' ;
15+ const PAD_LEFT = 1 ;
16+ const PAD_RIGHT = 2 ;
17+ const ALIGN_LEFT = PAD_RIGHT ;
18+ const ALIGN_RIGHT = PAD_LEFT ;
19+ const SCENE_EVENTS = [
2020 Phaser . Scenes . Events . BOOT ,
2121 Phaser . Scenes . Events . CREATE ,
2222 Phaser . Scenes . Events . DESTROY ,
@@ -28,14 +28,14 @@ var SCENE_EVENTS = [
2828 Phaser . Scenes . Events . START ,
2929 Phaser . Scenes . Events . WAKE
3030] . filter ( Boolean ) ;
31- var SCENE_TRANSITION_EVENTS = [
31+ const SCENE_TRANSITION_EVENTS = [
3232 Phaser . Scenes . Events . TRANSITION_COMPLETE ,
3333 Phaser . Scenes . Events . TRANSITION_INIT ,
3434 Phaser . Scenes . Events . TRANSITION_OUT ,
3535 Phaser . Scenes . Events . TRANSITION_START ,
3636 Phaser . Scenes . Events . TRANSITION_WAKE
3737] . filter ( Boolean ) ;
38- var SCENE_STATES = {
38+ const SCENE_STATES = {
3939 0 : 'pending' ,
4040 1 : 'init' ,
4141 2 : 'start' ,
@@ -47,8 +47,8 @@ var SCENE_STATES = {
4747 8 : 'shutdown' ,
4848 9 : 'destroyed'
4949} ;
50- var SPACE = ' ' ;
51- var VIEW_STYLE = {
50+ const SPACE = ' ' ;
51+ const VIEW_STYLE = {
5252 position : 'absolute' ,
5353 left : '0' ,
5454 top : '0' ,
@@ -61,70 +61,69 @@ var VIEW_STYLE = {
6161 color : 'white' ,
6262 pointerEvents : 'none'
6363} ;
64- var ICONS = { } ;
65- ICONS [ Phaser . Scenes . RUNNING ] = ICON_RUNNING ;
66- ICONS [ Phaser . Scenes . SLEEPING ] = ICON_SLEEPING ;
67- ICONS [ Phaser . Scenes . PAUSED ] = ICON_PAUSED ;
64+ const ICONS = {
65+ [ Phaser . Scenes . RUNNING ] : ICON_RUNNING ,
66+ [ Phaser . Scenes . SLEEPING ] : ICON_SLEEPING ,
67+ [ Phaser . Scenes . PAUSED ] : ICON_PAUSED
68+ } ;
6869
69- var Fit = function ( val , width , dir ) {
70+ const Fit = function ( val , width , dir ) {
7071 return Pad ( String ( val ) . substr ( 0 , width ) , width , SPACE , dir ) ;
7172} ;
7273
73- var getIcon = function ( scene ) {
74+ const getIcon = function ( scene ) {
7475 return ICONS [ scene . sys . settings . status ] || ICON_OTHER ;
7576} ;
7677
77- var getKey = function ( scene ) {
78+ const getKey = function ( scene ) {
7879 return scene . sys . settings . key ;
7980} ;
8081
81- var getStatus = function ( scene ) {
82+ const getStatus = function ( scene ) {
8283 return SCENE_STATES [ scene . sys . settings . status ] ;
8384} ;
8485
85- var getDisplayListLength = function ( scene ) {
86+ const getDisplayListLength = function ( scene ) {
8687 return scene . sys . displayList . length ;
8788} ;
8889
89- var getUpdateListLength = function ( scene ) {
90+ const getUpdateListLength = function ( scene ) {
9091 return scene . sys . updateList . length ;
9192} ;
9293
93- var getActiveIcon = function ( scene ) {
94+ const getActiveIcon = function ( scene ) {
9495 return scene . sys . settings . active ? ICON_ACTIVE : ICON_OTHER ;
9596} ;
9697
97- var getVisibleIcon = function ( scene ) {
98+ const getVisibleIcon = function ( scene ) {
9899 return scene . sys . settings . visible ? ICON_VISIBLE : ICON_OTHER ;
99100} ;
100101
101- var getTransitioningIcon = function ( scene ) {
102+ const getTransitioningIcon = function ( scene ) {
102103 return scene . sys . settings . isTransition ? ICON_TRANSITIONING : ICON_OTHER ;
103104} ;
104105
105- var getInputIcon = function ( scene ) {
106+ const getInputIcon = function ( scene ) {
106107 return isSceneInputActive ( scene ) ? ICON_INPUT : ICON_OTHER ;
107108} ;
108109
109- var getKeyboardIcon = function ( scene ) {
110+ const getKeyboardIcon = function ( scene ) {
110111 return isSceneKeyboardActive ( scene ) ? ICON_KEYBOARD : ICON_OTHER ;
111112} ;
112113
113- var isSceneInputActive = function ( scene ) {
114- var ref = scene . sys ;
115- var input = ref . input ;
114+ const isSceneInputActive = function ( scene ) {
115+ const { input } = scene . sys ;
116116
117117 return Boolean ( input && input . isActive ( ) ) ;
118118} ;
119119
120- var isSceneKeyboardActive = function ( scene ) {
121- var ref = scene . sys ;
122- var input = ref . input ;
120+ const isSceneKeyboardActive = function ( scene ) {
121+ const { input } = scene . sys ;
123122
124123 return Boolean ( input && input . keyboard && input . keyboard . isActive ( ) ) ;
125124} ;
126125
127- var COLS = [
126+ const COLS = [
128127 { name : 'icon' , width : 2 , pad : ALIGN_LEFT , output : getIcon } ,
129128 { name : 'key' , width : 18 , pad : ALIGN_LEFT , output : getKey } ,
130129 { name : 'status' , width : 10 , pad : ALIGN_LEFT , output : getStatus } ,
@@ -139,105 +138,99 @@ var COLS = [
139138
140139// console.table(COLS);
141140
142- var SceneWatcherPlugin = /* @__PURE__ */ ( function ( superclass ) {
143- function SceneWatcherPlugin ( pluginManager ) {
144- superclass . call ( this , pluginManager ) ;
141+ class SceneWatcherPlugin extends Phaser . Plugins . BasePlugin {
142+ constructor ( pluginManager ) {
143+ super ( pluginManager ) ;
145144 this . eventHandlers = { } ;
146145 this . transitionEventHandlers = { } ;
147146 this . output = '' ;
148147 }
149148
150- if ( superclass ) SceneWatcherPlugin . __proto__ = superclass ;
151- SceneWatcherPlugin . prototype = Object . create ( superclass && superclass . prototype ) ;
152- SceneWatcherPlugin . prototype . constructor = SceneWatcherPlugin ;
153-
154- SceneWatcherPlugin . prototype . init = function init ( ) {
149+ init ( ) {
155150 this . view = document . createElement ( 'pre' ) ;
156151 Object . assign ( this . view . style , VIEW_STYLE ) ;
157152 this . game . canvas . parentNode . append ( this . view ) ;
158153
159154 SCENE_EVENTS . forEach ( this . createEventHandler , this ) ;
160155
161156 SCENE_TRANSITION_EVENTS . forEach ( this . createTransitionEventHandler , this ) ;
162- } ;
157+ }
163158
164- SceneWatcherPlugin . prototype . start = function start ( ) {
159+ start ( ) {
165160 this . game . events . on ( 'poststep' , this . postStep , this ) ;
166- } ;
161+ }
167162
168- SceneWatcherPlugin . prototype . stop = function stop ( ) {
163+ stop ( ) {
169164 this . game . events . off ( 'poststep' , this . postStep , this ) ;
170- } ;
165+ }
171166
172- SceneWatcherPlugin . prototype . destroy = function destroy ( ) {
167+ destroy ( ) {
173168 this . unwatchAll ( ) ;
174169 this . view . remove ( ) ;
175170 this . view = null ;
176- superclass . prototype . destroy . call ( this ) ;
177- } ;
171+ super . destroy ( ) ;
172+ }
178173
179- SceneWatcherPlugin . prototype . postStep = function postStep ( ) {
180- var output = this . getOutput ( ) ;
174+ postStep ( ) {
175+ const output = this . getOutput ( ) ;
181176
182177 if ( output !== this . output ) {
183178 this . view . textContent = output ;
184179 this . output = output ;
185180 }
186- } ;
181+ }
187182
188- SceneWatcherPlugin . prototype . createEventHandler = function createEventHandler ( name ) {
183+ createEventHandler ( name ) {
189184 this . eventHandlers [ name ] = function ( arg ) {
190185 console . info ( name , ( arg . sys || arg ) . settings . key ) ;
191186 } ;
192- } ;
187+ }
193188
194- SceneWatcherPlugin . prototype . createTransitionEventHandler = function createTransitionEventHandler ( name ) {
189+ createTransitionEventHandler ( name ) {
195190 this . transitionEventHandlers [ name ] = function ( scene ) {
196191 console . info ( name , scene . sys . settings . key ) ;
197192 } ;
198- } ;
193+ }
199194
200- SceneWatcherPlugin . prototype . getOutput = function getOutput ( ) {
195+ getOutput ( ) {
201196 return this . game . scene . scenes . map ( this . getSceneOutput , this ) . join ( NEWLINE ) ;
202- } ;
197+ }
203198
204- SceneWatcherPlugin . prototype . getSceneOutput = function getSceneOutput ( scene ) {
199+ getSceneOutput ( scene ) {
205200 return COLS . map ( function ( col ) { return this . getColOutput ( col , scene ) ; } , this ) . join ( EMPTY ) ;
206- } ;
201+ }
207202
208- SceneWatcherPlugin . prototype . getColOutput = function getColOutput ( col , scene ) {
203+ getColOutput ( col , scene ) {
209204 return Fit ( col . output ( scene ) , col . width , col . pad ) ;
210- } ;
205+ }
211206
212- SceneWatcherPlugin . prototype . watchAll = function watchAll ( ) {
207+ watchAll ( ) {
213208 this . game . scene . scenes . forEach ( this . watch , this ) ;
214- } ;
209+ }
215210
216- SceneWatcherPlugin . prototype . watch = function watch ( scene ) {
217- for ( var eventName in this . eventHandlers ) {
211+ watch ( scene ) {
212+ for ( const eventName in this . eventHandlers ) {
218213 scene . sys . events . on ( eventName , this . eventHandlers [ eventName ] , this ) ;
219214 }
220215
221- for ( var eventName$1 in this . transitionEventHandlers ) {
222- scene . sys . events . on ( eventName$1 , this . transitionEventHandlers [ eventName$1 ] , this ) ;
216+ for ( const eventName in this . transitionEventHandlers ) {
217+ scene . sys . events . on ( eventName , this . transitionEventHandlers [ eventName ] , this ) ;
223218 }
224- } ;
219+ }
225220
226- SceneWatcherPlugin . prototype . unwatchAll = function unwatchAll ( ) {
221+ unwatchAll ( ) {
227222 this . game . scene . scenes . forEach ( this . unwatch , this ) ;
228- } ;
223+ }
229224
230- SceneWatcherPlugin . prototype . unwatch = function unwatch ( scene ) {
231- for ( var eventName in this . eventHandlers ) {
225+ unwatch ( scene ) {
226+ for ( const eventName in this . eventHandlers ) {
232227 scene . sys . events . off ( eventName , this . eventHandlers [ eventName ] , this ) ;
233228 }
234- } ;
229+ }
235230
236- SceneWatcherPlugin . prototype . print = function print ( ) {
231+ print ( ) {
237232 console . info ( '%c' + this . getOutput ( ) , 'font-family: monospace; white-space: pre' ) ;
238- } ;
239-
240- return SceneWatcherPlugin ;
241- } ( Phaser . Plugins . BasePlugin ) ) ;
233+ }
234+ }
242235
243236export default SceneWatcherPlugin ;
0 commit comments