Skip to content

Commit

Permalink
Typing updates for enabling noImplicitAny on ogs
Browse files Browse the repository at this point in the history
  • Loading branch information
anoek committed Dec 15, 2023
1 parent 1e951e9 commit 36977a9
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 111 deletions.
24 changes: 18 additions & 6 deletions src/GobanCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<{
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -1858,9 +1869,10 @@ export abstract class GobanCore extends EventEmitter<Events> {
}
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") {
Expand Down
213 changes: 108 additions & 105 deletions src/protocol/ServerToClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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"];
Expand Down Expand Up @@ -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"];
Expand Down Expand Up @@ -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[];
}

0 comments on commit 36977a9

Please sign in to comment.