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.
- update manifest plugin to remove specific logic
- add a manifest modifier for texture packer - add a manifest modifier for spine atlas
- Loading branch information
1 parent
cd905ad
commit 4a51137
Showing
16 changed files
with
576 additions
and
92 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.