File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ import type { Log as ScrabbleLog } from '@/ps/games/scrabble/logs';
1313import type { WinCtx as ScrabbleWinCtx } from '@/ps/games/scrabble/types' ;
1414import type { Player } from '@/ps/games/types' ;
1515
16- const schema = new mongoose . Schema ( {
16+ const schema = new mongoose . Schema < GameModel > ( {
1717 id : {
1818 type : String ,
1919 required : true ,
@@ -44,6 +44,7 @@ const schema = new mongoose.Schema({
4444 type : String ,
4545 required : true ,
4646 } ,
47+ out : Boolean ,
4748 } ,
4849 required : true ,
4950 } ,
@@ -117,6 +118,14 @@ export async function getScrabbleDex(): Promise<ScrabbleDexEntry[] | null> {
117118 const winCtx = game . winCtx as ScrabbleWinCtx | undefined ;
118119 const winners = winCtx ?. type === 'win' ? winCtx . winnerIds : [ ] ;
119120 const logs = game . log . map < ScrabbleLog > ( log => JSON . parse ( log ) ) ;
121+ if ( winCtx ?. type === 'dq' ) {
122+ const leftUsers = logs . filter ( log => log . action === 'dq' || log . action === 'forfeit' ) . map ( log => log . turn ) ;
123+ winners . push (
124+ ...Object . values ( game . players )
125+ . map ( player => player . turn )
126+ . filter ( player => ! leftUsers . includes ( player ) )
127+ ) ;
128+ }
120129 return logs
121130 . filterMap < ScrabbleDexEntry [ ] > ( log => {
122131 if ( log . action !== 'play' ) return ;
Original file line number Diff line number Diff line change 11import type { DIRECTION } from '@/ps/games/scrabble/constants' ;
22import type { BoardTile , Points } from '@/ps/games/scrabble/types' ;
3- import type { BaseLog } from '@/ps/games/types' ;
3+ import type { BaseLog , BaseLogAction } from '@/ps/games/types' ;
44import type { Satisfies , SerializedInstance } from '@/types/common' ;
55import type { Point } from '@/utils/grid' ;
66
7- export type Log = Satisfies <
8- BaseLog ,
9- {
10- time : Date ;
11- turn : string ;
12- } & (
13- | {
14- action : 'play' ;
15- ctx : {
16- points : Points ;
17- tiles : BoardTile [ ] ;
18- dir : DIRECTION ;
19- point : Point ;
20- newTiles : string [ ] ;
21- rack : string [ ] ;
22- words : Record < string , number > ;
23- } ;
24- }
25- | { action : 'exchange' ; ctx : { tiles : string [ ] ; newTiles : string [ ] ; rack : string [ ] } }
26- | { action : 'pass' ; ctx : { rack : string [ ] } }
27- )
28- > ;
7+ export type Log =
8+ | Satisfies <
9+ BaseLog ,
10+ {
11+ time : Date ;
12+ turn : string ;
13+ } & (
14+ | {
15+ action : 'play' ;
16+ ctx : {
17+ points : Points ;
18+ tiles : BoardTile [ ] ;
19+ dir : DIRECTION ;
20+ point : Point ;
21+ newTiles : string [ ] ;
22+ rack : string [ ] ;
23+ words : Record < string , number > ;
24+ } ;
25+ }
26+ | { action : 'exchange' ; ctx : { tiles : string [ ] ; newTiles : string [ ] ; rack : string [ ] } }
27+ | { action : 'pass' ; ctx : { rack : string [ ] } }
28+ )
29+ >
30+ | BaseLogAction ;
2931
3032export type APILog = SerializedInstance < Log > ;
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ export type RenderCtx = {
4848 turn : string ;
4949 selected ?: Point | null ;
5050} ;
51- export type WinCtx = { type : 'win' ; winnerIds : string [ ] ; score : State [ 'score' ] } | { type : 'draw' } ;
51+ export type WinCtx = { type : 'win' ; winnerIds : string [ ] ; score : State [ 'score' ] } | { type : 'draw' } | { type : 'dq' } ;
5252
5353export type Word = { word : string ; baseScore : number ; bonuses : BonusReducer [ ] } ;
5454export type WordScore = [ times : number , plus : number ] ;
Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ export type ActionResponse<T = null> = { success: true; data: T } | { success: f
6868export type EndType = 'regular' | 'force' | 'dq' | 'loss' ;
6969
7070export type BaseLog = { action : string ; time : Date ; turn : string | null ; ctx : unknown } ;
71+ export type BaseLogAction = { action : 'dq' | 'forfeit' | 'skip' ; turn : string ; ctx : null } & BaseLog ;
7172
7273export type CommonLog < Turn extends string = string > = Satisfies <
7374 BaseLog ,
Original file line number Diff line number Diff line change @@ -9,8 +9,10 @@ export default async function init() {
99 await connection ;
1010 await loadCommands ( ) ;
1111 if ( IS_ENABLED . DB ) {
12- await loadAlts ( ) ;
13- await loadSeens ( ) ;
12+ if ( process . env . NODE_ENV !== 'development' ) {
13+ await loadAlts ( ) ;
14+ await loadSeens ( ) ;
15+ }
1416 await loadRoomConfigs ( ) ;
1517 }
1618}
You can’t perform that action at this time.
0 commit comments