2
2
3
3
namespace App \Livewire ;
4
4
5
+ use App \Events \BuzzerPressed ;
5
6
use App \Events \ClueRevealed ;
6
7
use App \Events \DailyDoubleTriggered ;
7
8
use App \Events \GameStateChanged ;
10
11
use App \Models \Game ;
11
12
use App \Models \Team ;
12
13
use App \Services \BuzzerService ;
14
+ use App \Services \GameService ;
13
15
use App \Services \ScoringService ;
14
16
use Livewire \Attributes \On ;
15
17
use Livewire \Component ;
@@ -26,6 +28,9 @@ class HostControl extends Component
26
28
public ?Team $ currentTeam = null ;
27
29
28
30
public $ teams = [];
31
+
32
+ // Lightning Round state
33
+ public ?Team $ lightningAnsweringTeam = null ;
29
34
30
35
// Daily Double
31
36
public bool $ showDailyDoubleWager = false ;
@@ -120,28 +125,44 @@ public function selectCurrentTeam($teamId)
120
125
public function triggerBuzzer ($ teamId )
121
126
{
122
127
$ team = Team::find ($ teamId );
123
-
124
- if (!$ team ) {
128
+
129
+ if (! $ team ) {
125
130
return ;
126
131
}
127
132
128
- // Set the team as active
129
- $ this ->currentTeam = $ team ;
130
- $ this -> game -> current_team_id = $ teamId ;
131
- $ this ->game ->save ( );
133
+ // Check if we're in lightning round
134
+ if ( $ this ->game -> status === ' lightning_round ' ) {
135
+ // For lightning round, dispatch the buzzer event to the lightning round component
136
+ broadcast ( new GameStateChanged ( $ this ->game ->id , ' buzzer-pressed ' , [ ' teamId ' => $ teamId ]) );
132
137
133
- // Broadcast team selection to all clients
134
- broadcast (new GameStateChanged ( $ this -> game -> id , ' team-selected ' , [ ' teamId ' => $ teamId ] ));
138
+ // Also broadcast the buzzer sound
139
+ broadcast (new BuzzerPressed ( $ team ));
135
140
136
- // Broadcast buzzer event to trigger sound on game board
137
- broadcast (new \App \Events \BuzzerPressed ($ team ));
138
-
139
- Log::info ('Buzzer triggered manually from host control ' , [
140
- 'game_id ' => $ this ->game ->id ,
141
- 'team_id ' => $ teamId ,
142
- 'team_name ' => $ team ->name ,
143
- 'set_as_active ' => true ,
144
- ]);
141
+ Log::info ('Lightning round buzzer triggered manually from host control ' , [
142
+ 'game_id ' => $ this ->game ->id ,
143
+ 'team_id ' => $ teamId ,
144
+ 'team_name ' => $ team ->name ,
145
+ ]);
146
+ } else {
147
+ // Regular game mode
148
+ // Set the team as active
149
+ $ this ->currentTeam = $ team ;
150
+ $ this ->game ->current_team_id = $ teamId ;
151
+ $ this ->game ->save ();
152
+
153
+ // Broadcast team selection to all clients
154
+ broadcast (new GameStateChanged ($ this ->game ->id , 'team-selected ' , ['teamId ' => $ teamId ]));
155
+
156
+ // Broadcast buzzer event to trigger sound on game board
157
+ broadcast (new BuzzerPressed ($ team ));
158
+
159
+ Log::info ('Buzzer triggered manually from host control ' , [
160
+ 'game_id ' => $ this ->game ->id ,
161
+ 'team_id ' => $ teamId ,
162
+ 'team_name ' => $ team ->name ,
163
+ 'set_as_active ' => true ,
164
+ ]);
165
+ }
145
166
}
146
167
147
168
// Clue Control
@@ -241,27 +262,7 @@ private function calculateWagerOptions()
241
262
// Sort options
242
263
sort ($ options );
243
264
244
- // Limit to 8 options for UI consistency
245
- if (count ($ options ) > 8 ) {
246
- // Keep first few, some middle values, and the max
247
- $ filtered = [];
248
- $ filtered [] = $ options [0 ]; // minimum
249
-
250
- // Add evenly distributed values
251
- $ step = (count ($ options ) - 2 ) / 6 ; // We want 6 middle values
252
- for ($ i = 1 ; $ i <= 6 ; $ i ++) {
253
- $ index = min (round ($ i * $ step ), count ($ options ) - 2 );
254
- if (! in_array ($ options [$ index ], $ filtered )) {
255
- $ filtered [] = $ options [$ index ];
256
- }
257
- }
258
-
259
- $ filtered [] = $ options [count ($ options ) - 1 ]; // maximum
260
-
261
- $ this ->wagerOptions = $ filtered ;
262
- } else {
263
- $ this ->wagerOptions = $ options ;
264
- }
265
+ $ this ->wagerOptions = $ options ;
265
266
}
266
267
267
268
public function markCorrect ($ teamId = null )
@@ -435,11 +436,42 @@ public function startLightningRound()
435
436
return ;
436
437
}
437
438
438
- $ this ->game ->update (['status ' => 'lightning_round ' ]);
439
+ // Transition to lightning round
440
+ $ gameService = app (GameService::class);
441
+ $ gameService ->transitionToLightningRound ($ this ->game ->id );
442
+
439
443
$ this ->game ->refresh ();
440
444
441
- // Redirect to lightning round
442
- return redirect ()->route ('game.lightning ' , ['gameId ' => $ this ->game ->id ]);
445
+ // Broadcast event to tell game board to navigate to lightning round
446
+ broadcast (new GameStateChanged ($ this ->game ->id , 'lightning-round-started ' ));
447
+
448
+ // Host stays on the control page, no redirect
449
+ $ this ->refreshGame ();
450
+ }
451
+
452
+ // Lightning Round Question Controls
453
+ public function markLightningCorrect ()
454
+ {
455
+ $ this ->dispatch ('lightning-mark-correct ' )->to (LightningRound::class);
456
+ $ this ->lightningAnsweringTeam = null ; // Reset after marking
457
+ }
458
+
459
+ public function markLightningIncorrect ()
460
+ {
461
+ $ this ->dispatch ('lightning-mark-incorrect ' )->to (LightningRound::class);
462
+ // Don't reset here as another team might buzz in
463
+ }
464
+
465
+ public function skipLightningQuestion ()
466
+ {
467
+ $ this ->dispatch ('lightning-skip-question ' )->to (LightningRound::class);
468
+ $ this ->lightningAnsweringTeam = null ; // Reset when skipping
469
+ }
470
+
471
+ public function nextLightningQuestion ()
472
+ {
473
+ $ this ->dispatch ('lightning-next-question ' )->to (LightningRound::class);
474
+ $ this ->lightningAnsweringTeam = null ; // Reset for next question
443
475
}
444
476
445
477
// Listen for buzzer events from main display
@@ -450,6 +482,15 @@ public function handleBuzzerWebhook($teamId)
450
482
$ this ->currentTeam = Team::find ($ teamId );
451
483
}
452
484
}
485
+
486
+ #[On('buzzer-pressed ' )]
487
+ public function handleBuzzerPressed ($ teamId )
488
+ {
489
+ // Track which team buzzed in during lightning round
490
+ if ($ this ->game ->status === 'lightning_round ' ) {
491
+ $ this ->lightningAnsweringTeam = Team::find ($ teamId );
492
+ }
493
+ }
453
494
454
495
private function refreshGame ()
455
496
{
0 commit comments