fix: fix tic tac toe tests
This commit is contained in:
@@ -111,3 +111,19 @@ function createEmptyPartPool<TMeta>(): PartPool<TMeta> {
|
||||
},
|
||||
};
|
||||
}
|
||||
export function createPartsFromTable<T>(items: T[], getId: (item: T, index: number) => string, getCount?: ((item: T) => number) | number){
|
||||
const pool: Record<string, Part<T>> = {};
|
||||
for (const entry of items) {
|
||||
const count = getCount ? (typeof getCount === 'function' ? getCount(entry) : getCount) : 1;
|
||||
for (let i = 0; i < count; i++) {
|
||||
const id = getId(entry, i);
|
||||
pool[id] = {
|
||||
id,
|
||||
regionId: '',
|
||||
position: [],
|
||||
...entry
|
||||
};
|
||||
}
|
||||
}
|
||||
return pool;
|
||||
}
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ export type { Part } from './core/part';
|
||||
export { flip, flipTo, roll, findPartById, isCellOccupied, getPartAtPosition, isCellOccupiedByRegion, getPartAtPositionInRegion } from './core/part';
|
||||
|
||||
export type { PartTemplate, PartPool } from './core/part-factory';
|
||||
export { createPart, createParts, createPartPool, mergePartPools } from './core/part-factory';
|
||||
export { createPart, createParts, createPartPool, mergePartPools, createPartsFromTable } from './core/part-factory';
|
||||
|
||||
export type { Region, RegionAxis } from './core/region';
|
||||
export { createRegion, applyAlign, shuffle, moveToRegion } from './core/region';
|
||||
|
||||
Reference in New Issue
Block a user