Skip to content

Commit de61bae

Browse files
committed
games: Move createGrid to utils
1 parent 5fee72b commit de61bae

6 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/ps/games/connectfour/index.ts

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

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

89
import type { TranslatedText } from '@/i18n/types';

src/ps/games/game.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,5 @@ export type BaseContext = {
484484
args: string[];
485485
};
486486

487-
export function createGrid<T>(x: number, y: number, fill: (x: number, y: number) => T) {
488-
return Array.from({ length: x }).map((_, i) => Array.from({ length: y }).map((_, j) => fill(i, j)));
489-
}
490-
491487
/** Non-generic type representing only the things all games have in common */
492488
export type CommonGame = BaseGame<BaseState>;

src/ps/games/lightsout/index.ts

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

3-
import { BaseGame, createGrid } from '@/ps/games/game';
3+
import { BaseGame } from '@/ps/games/game';
44
import { render, renderCloseSignups } from '@/ps/games/lightsout/render';
5+
import { createGrid } from '@/ps/games/utils';
56
import { deepClone } from '@/utils/deepClone';
67
import { type Point, parsePoint, stepPoint } from '@/utils/grid';
78

src/ps/games/othello/index.ts

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

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

89
import type { TranslatedText } from '@/i18n/types';

src/ps/games/scrabble/index.ts

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

3-
import { BaseGame, createGrid } from '@/ps/games/game';
3+
import { BaseGame } from '@/ps/games/game';
44
import { checkWord } from '@/ps/games/scrabble/checker';
55
import {
66
BaseBoard,
@@ -13,6 +13,7 @@ import {
1313
} from '@/ps/games/scrabble/constants';
1414
import { ScrabbleModData } from '@/ps/games/scrabble/mods';
1515
import { render, renderMove } from '@/ps/games/scrabble/render';
16+
import { createGrid } from '@/ps/games/utils';
1617
import { type Point, coincident, flipPoint, multiStepPoint, rangePoints, stepPoint } from '@/utils/grid';
1718

1819
import type { TranslatedText } from '@/i18n/types';

src/ps/games/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ export function generateId(): string {
1212
const idNum = (newId * 999979) % 36 ** 4;
1313
return `#${idNum.toString(36).padStart(4, '0').toUpperCase()}`;
1414
}
15+
16+
export function createGrid<T>(x: number, y: number, fill: (x: number, y: number) => T) {
17+
return Array.from({ length: x }).map((_, i) => Array.from({ length: y }).map((_, j) => fill(i, j)));
18+
}

0 commit comments

Comments
 (0)