1+ <?php
2+
3+ use GL \Math \Vec2 ;
4+ use GL \Math \Vec3 ;
5+ use GL \Math \Vec4 ;
6+ use GL \VectorGraphics \VGAlign ;
7+ use GL \VectorGraphics \VGColor ;
8+ use VISU \ECS \EntityRegisty ;
9+ use VISU \Graphics \Rendering \RenderContext ;
10+ use VISU \Graphics \Rendering \Resource \RenderTargetResource ;
11+ use VISU \Graphics \RenderTarget ;
12+ use VISU \Quickstart ;
13+ use VISU \Quickstart \QuickstartApp ;
14+ use VISU \Quickstart \QuickstartOptions ;
15+ use VISU \FlyUI \FlyUI ;
16+ use VISU \Runtime \DebugConsole ;
17+ use VISU \Signal \Dispatcher ;
18+ use VISU \Signals \Runtime \ConsoleCommandSignal ;
19+
20+ $ container = require __DIR__ . '/../bootstrap.php ' ;
21+
22+ // state for our demo
23+ $ demoState = [
24+ 'message ' => 'Welcome to the Debug Console Demo! ' ,
25+ 'counter ' => 0 ,
26+ 'color ' => new Vec3 (1.0 , 1.0 , 1.0 ),
27+ ];
28+
29+ /**
30+ * Custom QuickstartApp with Debug Console Integration
31+ */
32+ class DebugConsoleQuickstartApp extends QuickstartApp
33+ {
34+ private ?DebugConsole $ debugConsole = null ;
35+
36+ public function setDebugConsole (DebugConsole $ console ): void
37+ {
38+ $ this ->debugConsole = $ console ;
39+ }
40+
41+ public function setupDrawAfter (RenderContext $ context , RenderTargetResource $ renderTarget ): void
42+ {
43+ parent ::setupDrawAfter ($ context , $ renderTarget );
44+
45+ // attach the debug console rendering pass after all other rendering
46+ if ($ this ->debugConsole ) {
47+ $ this ->debugConsole ->attachPass ($ context ->pipeline , $ context ->resources , $ renderTarget );
48+ }
49+ }
50+ }
51+
52+ /**
53+ * Main Entry Point
54+ *
55+ * ----------------------------------------------------------------------------
56+ */
57+ $ quickstart = new Quickstart (function (QuickstartOptions $ app ) use (&$ demoState )
58+ {
59+ $ app ->windowTitle = 'VISU Debug Console Demo ' ;
60+ $ app ->appClass = DebugConsoleQuickstartApp::class;
61+
62+ $ app ->ready = function (DebugConsoleQuickstartApp $ app ) use (&$ demoState ) {
63+ // create and configure the debug console
64+ $ debugConsole = new DebugConsole (
65+ $ app ->gl ,
66+ $ app ->input ,
67+ $ app ->dispatcher
68+ );
69+
70+ // load a base font
71+ $ app ->vg ->createFont ('inter-regular ' , VISU_PATH_FRAMEWORK_RESOURCES_FONT . '/inter/Inter-Regular.ttf ' );
72+ $ app ->vg ->fontFace ('inter-regular ' );
73+
74+ // store the console in the container for easy access
75+ $ app ->container ->set ('debugConsole ' , $ debugConsole );
76+
77+ // set the debug console on our custom app
78+ $ app ->setDebugConsole ($ debugConsole );
79+
80+ // register console command handlers
81+ $ app ->dispatcher ->register (DebugConsole::EVENT_CONSOLE_COMMAND , function (ConsoleCommandSignal $ signal ) use (&$ demoState , $ app ) {
82+
83+ // handle 'help' command
84+ if ($ signal ->isAction ('help ' )) {
85+ $ signal ->console ->writeLine ('Available commands: ' );
86+ $ signal ->console ->writeLine (' help - Show this help message ' );
87+ $ signal ->console ->writeLine (' clear - Clear console history ' );
88+ $ signal ->console ->writeLine (' echo <message> - Echo a message ' );
89+ $ signal ->console ->writeLine (' set message <text> - Set display message ' );
90+ $ signal ->console ->writeLine (' set color <r> <g> <b> - Set text color (0-1) ' );
91+ $ signal ->console ->writeLine (' counter - Show current counter value ' );
92+ $ signal ->console ->writeLine (' counter inc - Increment counter ' );
93+ $ signal ->console ->writeLine (' counter dec - Decrement counter ' );
94+ $ signal ->console ->writeLine (' counter reset - Reset counter to 0 ' );
95+ return ;
96+ }
97+
98+ // handle 'clear' command
99+ if ($ signal ->isAction ('clear ' )) {
100+ $ signal ->console ->clearHistory ();
101+ $ signal ->console ->writeLine ('Console cleared. ' );
102+ return ;
103+ }
104+
105+ // handle 'echo' command
106+ if ($ signal ->isAction ('echo ' )) {
107+ $ message = implode (' ' , array_slice ($ signal ->commandParts , 1 ));
108+ $ signal ->console ->writeLine ('Echo: ' . $ message );
109+ return ;
110+ }
111+
112+ // handle 'set' commands
113+ if ($ signal ->isAction ('set ' )) {
114+ if (count ($ signal ->commandParts ) < 2 ) {
115+ $ signal ->console ->writeLine ('Usage: set <property> <value> ' );
116+ return ;
117+ }
118+
119+ $ property = $ signal ->commandParts [1 ];
120+
121+ if ($ property === 'message ' ) {
122+ $ demoState ['message ' ] = implode (' ' , array_slice ($ signal ->commandParts , 2 ));
123+ $ signal ->console ->writeLine ('Message set to: ' . $ demoState ['message ' ]);
124+ } elseif ($ property === 'color ' ) {
125+ if (count ($ signal ->commandParts ) < 5 ) {
126+ $ signal ->console ->writeLine ('Usage: set color <r> <g> <b> ' );
127+ return ;
128+ }
129+ $ r = (float )$ signal ->commandParts [2 ];
130+ $ g = (float )$ signal ->commandParts [3 ];
131+ $ b = (float )$ signal ->commandParts [4 ];
132+ $ demoState ['color ' ] = new Vec3 ($ r , $ g , $ b );
133+ $ signal ->console ->writeLine ("Color set to RGB( $ r, $ g, $ b) " );
134+ } else {
135+ $ signal ->console ->writeLine ("Unknown property: $ property " );
136+ }
137+ return ;
138+ }
139+
140+ // handle 'counter' commands
141+ if ($ signal ->isAction ('counter ' )) {
142+ if (count ($ signal ->commandParts ) === 1 ) {
143+ $ signal ->console ->writeLine ('Counter value: ' . $ demoState ['counter ' ]);
144+ return ;
145+ }
146+
147+ $ action = $ signal ->commandParts [1 ];
148+ if ($ action === 'inc ' ) {
149+ $ demoState ['counter ' ]++;
150+ $ signal ->console ->writeLine ('Counter incremented to: ' . $ demoState ['counter ' ]);
151+ } elseif ($ action === 'dec ' ) {
152+ $ demoState ['counter ' ]--;
153+ $ signal ->console ->writeLine ('Counter decremented to: ' . $ demoState ['counter ' ]);
154+ } elseif ($ action === 'reset ' ) {
155+ $ demoState ['counter ' ] = 0 ;
156+ $ signal ->console ->writeLine ('Counter reset to 0 ' );
157+ } else {
158+ $ signal ->console ->writeLine ("Unknown counter action: $ action " );
159+ }
160+ return ;
161+ }
162+
163+ // unknown command
164+ $ signal ->console ->writeLine ("Unknown command: {$ signal ->commandParts [0 ]}. Type 'help' for available commands. " );
165+ });
166+
167+ // write initial welcome message to console
168+ $ debugConsole ->writeLine ('Debug Console Demo initialized! ' );
169+ $ debugConsole ->writeLine ('Press Ctrl+C to toggle the console. ' );
170+ $ debugConsole ->writeLine ('Type "help" for available commands. ' );
171+ };
172+
173+ $ app ->draw = function (QuickstartApp $ app , RenderContext $ context , RenderTarget $ target ) use (&$ demoState )
174+ {
175+ $ target ->framebuffer ()->clear ();
176+
177+ // main layout with padding and centered content
178+ FlyUI::beginLayout (new Vec4 (50 ))
179+ ->backgroundColor (VGColor::rgb (0.05 , 0.05 , 0.1 ))
180+ ->verticalFill ()
181+ ->horizontalFill ()
182+ ->spacing (20 );
183+
184+ // title
185+ FlyUI::text ('VISU Debug Console Demo ' , VGColor::white ())
186+ ->fontSize (32 );
187+
188+ // instructions
189+ FlyUI::text ('Press Ctrl+C to toggle the debug console ' , VGColor::rgb (0.8 , 0.8 , 0.8 ))
190+ ->fontSize (16 );
191+
192+ FlyUI::spaceY (30 );
193+
194+ // current message with custom color
195+ $ color = $ demoState ['color ' ];
196+ FlyUI::text ($ demoState ['message ' ], VGColor::rgb ($ color ->x , $ color ->y , $ color ->z ))
197+ ->fontSize (24 );
198+
199+ FlyUI::spaceY (20 );
200+
201+ // counter display
202+ FlyUI::text ('Counter: ' . $ demoState ['counter ' ], VGColor::rgb (0.9 , 0.9 , 0.1 ))
203+ ->fontSize (20 );
204+
205+ FlyUI::spaceY (30 );
206+
207+ // entities section (if any exist)
208+ if (!empty ($ demoState ['entities ' ])) {
209+ FlyUI::beginSection ('Entities ' );
210+ foreach ($ demoState ['entities ' ] as $ entity ) {
211+ FlyUI::text ($ entity ['name ' ] . ' at ( ' . round ($ entity ['position ' ]->x ) . ', ' . round ($ entity ['position ' ]->y ) . ') ' , VGColor::rgb (0.2 , 0.8 , 0.4 ))
212+ ->fontSize (14 );
213+ }
214+ FlyUI::end (); // end entities section
215+
216+ FlyUI::spaceY (20 );
217+ }
218+
219+ // commands reference
220+ FlyUI::beginSection ('Console Commands ' );
221+ FlyUI::text ('Available commands: help, echo, set, counter, entities ' , VGColor::rgb (0.6 , 0.6 , 0.6 ))
222+ ->fontSize (12 );
223+ FlyUI::end (); // end commands section
224+
225+ FlyUI::end (); // end main layout
226+ };
227+ });
228+
229+ $ quickstart ->run ();
0 commit comments