Skip to content

Commit f1157b0

Browse files
committed
chore: Rename 'Game' to 'BaseGame'
1 parent 77101d8 commit f1157b0

10 files changed

Lines changed: 26 additions & 25 deletions

File tree

src/cache/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { JudgementGame } from '@/discord/commands/judgement';
22
import type { Games } from '@/ps/games';
3-
import type { BaseGame } from '@/ps/games/game';
3+
import type { CommonGame } from '@/ps/games/game';
44
import type { PSCronJobManager } from '@/ps/handlers/cron';
55
import type { DiscCommand, PSCommand } from '@/types/chat';
66
import type { PSRoomConfig } from '@/types/ps';
@@ -22,7 +22,7 @@ export const PSQuoteRoomPrefs: { [key: string]: { room: string; at: Date } } = {
2222
export const PSCronJobs: { manager: PSCronJobManager | null } = { manager: null };
2323

2424
// Games
25-
export const PSGames: { [key in keyof Games]?: Record<string, BaseGame> } = {};
25+
export const PSGames: { [key in keyof Games]?: Record<string, CommonGame> } = {};
2626

2727
// Discord
2828
export const DiscCommands: { [key: string]: DiscCommand & { path: string; isAlias?: boolean; slash: SlashCommandBuilder } } = {};

src/ps/commands/games/core.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { toId } from '@/tools';
88
import { ChatError } from '@/utils/chatError';
99

1010
import type { NoTranslate, ToTranslate, TranslationFn } from '@/i18n/types';
11-
import type { BaseGame } from '@/ps/games/game';
11+
import type { CommonGame } from '@/ps/games/game';
1212
import type { PSCommand } from '@/types/chat';
1313
import type { Room } from 'ps-client';
1414
import type { HTMLopts } from 'ps-client/classes/common';
@@ -31,7 +31,7 @@ type RoomContext = { room: Room; $T: TranslationFn };
3131
export const command: PSCommand[] = Object.entries(Games).map(([_gameId, Game]): PSCommand => {
3232
const gameId = _gameId as keyof Games;
3333

34-
type GameFilter = (game: BaseGame) => boolean;
34+
type GameFilter = (game: CommonGame) => boolean;
3535

3636
function getByContext(ctx: SearchContext): GameFilter {
3737
return game => {
@@ -76,7 +76,7 @@ export const command: PSCommand[] = Object.entries(Games).map(([_gameId, Game]):
7676
searchCtx: SearchContext,
7777
roomCtx: RoomContext,
7878
restCtx: string
79-
): BaseGame | null {
79+
): CommonGame | null {
8080
if (!PSGames[gameId]) return null;
8181
if (Game.meta.players === 'single') {
8282
const inferredSpecifier = typeof specifier === 'string' ? `#${Game.meta.abbr}-${toId(specifier)}` : specifier;
@@ -125,7 +125,7 @@ export const command: PSCommand[] = Object.entries(Games).map(([_gameId, Game]):
125125
return null;
126126
}
127127

128-
function getGame(feed: string, searchCtx: SearchContext, roomCtx: RoomContext): { game: BaseGame; ctx: string } {
128+
function getGame(feed: string, searchCtx: SearchContext, roomCtx: RoomContext): { game: CommonGame; ctx: string } {
129129
const { $T } = roomCtx;
130130
const [fullSpec, fullCtx] = feed.lazySplit(/\s*,\s*/, 1);
131131
const fullGame = gameFromContext(fullSpec, searchCtx, roomCtx, fullCtx);

src/ps/games/chess/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Chess as ChessLib } from 'chess.js';
22
import { EmbedBuilder } from 'discord.js';
33

44
import { render } from '@/ps/games/chess/render';
5-
import { Game } from '@/ps/games/game';
5+
import { BaseGame } from '@/ps/games/game';
66
import { pick } from '@/utils/pick';
77

88
import type { TranslatedText } from '@/i18n/types';
@@ -19,7 +19,7 @@ function isValidSquare(input: string): input is Square {
1919
return /^[a-h][1-9]$/.test(input);
2020
}
2121

22-
export class Chess extends Game<State> {
22+
export class Chess extends BaseGame<State> {
2323
selected: Square | null = null;
2424
showMoves: Move[] = [];
2525
drawOffered: null | string = null;

src/ps/games/connectfour/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { EmbedBuilder } from 'discord.js';
22

33
import { WINNER_ICON } from '@/discord/constants/emotes';
44
import { render } from '@/ps/games/connectfour/render';
5-
import { Game, createGrid } from '@/ps/games/game';
5+
import { BaseGame, createGrid } from '@/ps/games/game';
66
import { repeat } from '@/utils/repeat';
77

88
import type { TranslatedText } from '@/i18n/types';
@@ -15,7 +15,7 @@ import type { ReactElement } from 'react';
1515

1616
export { meta } from '@/ps/games/connectfour/meta';
1717

18-
export class ConnectFour extends Game<State> {
18+
export class ConnectFour extends BaseGame<State> {
1919
log: Log[] = [];
2020
winCtx?: WinCtx | { type: EndType };
2121
cache: Record<string, Record<Turn, number>> = {};

src/ps/games/game.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const backupKeys = ['state', 'started', 'turn', 'turns', 'seed', 'players', 'the
2626
* This is the shared code for all games. To check the game-specific code, refer to the
2727
* extended constructor in `$game/index.ts` and go through the `action` method.
2828
*/
29-
export class Game<State extends BaseState> {
29+
export class BaseGame<State extends BaseState> {
3030
meta: Meta;
3131
id: string;
3232
$T: TranslationFn;
@@ -121,9 +121,9 @@ export class Game<State extends BaseState> {
121121
}
122122
persist(ctx: BaseContext) {
123123
if (!PSGames[this.meta.id]) PSGames[this.meta.id] = {};
124-
PSGames[this.meta.id]![this.id] = this as BaseGame;
124+
PSGames[this.meta.id]![this.id] = this as CommonGame;
125125
if (ctx.backup) {
126-
const parsedBackup: Pick<BaseGame, (typeof backupKeys)[number]> = JSON.parse(ctx.backup);
126+
const parsedBackup: Pick<CommonGame, (typeof backupKeys)[number]> = JSON.parse(ctx.backup);
127127
backupKeys.forEach(key => {
128128
switch (key) {
129129
case 'log':
@@ -486,4 +486,5 @@ export function createGrid<T>(x: number, y: number, fill: (x: number, y: number)
486486
return Array.from({ length: x }).map((_, i) => Array.from({ length: y }).map((_, j) => fill(i, j)));
487487
}
488488

489-
export type BaseGame = Game<BaseState>;
489+
/** Non-generic type representing only the things all games have in common */
490+
export type CommonGame = BaseGame<BaseState>;

src/ps/games/lightsout/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { type ReactElement } from 'react';
22

3-
import { Game, createGrid } from '@/ps/games/game';
3+
import { BaseGame, createGrid } from '@/ps/games/game';
44
import { render, renderCloseSignups } from '@/ps/games/lightsout/render';
55
import { deepClone } from '@/utils/deepClone';
66
import { type Point, parsePoint, stepPoint } from '@/utils/grid';
@@ -13,7 +13,7 @@ import type { User } from 'ps-client';
1313

1414
export { meta } from '@/ps/games/lightsout/meta';
1515

16-
export class LightsOut extends Game<State> {
16+
export class LightsOut extends BaseGame<State> {
1717
ended = false;
1818
size: [number, number];
1919
setBy: User | null = null;

src/ps/games/mastermind/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { type ReactElement } from 'react';
22

3-
import { Game } from '@/ps/games/game';
3+
import { BaseGame } from '@/ps/games/game';
44
import { render, renderCloseSignups } from '@/ps/games/mastermind/render';
55
import { sample } from '@/utils/random';
66

@@ -12,7 +12,7 @@ import type { User } from 'ps-client';
1212

1313
export { meta } from '@/ps/games/mastermind/meta';
1414

15-
export class Mastermind extends Game<State> {
15+
export class Mastermind extends BaseGame<State> {
1616
ended = false;
1717
setBy: User | null = null;
1818

src/ps/games/othello/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { EmbedBuilder } from 'discord.js';
22

33
import { WINNER_ICON } from '@/discord/constants/emotes';
4-
import { Game, createGrid } from '@/ps/games/game';
4+
import { BaseGame, createGrid } from '@/ps/games/game';
55
import { render } from '@/ps/games/othello/render';
66
import { deepClone } from '@/utils/deepClone';
77

@@ -14,7 +14,7 @@ import type { User } from 'ps-client';
1414

1515
export { meta } from '@/ps/games/othello/meta';
1616

17-
export class Othello extends Game<State> {
17+
export class Othello extends BaseGame<State> {
1818
log: Log[] = [];
1919
winCtx?: WinCtx | { type: EndType };
2020
cache: Record<string, Record<Turn, number>> = {};

src/ps/games/render.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Button } from '@/utils/components/ps';
22

33
import type { BaseState } from '@/ps/games/common';
4-
import type { Game } from '@/ps/games/game';
4+
import type { BaseGame } from '@/ps/games/game';
55
import type { CSSProperties, HTMLProps, ReactElement, ReactNode } from 'react';
66

7-
export function renderSignups<State extends BaseState>(this: Game<State>, staff: boolean): ReactElement | null {
7+
export function renderSignups<State extends BaseState>(this: BaseGame<State>, staff: boolean): ReactElement | null {
88
const startable = this.meta.autostart === false && this.startable();
99
if (staff && !startable) return null;
1010
return (
@@ -36,7 +36,7 @@ export function renderSignups<State extends BaseState>(this: Game<State>, staff:
3636
);
3737
}
3838

39-
export function renderCloseSignups<State extends BaseState>(this: Game<State>): ReactElement {
39+
export function renderCloseSignups<State extends BaseState>(this: BaseGame<State>): ReactElement {
4040
return (
4141
<>
4242
<hr />

src/ps/games/scrabble/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { EmbedBuilder } from 'discord.js';
22

3-
import { Game, createGrid } from '@/ps/games/game';
3+
import { BaseGame, createGrid } from '@/ps/games/game';
44
import { checkWord } from '@/ps/games/scrabble/checker';
55
import {
66
BaseBoard,
@@ -29,7 +29,7 @@ function isLetter(char: string): boolean {
2929
return /[A-Z]/.test(char);
3030
}
3131

32-
export class Scrabble extends Game<State> {
32+
export class Scrabble extends BaseGame<State> {
3333
points: Record<string, number> = LETTER_POINTS;
3434
log: Log[] = [];
3535
passCount: number | null = null;

0 commit comments

Comments
 (0)