@@ -10,29 +10,31 @@ import { useState } from 'react';
1010import BOTCCharacterSelectTable from './character-select' ;
1111import {
1212 BOTCPlayer ,
13- CharacterID ,
13+ CharacterId ,
14+ createPlayer ,
1415 EDITIONS ,
1516 getAllCharacters ,
1617} from './characters' ;
1718import NightOrder from './night-order' ;
1819import Grimoire from './grimoire' ;
20+ import { shuffle , zip } from 'utils/array' ;
1921
2022export const metadata : Metadata = {
2123 title : 'Blood on the Clocktower' ,
2224} ;
2325
2426interface GameState {
25- numberOfPlayers : number ;
2627 editionId : string ;
27- characters : CharacterID [ ] ;
28+ characters : CharacterId [ ] ;
29+ lobby : { name : string ; corpsId ?: string } [ ] ;
2830 players : BOTCPlayer [ ] ;
2931}
3032
3133const newGameState : GameState = {
32- numberOfPlayers : 7 ,
3334 editionId : 'trouble-brewing' ,
3435 characters : [ ] ,
3536 players : [ ] ,
37+ lobby : [ ] ,
3638} ;
3739
3840interface BloodOnTheClocktowerElementProps {
@@ -51,19 +53,24 @@ const BloodOnTheClocktowerElement = ({
5153 _setSearchParamsGameState ( JSON . stringify ( newGameState ) ) ;
5254 } ;
5355
56+ const assignCharacters = ( ) => {
57+ const players = zip (
58+ shuffle ( gameState . characters . slice ( ) ) ,
59+ gameState . lobby ,
60+ ) . map ( ( [ characterId , player ] ) => createPlayer ( { ...player , characterId } ) ) ;
61+ setGameState ( {
62+ ...gameState ,
63+ lobby : gameState . lobby . slice ( players . length ) ,
64+ players,
65+ } ) ;
66+ } ;
67+
5468 const edition = EDITIONS . find (
5569 ( edition ) => edition . id === gameState . editionId ,
5670 ) ;
5771
58- if ( ! edition ) {
59- return < div > NO EDITION FOUND</ div > ;
60- }
61-
6272 const detailsStartOpen = true ;
6373
64- // TODO: Change this to alive players
65- const alivePlayers = gameState . characters ;
66-
6774 return (
6875 < div className = 'flex max-w-3xl flex-col gap-2' >
6976 < h2 > Bleck on the Corpstower</ h2 >
@@ -82,35 +89,59 @@ const BloodOnTheClocktowerElement = ({
8289 value = { gameState . editionId }
8390 />
8491 < div className = 'h-2' />
85- < Modal
86- title = { `Select Characters - ${ edition . name } ` }
87- target = {
88- < Button >
89- < IconUser />
90- Select Characters
91- </ Button >
92- }
93- withCloseButton
94- >
95- < BOTCCharacterSelectTable
96- numberOfPlayers = { gameState . numberOfPlayers }
97- onNumberOfPlayersChange = { ( n ) => {
98- setGameState ( { ...gameState , numberOfPlayers : n } ) ;
92+ { edition && (
93+ < div className = 'flex gap-4' >
94+ < Modal
95+ title = { `Select Characters - ${ edition . name } ` }
96+ target = {
97+ < Button >
98+ < IconUser />
99+ Select Characters
100+ </ Button >
101+ }
102+ withCloseButton
103+ >
104+ < BOTCCharacterSelectTable
105+ edition = { edition }
106+ onSelectedCharactersChange = { ( characters ) => {
107+ setGameState ( { ...gameState , characters } ) ;
108+ } }
109+ />
110+ </ Modal >
111+ { gameState . characters . length > 0 && (
112+ < Button onClick = { assignCharacters } > Assign characters</ Button >
113+ ) }
114+ </ div >
115+ ) }
116+ < div className = 'h-2' />
117+ < div className = 'flex gap-4' >
118+ < Button
119+ onClick = { ( ) => {
120+ setGameState ( newGameState ) ;
99121 } }
100- edition = { edition }
101- onSelectedCharactersChange = { ( characters ) => {
102- setGameState ( { ...gameState , characters } ) ;
122+ >
123+ Clear cache
124+ </ Button >
125+ < Button
126+ onClick = { ( ) => {
127+ setGameState ( {
128+ ...gameState ,
129+ lobby : [
130+ { name : 'Hannes' } ,
131+ { name : 'Hannes2' } ,
132+ { name : 'Bartolomeus' } ,
133+ { name : 'Kyoto' } ,
134+ { name : 'Jörgen' } ,
135+ { name : 'Pratkvarn' } ,
136+ { name : 'Pelle' } ,
137+ { name : 'Lars' } ,
138+ ] ,
139+ } ) ;
103140 } }
104- />
105- </ Modal >
106- < div className = 'h-2' />
107- < Button
108- onClick = { ( ) => {
109- setGameState ( newGameState ) ;
110- } }
111- >
112- Clear cache
113- </ Button >
141+ >
142+ Populate lobby
143+ </ Button >
144+ </ div >
114145 </ details >
115146 < details open = { detailsStartOpen } className = 'border p-2 shadow-md' >
116147 < summary className = 'select-none' > Grimoire</ summary >
@@ -119,15 +150,16 @@ const BloodOnTheClocktowerElement = ({
119150 characters = { gameState . characters }
120151 />
121152 </ details >
122- < details open = { detailsStartOpen } className = 'border p-2 shadow-md' >
123- < summary className = 'select-none' > Night Order</ summary >
124- < div className = 'h-2' />
125- < NightOrder
126- alivePlayers = { alivePlayers }
127- numberOfPlayers = { gameState . numberOfPlayers }
128- allCharacters = { getAllCharacters ( edition ) }
129- />
130- </ details >
153+ { edition && gameState . players . length > 0 && (
154+ < details open = { detailsStartOpen } className = 'border p-2 shadow-md' >
155+ < summary className = 'select-none' > Night Order</ summary >
156+ < div className = 'h-2' />
157+ < NightOrder
158+ players = { gameState . players }
159+ allCharacters = { getAllCharacters ( edition ) }
160+ />
161+ </ details >
162+ ) }
131163 </ div >
132164 ) ;
133165} ;
0 commit comments