@@ -338,19 +338,27 @@ <h1 class="title">🩸 Blood on the Clocktower</h1>
338338
339339 < div id ="storytellerSetup " class ="hidden ">
340340 < div class ="input-group ">
341+ < label > Game Mode:</ label >
342+ < div style ="display: flex; gap: 10px; margin-bottom: 15px; ">
343+ < button type ="button " id ="newGameBtn " onclick ="selectGameMode('new') " style ="flex: 1; "> 🎲 New Game</ button >
344+ < button type ="button " id ="reconnectBtn " onclick ="selectGameMode('reconnect') " style ="flex: 1; background: #666; "> 🔄 Reconnect</ button >
345+ </ div >
346+ </ div >
347+
348+ < div class ="input-group ">
341349 < label for ="gameRoom "> Game Room ID:</ label >
342350 < input type ="text " id ="gameRoom " placeholder ="Enter or create room ID ">
343- < button type ="button " onclick ="generateRoomId() "> Generate New Room</ button >
351+ < button type ="button " id =" generateRoomBtn " onclick ="generateRoomId() "> Generate New Room</ button >
344352 </ div >
345353
346- < div class ="input-group ">
354+ < div id =" newGameFields " class ="input-group ">
347355 < label for ="scriptSelect "> Script:</ label >
348356 < select id ="scriptSelect ">
349357 < option value =""> Select a script...</ option >
350358 </ select >
351359 </ div >
352360
353- < div class ="input-group ">
361+ < div id =" playerNamesField " class ="input-group ">
354362 < label for ="playerNames "> Player Names (one per line):</ label >
355363 < textarea id ="playerNames " rows ="6 " placeholder ="Alice Bob Charlie Diana Eve "> </ textarea >
356364 </ div >
@@ -373,7 +381,7 @@ <h1 class="title">🩸 Blood on the Clocktower</h1>
373381 < div id ="roomStatus " class ="hidden "> </ div >
374382 </ div >
375383
376- < button onclick ="joinGame() "> Start Game</ button >
384+ < button id =" joinGameBtn " onclick ="joinGame() "> Start Game</ button >
377385 </ div >
378386
379387 <!-- Game Screen -->
@@ -413,9 +421,9 @@ <h3>Storyteller Controls</h3>
413421 </ div >
414422
415423 < div class ="template-buttons ">
416- < button class ="template-btn " onclick ="useSimpleTemplate('Your role is [ROLE]. {role}', 'role') "> Assign Role</ button >
424+ < button class ="template-btn " onclick ="useSimpleTemplate('Your role is {role}', 'role') "> Assign Role</ button >
417425 < button class ="template-btn " onclick ="usePromptTemplate('Choose a player tonight.', 'I choose {player}.', ['player']) "> Ask: Choose Player</ button >
418- < button class ="template-btn " onclick ="useSimpleTemplate('You learn: {info}', 'text ') "> Give Info</ button >
426+ < button class ="template-btn " onclick ="useSimpleTemplate('You learn: {info}', 'info ') "> Give Info</ button >
419427 < button class ="template-btn " onclick ="usePromptTemplate('Use your ability tonight.', 'I use my ability on {player}.', ['player']) "> Use Ability</ button >
420428 </ div >
421429 </ div >
@@ -654,6 +662,34 @@ <h4 id="templateTitle">Template</h4>
654662 } ;
655663
656664 let currentScript = null ;
665+
666+ let gameMode = 'new' ; // 'new' or 'reconnect'
667+
668+ function selectGameMode ( mode ) {
669+ gameMode = mode ;
670+ const newBtn = document . getElementById ( 'newGameBtn' ) ;
671+ const reconnectBtn = document . getElementById ( 'reconnectBtn' ) ;
672+ const generateBtn = document . getElementById ( 'generateRoomBtn' ) ;
673+ const newGameFields = document . getElementById ( 'newGameFields' ) ;
674+ const playerNamesField = document . getElementById ( 'playerNamesField' ) ;
675+ const joinBtn = document . getElementById ( 'joinGameBtn' ) ;
676+
677+ if ( mode === 'new' ) {
678+ newBtn . style . background = 'linear-gradient(45deg, #ff6b6b, #ee5a24)' ;
679+ reconnectBtn . style . background = '#666' ;
680+ generateBtn . style . display = 'inline-block' ;
681+ newGameFields . style . display = 'block' ;
682+ playerNamesField . style . display = 'block' ;
683+ joinBtn . textContent = 'Start Game' ;
684+ } else {
685+ newBtn . style . background = '#666' ;
686+ reconnectBtn . style . background = 'linear-gradient(45deg, #ff6b6b, #ee5a24)' ;
687+ generateBtn . style . display = 'none' ;
688+ newGameFields . style . display = 'none' ;
689+ playerNamesField . style . display = 'none' ;
690+ joinBtn . textContent = 'Rejoin Game' ;
691+ }
692+ }
657693
658694 // Initialize user type selection and populate scripts
659695 document . getElementById ( 'userType' ) . addEventListener ( 'change' , function ( ) {
@@ -754,39 +790,44 @@ <h4 id="templateTitle">Template</h4>
754790
755791 if ( userType === 'storyteller' ) {
756792 currentRoom = document . getElementById ( 'gameRoom' ) . value . trim ( ) ;
757- const scriptId = document . getElementById ( 'scriptSelect' ) . value ;
758793
759794 if ( ! currentRoom ) {
760795 alert ( 'Please enter a room ID' ) ;
761796 return ;
762797 }
763798
764- if ( ! scriptId ) {
765- alert ( 'Please select a script' ) ;
766- return ;
767- }
768-
769- const playerNamesText = document . getElementById ( 'playerNames' ) . value . trim ( ) ;
770- if ( ! playerNamesText ) {
771- alert ( 'Please enter player names' ) ;
772- return ;
799+ if ( gameMode === 'new' ) {
800+ const scriptId = document . getElementById ( 'scriptSelect' ) . value ;
801+ console . log ( 'scriptId:' , scriptId ) ;
802+ console . log ( 'EMBEDDED_SCRIPTS[scriptId]:' , EMBEDDED_SCRIPTS [ scriptId ] ) ;
803+
804+ if ( ! scriptId ) {
805+ alert ( 'Please select a script' ) ;
806+ return ;
807+ }
808+
809+ const playerNamesText = document . getElementById ( 'playerNames' ) . value . trim ( ) ;
810+ if ( ! playerNamesText ) {
811+ alert ( 'Please enter player names' ) ;
812+ return ;
813+ }
814+
815+ // Load the selected script
816+ currentScript = EMBEDDED_SCRIPTS [ scriptId ] ;
817+ players = playerNamesText . split ( '\n' ) . map ( name => name . trim ( ) ) . filter ( name => name ) ;
818+
819+ // Populate target player dropdown for new games
820+ const targetSelect = document . getElementById ( 'targetPlayer' ) ;
821+ targetSelect . innerHTML = '<option value="">Select player...</option>' ;
822+ players . forEach ( player => {
823+ const option = document . createElement ( 'option' ) ;
824+ option . value = player ;
825+ option . textContent = player ;
826+ targetSelect . appendChild ( option ) ;
827+ } ) ;
773828 }
774-
775- // Load the selected script
776- currentScript = EMBEDDED_SCRIPTS [ scriptId ] ;
777- players = playerNamesText . split ( '\n' ) . map ( name => name . trim ( ) ) . filter ( name => name ) ;
829+
778830 currentUser = 'Storyteller' ;
779-
780- // Populate target player dropdown
781- const targetSelect = document . getElementById ( 'targetPlayer' ) ;
782- targetSelect . innerHTML = '<option value="">Select player...</option>' ;
783- players . forEach ( player => {
784- const option = document . createElement ( 'option' ) ;
785- option . value = player ;
786- option . textContent = player ;
787- targetSelect . appendChild ( option ) ;
788- } ) ;
789-
790831 } else {
791832 currentRoom = document . getElementById ( 'gameRoomPlayer' ) . value . trim ( ) ;
792833 currentUser = document . getElementById ( 'playerName' ) . value ;
@@ -869,7 +910,8 @@ <h4 id="templateTitle">Template</h4>
869910 }
870911
871912 function sendGameSetup ( ) {
872- const setupMessage = {
913+ console . log ( 'sendGameSetup called, currentScript:' , currentScript ) ; // Add this line
914+ const setupMessage = {
873915 type : 'game_setup' ,
874916 players : players ,
875917 script : currentScript ,
0 commit comments