diff --git a/packages/manifest/src/pixiManifest.ts b/packages/manifest/src/pixiManifest.ts index a3b0223..8b84a5d 100644 --- a/packages/manifest/src/pixiManifest.ts +++ b/packages/manifest/src/pixiManifest.ts @@ -7,12 +7,17 @@ import { stripTags } from '@play-co/assetpack-core'; -export interface PixiManifest +export interface PixiBundle { name: string; assets: PixiManifestEntry[]; } +export interface PixiManifest +{ + bundles: PixiBundle[]; +} + export interface PixiManifestEntry { alias: string | string[]; @@ -79,29 +84,51 @@ export function pixiManifest(_options: PixiManifestOptions = {}): AssetPipe(); + + manifest.bundles.forEach((bundle) => + bundle.assets.forEach((asset) => nameMap.set(asset, asset.alias as string[]))); + + const arrays = Array.from(nameMap.values()); + const sets = arrays.map((arr) => new Set(arr)); + const uniqueArrays = arrays.map((arr, i) => arr.filter((x) => sets.every((set, j) => j === i || !set.has(x)))); + + manifest.bundles.forEach((bundle) => + { + bundle.assets.forEach((asset) => + { + const names = nameMap.get(asset) as string[]; + + asset.alias = uniqueArrays.find((arr) => arr.every((x) => names.includes(x))) as string[]; + }); + }); +} + function collectAssets( asset: Asset, options: PixiManifestOptions, outputPath = '', entryPath = '', - bundles: PixiManifest[], - bundle: PixiManifest, + bundles: PixiBundle[], + bundle: PixiBundle, ) { if (asset.skip) return; diff --git a/packages/manifest/test/Manifest.test.ts b/packages/manifest/test/Manifest.test.ts index be1254c..c19b962 100644 --- a/packages/manifest/test/Manifest.test.ts +++ b/packages/manifest/test/Manifest.test.ts @@ -357,9 +357,7 @@ describe('Manifest', () => { alias: [ 'folder/json.json', - 'folder/json', 'json.json', - 'json' ], src: [ 'folder/json.json' @@ -368,9 +366,7 @@ describe('Manifest', () => { alias: [ 'folder/json.json5', - 'folder/json', 'json.json5', - 'json' ], src: [ 'folder/json.json5' @@ -394,8 +390,6 @@ describe('Manifest', () => alias: [ 'folder2/1.mp3', 'folder2/1', - '1.mp3', - '1' ], src: [ 'folder2/1.ogg', @@ -406,8 +400,6 @@ describe('Manifest', () => alias: [ 'folder2/folder3/1.mp3', 'folder2/folder3/1', - '1.mp3', - '1' ], src: [ 'folder2/folder3/1.ogg', @@ -417,9 +409,7 @@ describe('Manifest', () => { alias: [ 'spine/dragon.json', - 'spine/dragon', 'dragon.json', - 'dragon' ], src: [ 'spine/dragon.json' @@ -428,9 +418,7 @@ describe('Manifest', () => { alias: [ 'spine/dragon.atlas', - 'spine/dragon', 'dragon.atlas', - 'dragon' ], src: [ 'spine/dragon@0.5x.atlas',