45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import parts from './parts.csv';
|
|
import {createRegion, moveToRegion, Region} from "@/core/region";
|
|
import {createPartsFromTable} from "@/core/part-factory";
|
|
import {BoopPart} from "@/samples/boop/types";
|
|
import {BOARD_SIZE} from "@/samples/boop/constants";
|
|
import {PlayerType, PieceType, RegionType} from "@/samples/boop/types";
|
|
|
|
export function createInitialState() {
|
|
const pieces = createPartsFromTable(
|
|
parts,
|
|
(item, index) => `${item.player}-${item.type}-${index + 1}`,
|
|
(item) => item.count
|
|
) as Record<string, BoopPart>;
|
|
|
|
// Initialize region childIds
|
|
const whiteRegion = createRegion('white', []);
|
|
const blackRegion = createRegion('black', []);
|
|
const boardRegion = createRegion('board', [
|
|
{ name: 'x', min: 0, max: BOARD_SIZE - 1 },
|
|
{ name: 'y', min: 0, max: BOARD_SIZE - 1 },
|
|
]);
|
|
|
|
// Populate region childIds based on piece regionId
|
|
for (const part of Object.values(pieces)) {
|
|
if(part.type !== 'kitten') continue;
|
|
if (part.player === 'white' ) {
|
|
moveToRegion(part, null, whiteRegion);
|
|
} else if (part.player === 'black') {
|
|
moveToRegion(part, null, blackRegion);
|
|
}
|
|
}
|
|
|
|
return {
|
|
regions: {
|
|
white: whiteRegion,
|
|
black: blackRegion,
|
|
board: boardRegion,
|
|
} as Record<RegionType, Region>,
|
|
pieces,
|
|
currentPlayer: 'white' as PlayerType,
|
|
winner: null as PlayerType | 'draw' | null,
|
|
};
|
|
}
|
|
export type BoopState = ReturnType<typeof createInitialState>;
|