From 36977a92c4b928664d2bbd4890819c5a594d3731 Mon Sep 17 00:00:00 2001 From: Akita Noek Date: Thu, 14 Dec 2023 19:47:18 -0700 Subject: [PATCH] Typing updates for enabling noImplicitAny on ogs --- src/GobanCore.ts | 24 +++- src/protocol/ServerToClient.ts | 213 +++++++++++++++++---------------- 2 files changed, 126 insertions(+), 111 deletions(-) diff --git a/src/GobanCore.ts b/src/GobanCore.ts index 92019fb4..08dc95d5 100644 --- a/src/GobanCore.ts +++ b/src/GobanCore.ts @@ -48,7 +48,12 @@ import { import { AdHocClock, AdHocPlayerClock, AdHocPauseControl } from "./AdHocFormat"; import { MessageID } from "./messages"; import { GobanSocket, GobanSocketEvents } from "./GobanSocket"; -import { ServerToClient } from "./protocol/ServerToClient"; +import { + ServerToClient, + GameChatAnalysisMessage, + GameChatReviewMessage, + GameChatTranslatedMessage, +} from "./protocol"; import { EventEmitter } from "eventemitter3"; declare let swal: any; @@ -115,8 +120,14 @@ export interface GobanBounds { export interface GobanChatLogLine { chat_id: string; - // TODO: there are other fields in here, we need to flesh them out, and/or - // figure out if we even still need this + body: string | GameChatAnalysisMessage | GameChatReviewMessage | GameChatTranslatedMessage; + date: number; + move_number: number; + from?: number; + moves?: string; + channel: string; + player_id: number; + username?: string; } export type GobanChatLog = Array<{ @@ -244,7 +255,7 @@ export interface StateUpdateEvents { outcome: (d: string) => void; review_owner_id: (d: number | undefined) => void; review_controller_id: (d: number | undefined) => void; - stalling_score_estimate: (d: ServerToClient["game/:id/stalling_score_estimate"]) => void; + stalling_score_estimate: ServerToClient["game/:id/stalling_score_estimate"]; } export interface Events extends StateUpdateEvents { @@ -1858,9 +1869,10 @@ export abstract class GobanCore extends EventEmitter { } return { i: i, j: j, valid: i >= 0 && j >= 0 && i < this.width && j < this.height }; } - public setAnalyzeTool(tool: AnalysisTool, subtool: AnalysisSubTool) { + public setAnalyzeTool(tool: AnalysisTool, subtool: AnalysisSubTool | undefined | null) { this.analyze_tool = tool; - this.analyze_subtool = subtool; + this.analyze_subtool = subtool ?? "alternate"; + if (tool === "stone" && subtool === "black") { this.edit_color = "black"; } else if (tool === "stone" && subtool === "white") { diff --git a/src/protocol/ServerToClient.ts b/src/protocol/ServerToClient.ts index 78a93e72..9d97f360 100644 --- a/src/protocol/ServerToClient.ts +++ b/src/protocol/ServerToClient.ts @@ -341,101 +341,7 @@ export interface ServerToClient { }) => void; "seekgraph/global": ( - data: - | { - /** The ID of the challenge */ - challenge_id: number; - /** The entry should be deleted if this field exists and is true */ - delete: true; - } - | { - /** The ID of the challenge */ - challenge_id: number; - /** If exists and is true, the game has been started and the entry should be removed from the seek graph */ - game_started?: true; - /** The game id */ - game_id: number; - /** Player ID of the creator */ - creator: number; - /** Black player */ - black: User; - /** White player */ - white: User; - /** Time control system */ - time_control: string; - /** Time control parameters */ - time_control_parameters: JGOFTimeControl; - /** Rengo game if true */ - rengo?: true; - /** Player ids of the players on the Black team */ - rengo_black_team?: number[]; - /** Player ids of the players on the White team */ - rengo_white_team?: number[]; - /** Wether it's a Casual mode rengo game */ - rengo_casual_mode?: boolean; - /** Whether the rengo game with automatically start */ - rengo_auto_start?: boolean; - } - | { - /** The ID of the challenge */ - challenge_id: number; - /** User id of the player who is looking for a game */ - user_id: number; - /** Username of the player looking for the game */ - username: string; - /** Their ranking **/ - ranking: number; - /** If they are a professional player */ - professional: boolean; - /** Minimum rank allowed to accept the game */ - min_rank: number; - /** Maximum rank allowed to accept the game */ - max_rank: number; - /** The game ID */ - game_id: number; - /** Game name */ - name: string; - /** If the game is ranked */ - ranked: boolean; - /** The game handicap */ - handicap: number | null; - /** Komi */ - komi: number | null; - /** Rules being used */ - rules: string; - /** Board width */ - width: number; - /** Board height */ - height: number; - /** Color the accepting player will be */ - challenger_color: "black" | "white" | "automatic"; - /** If analysis is disabled */ - disable_analysis: boolean; - /** Time control system type */ - time_control: string; - /** Time control parameters */ - time_control_parameters: JGOFTimeControl; - /** Average time per move */ - time_per_move: number; - /** If it's a rengo game */ - rengo: boolean; - /** Player ids of people that have been nominated to play */ - rengo_nominees: number[]; - /** Player ids of the players on the Black team */ - rengo_black_team: number[]; - /** Player ids of the players on the White team */ - rengo_white_team: number[]; - /** All player ids involved in the game */ - rengo_participants: number[]; - /** If the game is a casual rengo game */ - rengo_casual_mode: boolean; - /** If the rengo game will automatically start */ - rengo_auto_start: boolean; - /** If the game is only joinable by invitation */ - invite_only: boolean; - /** A UUID for the invitation */ - uuid: string; - }, + messages: (SeekgraphDeleteMessage | SeekgraphStartedMessage | SeekgraphChallengeMessage)[], ) => void; /** Informs the client the player is scheduled to resign if not cleared */ @@ -444,7 +350,7 @@ export interface ServerToClient { game_id: number; /** The player id */ player_id: number; - /** Whent he auto resign will happen */ + /** When the auto resign will happen */ expiration: number; }) => void; [k: `game/${number}/auto_resign`]: ServerToClient["game/:id/auto_resign"]; @@ -621,15 +527,7 @@ export interface ServerToClient { [k: `game/${number}/undo_requested`]: ServerToClient["game/:id/undo_requested"]; /** A score estimation result has been broadcast, this is used for avoiding game stalling */ - "game/:id/stalling_score_estimate": (data?: { - move_number: number; - predicted_winner: "black" | "white"; - game_id: number; - removed: string; - score: number; - win_rate: number; - ownership: any[]; - }) => void; + "game/:id/stalling_score_estimate": (data?: StallingScoreEstimate) => void; [ k: `game/${number}/stalling_score_estimate` ]: ServerToClient["game/:id/stalling_score_estimate"]; @@ -725,3 +623,108 @@ export interface GameClock { }; }; } + +export interface SeekgraphDeleteMessage { + /** The ID of the challenge */ + challenge_id: number; + /** The entry should be deleted if this field exists and is true */ + delete: true; +} +export interface SeekgraphStartedMessage { + /** The ID of the challenge */ + challenge_id: number; + /** If exists and is true, the game has been started and the entry should be removed from the seek graph */ + game_started?: true; + /** The game id */ + game_id: number; + /** Player ID of the creator */ + creator: number; + /** Black player */ + black: User; + /** White player */ + white: User; + /** Time control system */ + time_control: string; + /** Time control parameters */ + time_control_parameters: JGOFTimeControl; + /** Rengo game if true */ + rengo?: true; + /** Player ids of the players on the Black team */ + rengo_black_team?: number[]; + /** Player ids of the players on the White team */ + rengo_white_team?: number[]; + /** Wether it's a Casual mode rengo game */ + rengo_casual_mode?: boolean; + /** Whether the rengo game with automatically start */ + rengo_auto_start?: boolean; +} +export interface SeekgraphChallengeMessage { + /** The ID of the challenge */ + challenge_id: number; + /** User id of the player who is looking for a game */ + user_id: number; + /** Username of the player looking for the game */ + username: string; + /** Their ranking **/ + ranking: number; + /** If they are a professional player */ + professional: boolean; + /** Minimum rank allowed to accept the game */ + min_rank: number; + /** Maximum rank allowed to accept the game */ + max_rank: number; + /** The game ID */ + game_id: number; + /** Game name */ + name: string; + /** If the game is ranked */ + ranked: boolean; + /** The game handicap */ + handicap: number | null; + /** Komi */ + komi: number | null; + /** Rules being used */ + rules: string; + /** Board width */ + width: number; + /** Board height */ + height: number; + /** Color the accepting player will be */ + challenger_color: "black" | "white" | "automatic"; + /** If analysis is disabled */ + disable_analysis: boolean; + /** Time control system type */ + time_control: string; + /** Time control parameters */ + time_control_parameters: JGOFTimeControl; + /** Average time per move */ + time_per_move: number; + /** If it's a rengo game */ + rengo: boolean; + /** Player ids of people that have been nominated to play */ + rengo_nominees: number[]; + /** Player ids of the players on the Black team */ + rengo_black_team: number[]; + /** Player ids of the players on the White team */ + rengo_white_team: number[]; + /** All player ids involved in the game */ + rengo_participants: number[]; + /** If the game is a casual rengo game */ + rengo_casual_mode: boolean; + /** If the rengo game will automatically start */ + rengo_auto_start: boolean; + /** If the game is only joinable by invitation */ + invite_only: boolean; + /** A UUID for the invitation */ + uuid: string; +} + +export interface StallingScoreEstimate { + move_number: number; + predicted_winner: "black" | "white"; + game_id: number; + removed: string; + score: number; + win_rate: number; + ownership: any[]; +}