refactor: add export for createPart

This commit is contained in:
hyper 2026-04-10 12:34:47 +08:00
parent 3d5a484e52
commit 9d6e7a75f8
1 changed files with 10 additions and 6 deletions

View File

@ -7,12 +7,7 @@ export function createPartsFromTable<T>(items: readonly T[], getId: (item: T, in
const count = getCount ? (typeof getCount === 'function' ? getCount(entry) : getCount) : 1; const count = getCount ? (typeof getCount === 'function' ? getCount(entry) : getCount) : 1;
for (let i = 0; i < count; i++) { for (let i = 0; i < count; i++) {
const id = getId(entry, i); const id = getId(entry, i);
pool[id] = { pool[id] = createPart(id, entry);
id,
regionId: '',
position: [],
...entry as Immutable<T>
};
} }
} }
return pool; return pool;
@ -20,4 +15,13 @@ export function createPartsFromTable<T>(items: readonly T[], getId: (item: T, in
export function createParts<T>(item: T, getId: (index: number) => string, count?: number){ export function createParts<T>(item: T, getId: (index: number) => string, count?: number){
return createPartsFromTable([item], (_,index) => getId(index), count); return createPartsFromTable([item], (_,index) => getId(index), count);
}
export function createPart<T>(id: string, entry: T): Part<T> {
return {
id,
regionId: '',
position: [],
...entry as Immutable<T>
}
} }