import {Letter as LetterData, Letter} from "../../pkg/word_grid"; import * as React from "react"; export enum CellType { Normal = "Normal", DoubleWord = "DoubleWord", DoubleLetter = "DoubleLetter", TripleLetter = "TripleLetter", TripleWord = "TripleWord", Start = "Start", } export interface Settings { trayLength: number; playerName: string; aiName: string; } export enum LocationType { GRID, TRAY } export interface CoordinateData { location: LocationType; index: number; } export type PlayableLetterData = LetterData & CoordinateData; export type HighlightableLetterData = LetterData & {highlight: boolean}; export enum TileDispatchActionType { MOVE, RETRIEVE, SET_BLANK, RETURN, MOVE_TO_ARROW, } export type TileDispatchAction = {action: TileDispatchActionType, start?: CoordinateData, end?: CoordinateData, newBlankValue?: string, blankIndex?: number, override?: boolean}; export type TileDispatch = React.Dispatch; export enum Direction { RIGHT = "right", DOWN = "down", } export interface GridArrowData { direction: Direction, position: number, } export enum GridArrowDispatchActionType { CLEAR, CYCLE, SHIFT, } // I need to include the playerLetters as an argument because I can't define gridArrow after defining the playerLetters in export type GridArrowDispatchAction = { action: GridArrowDispatchActionType, position?: number, playerLetters?: PlayableLetterData[] // only needs to be defined on action type SHIFT }; export type GridArrowDispatch = React.Dispatch; export function matchCoordinate(playerLetters: PlayableLetterData[], coords: CoordinateData): number { for (let i=0; i(array: T[], toAdd: T, times: number) { for (let i=0; i(); for (let i = 0; i { return x !== undefined && x !== null; }).forEach((x) => { if (x.location === LocationType.TRAY) { freeSpots[x.index] = null; } }); const firstNotNull = (): number => { for (let i of freeSpots) { if (i !== null) { freeSpots[i] = null; return i; } } return null; } return newer.map((ld, i) => { if (ld !== undefined) { if (existing[i] !== undefined && existing[i] !== null && existing[i].location === LocationType.TRAY) { ld["index"] = existing[i].index; } else { ld["index"] = firstNotNull(); } ld["location"] = LocationType.TRAY; } return ld as PlayableLetterData; }); } export const GRID_LENGTH = 15;