forked from pixijs/assetpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(manifest): update manifest plugin to remove specific logic (#16)
* - add spine cache buster - add sprite sheet cache buster - tests * cache id is now takes into account all pipe options add test * docs * Update packages/spine/test/spineAtlasAll.test.ts * remove only * fix test and merge bits * rename * - update manifest plugin to remove specific logic - add a manifest modifier for texture packer - add a manifest modifier for spine atlas * fix options * fix options * fin name * fix tests --------- Co-authored-by: Zyie <[email protected]>
- Loading branch information
1 parent
eece9ff
commit ef71c06
Showing
16 changed files
with
9,119 additions
and
4,307 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,5 +128,10 @@ export class PipeSystem | |
} | ||
} | ||
} | ||
|
||
getPipe(name: string): AssetPipe | ||
{ | ||
return this.pipeHash[name]; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './spineAtlasMipmap'; | ||
export * from './spineAtlasCompress'; | ||
export * from './spineAtlasCacheBuster'; | ||
export * from './spineAtlasManifestMod'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import type { Asset } from '@play-co/assetpack-core'; | ||
import { type AssetPipe, path, findAssets } from '@play-co/assetpack-core'; | ||
import { AtlasView } from './AtlasView'; | ||
import { readJsonSync, writeJSONSync } from 'fs-extra'; | ||
|
||
export interface SpineManifestOptions | ||
{ | ||
output?: string; | ||
} | ||
|
||
/** | ||
* This pipe will modify the manifest generated by 'pixiManifest'. It will look for any images found in the atlas | ||
* files and remove them from the manifest. As the atlas files will be responsible for loading the textures. | ||
* | ||
* Once done, it rewrites the manifest. | ||
* | ||
* This should be added after the `pixiManifest` pipe. | ||
* | ||
* ensure that the same output path is passed to the pipe as the `pixiManifest` pipe. Otherwise | ||
* the manifest will not be found. | ||
* | ||
* As this pipe needs to know about all the textures in the texture files most of the work is done | ||
* in the finish method. | ||
* | ||
* Kind of like applying a patch at the end of the manifest process. | ||
* | ||
* @param _options | ||
* @returns | ||
*/ | ||
export function spineAtlasManifestMod(_options: SpineManifestOptions = {}): AssetPipe<SpineManifestOptions> | ||
{ | ||
const defaultOptions = { | ||
output: 'manifest.json', | ||
..._options | ||
}; | ||
|
||
return { | ||
folder: false, | ||
name: 'spine-atlas-manifest', | ||
defaultOptions, | ||
|
||
async finish(asset: Asset, options, pipeSystem) | ||
{ | ||
const atlasAssets = findAssets((asset) => | ||
asset.extension === '.atlas' && asset.transformChildren.length === 0, asset, true); | ||
|
||
const manifestLocation = options.output; | ||
|
||
const newFileName = path.dirname(manifestLocation) === '.' | ||
? path.joinSafe(pipeSystem.outputPath, manifestLocation) : manifestLocation; | ||
|
||
const manifest = readJsonSync(newFileName); | ||
|
||
atlasAssets.forEach((atlasAsset) => | ||
{ | ||
const atlasView = new AtlasView(atlasAsset.buffer); | ||
|
||
atlasView.getTextures().forEach((texture) => | ||
{ | ||
// relative path to the output folder | ||
const texturePath = path.relative(pipeSystem.outputPath, path.joinSafe(atlasAsset.directory, texture)); | ||
|
||
findAndRemoveManifestAsset(manifest, texturePath); | ||
}); | ||
}); | ||
|
||
writeJSONSync(newFileName, manifest, { spaces: 2 }); | ||
} | ||
}; | ||
} | ||
|
||
function findAndRemoveManifestAsset(manifest: any, assetPath: string) | ||
{ | ||
for (let i = 0; i < manifest.bundles.length; i++) | ||
{ | ||
const assets = manifest.bundles[i].assets; | ||
|
||
const manifestAsset = assets.find((asset: {src: string[]}) => | ||
|
||
asset.src.includes(assetPath) | ||
); | ||
|
||
if (manifestAsset) | ||
{ | ||
assets.splice(assets.indexOf(manifestAsset), 1); | ||
break; | ||
} | ||
} | ||
} |
Oops, something went wrong.