1- import { UserId } from "@lefun/core" ;
1+ import { GamePlayerSettings , GameSettings , UserId } from "@lefun/core" ;
22import {
33 AutoMove ,
44 BoardMove ,
@@ -21,9 +21,12 @@ export type Board = {
2121
2222 sum : number ;
2323 lastSomeBoardMoveValue ?: number ;
24+
25+ matchSettings : Record < string , string > ;
26+ matchPlayersSettings : Record < UserId , Record < string , string > > ;
2427} ;
2528
26- export type RollGameState = GameState < Board > ;
29+ export type GS = GameState < Board > ;
2730
2831type MoveWithArgPayload = { someArg : string } ;
2932type BoardMoveWithArgPayload = { someArg : number } ;
@@ -47,7 +50,7 @@ const playerStats = [
4750] as const satisfies GameStats ;
4851
4952type PM < Payload = null > = PlayerMove <
50- RollGameState ,
53+ GS ,
5154 Payload ,
5255 PMT ,
5356 BMT ,
@@ -71,7 +74,10 @@ const roll: PM = {
7174 logPlayerStat,
7275 endMatch,
7376 } ) {
74- const diceValue = random . d6 ( ) ;
77+ const diceValue =
78+ board . matchPlayersSettings [ userId ] . dieNumFaces === "6"
79+ ? random . d6 ( )
80+ : random . dice ( 20 ) ;
7581 board . players [ userId ] . diceValue = diceValue ;
7682 board . players [ userId ] . isRolling = false ;
7783 board . sum += diceValue ;
@@ -102,7 +108,7 @@ const roll: PM = {
102108 } ,
103109} ;
104110
105- type BM < P = null > = BoardMove < RollGameState , P , PMT , BMT > ;
111+ type BM < P = null > = BoardMove < GS , P , PMT , BMT > ;
106112
107113const initMove : BM = {
108114 execute ( { board, turns } ) {
@@ -122,8 +128,41 @@ const someBoardMoveWithArgs: BM<BoardMoveWithArgPayload> = {
122128 } ,
123129} ;
124130
131+ const gameSettings : GameSettings = [
132+ {
133+ key : "setting1" ,
134+ options : [ { value : "a" } , { value : "b" } ] ,
135+ } ,
136+ { key : "setting2" , options : [ { value : "x" } , { value : "y" } ] } ,
137+ ] ;
138+
139+ const gamePlayerSettings : GamePlayerSettings = [
140+ {
141+ key : "color" ,
142+ type : "color" ,
143+ exclusive : true ,
144+ options : [
145+ { value : "red" , label : "red" } ,
146+ { value : "blue" , label : "blue" } ,
147+ { value : "green" , label : "green" } ,
148+ { value : "orange" , label : "orange" } ,
149+ { value : "pink" , label : "pink" } ,
150+ { value : "brown" , label : "brown" } ,
151+ { value : "black" , label : "black" } ,
152+ { value : "darkgreen" , label : "darkgreen" } ,
153+ { value : "darkred" , label : "darkred" } ,
154+ { value : "purple" , label : "purple" } ,
155+ ] ,
156+ } ,
157+ {
158+ key : "dieNumFaces" ,
159+ type : "string" ,
160+ options : [ { value : "6" } , { value : "20" } ] ,
161+ } ,
162+ ] ;
163+
125164export const game = {
126- initialBoards ( { players } ) {
165+ initialBoards ( { players, matchSettings , matchPlayersSettings } ) {
127166 return {
128167 board : {
129168 sum : 0 ,
@@ -132,6 +171,8 @@ export const game = {
132171 ) ,
133172 playerOrder : [ ...players ] ,
134173 currentPlayerIndex : 0 ,
174+ matchSettings,
175+ matchPlayersSettings,
135176 } ,
136177 } ;
137178 } ,
@@ -141,11 +182,13 @@ export const game = {
141182 maxPlayers : 10 ,
142183 matchStats,
143184 playerStats,
144- } satisfies Game < RollGameState , PMT , BMT > ;
185+ gameSettings,
186+ gamePlayerSettings,
187+ } satisfies Game < GS , PMT , BMT > ;
145188
146- export type RollGame = typeof game ;
189+ export type G = typeof game ;
147190
148- export const autoMove : AutoMove < RollGameState , RollGame > = ( { random } ) => {
191+ export const autoMove : AutoMove < GS , G > = ( { random } ) => {
149192 if ( random . d2 ( ) === 1 ) {
150193 return [ "moveWithArg" , { someArg : "123" } ] ;
151194 }
0 commit comments