@@ -47,37 +47,101 @@ function wrapText(text, maxCharacters = 34) {
4747}
4848
4949export default class BreakoutScene extends Scene {
50- constructor ( ) {
50+ constructor ( options = { } ) {
5151 super ( ) ;
52+ this . devConsoleIntegration = options . devConsoleIntegration || null ;
53+ this . debugConfig = options . debugConfig || {
54+ debugMode : 'prod' ,
55+ debugEnabled : Boolean ( this . devConsoleIntegration ) ,
56+ } ;
5257 this . world = new BreakoutWorld ( VIEW ) ;
5358 this . inputController = null ;
5459 this . audio = new BreakoutAudio ( ) ;
5560 this . isPaused = false ;
61+ this . engineRef = null ;
5662 }
5763
5864 enter ( engine ) {
65+ this . engineRef = engine || null ;
5966 this . inputController = new BreakoutInputController ( engine . input ) ;
6067 this . audio . setAudioService ( engine . audio ?? null ) ;
6168 this . world . resetGame ( ) ;
6269 this . isPaused = false ;
6370 }
6471
65- update ( dt ) {
72+ exit ( ) {
73+ this . devConsoleIntegration ?. dispose ?. ( ) ;
74+ }
75+
76+ buildDebugDiagnosticsContext ( engine , dt ) {
77+ const safeDt = Number . isFinite ( dt ) && dt > 0 ? dt : 1 / 60 ;
78+ const fps = Math . round ( 1 / safeDt ) ;
79+ const input = engine ?. input ?? this . inputController ?. input ?? null ;
80+
81+ return {
82+ runtime : {
83+ sceneId : 'breakout-debug-showcase' ,
84+ status : this . world . status ,
85+ fps,
86+ frameTimeMs : Math . round ( safeDt * 1000 * 100 ) / 100 ,
87+ debugMode : this . debugConfig . debugMode ,
88+ debugEnabled : this . debugConfig . debugEnabled === true ,
89+ } ,
90+ entities : {
91+ count : this . world . remainingBricks + 2 ,
92+ bricksRemaining : this . world . remainingBricks ,
93+ lives : this . world . lives ,
94+ score : this . world . score ,
95+ } ,
96+ input : {
97+ left : input ?. isDown ?. ( 'ArrowLeft' ) === true || input ?. isDown ?. ( 'KeyA' ) === true ,
98+ right : input ?. isDown ?. ( 'ArrowRight' ) === true || input ?. isDown ?. ( 'KeyD' ) === true ,
99+ launch : input ?. isDown ?. ( 'Space' ) === true || input ?. isDown ?. ( 'Enter' ) === true ,
100+ pause : input ?. isDown ?. ( 'KeyP' ) === true ,
101+ } ,
102+ render : {
103+ stages : [ 'entities' , 'vector-overlay' ] ,
104+ debugSurfaceTail : [ 'debug-overlay' , 'dev-console-surface' ] ,
105+ } ,
106+ validation : {
107+ errorCount : 0 ,
108+ warningCount : 0 ,
109+ } ,
110+ } ;
111+ }
112+
113+ updateDebugIntegration ( engine , dt ) {
114+ if ( ! this . devConsoleIntegration ) {
115+ return ;
116+ }
117+
118+ this . devConsoleIntegration . update ( {
119+ engine,
120+ scene : this ,
121+ diagnosticsContext : this . buildDebugDiagnosticsContext ( engine , dt ) ,
122+ } ) ;
123+ }
124+
125+ update ( dt , engine = null ) {
126+ const engineRef = engine || this . engineRef || { input : this . inputController ?. input ?? null } ;
66127 const frame = this . inputController . getFrameState ( ) ;
67128
68129 if ( frame . exitPressed && this . isPaused ) {
69130 this . isPaused = false ;
70131 this . world . resetGame ( ) ;
132+ this . updateDebugIntegration ( engineRef , dt ) ;
71133 return ;
72134 }
73135
74136 const canPause = this . world . status === 'playing' || this . world . status === 'serve' ;
75137 if ( canPause && frame . pausePressed ) {
76138 this . isPaused = ! this . isPaused ;
139+ this . updateDebugIntegration ( engineRef , dt ) ;
77140 return ;
78141 }
79142
80143 if ( this . isPaused ) {
144+ this . updateDebugIntegration ( engineRef , dt ) ;
81145 return ;
82146 }
83147
@@ -101,6 +165,8 @@ export default class BreakoutScene extends Scene {
101165 if ( event . won ) {
102166 this . audio . playWin ( ) ;
103167 }
168+
169+ this . updateDebugIntegration ( engineRef , dt ) ;
104170 }
105171
106172 render ( renderer ) {
@@ -121,6 +187,12 @@ export default class BreakoutScene extends Scene {
121187 } else if ( this . world . status !== 'playing' ) {
122188 this . drawOverlay ( renderer ) ;
123189 }
190+
191+ if ( this . devConsoleIntegration ) {
192+ this . devConsoleIntegration . render ( renderer , {
193+ worldStages : [ 'entities' , 'vector-overlay' ] ,
194+ } ) ;
195+ }
124196 }
125197
126198 drawWalls ( renderer ) {
0 commit comments