From c8266faf68bb0cf068074078143250da9975cb3d Mon Sep 17 00:00:00 2001 From: h1ve2 Date: Mon, 6 Jan 2025 23:12:34 +0800 Subject: [PATCH] Fix: Errors resulting from identical TPS file names in different directories --- .../texture-packer/texturePackerCacheBuster.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/assetpack/src/texture-packer/texturePackerCacheBuster.ts b/packages/assetpack/src/texture-packer/texturePackerCacheBuster.ts index 64dcddb..abf0949 100644 --- a/packages/assetpack/src/texture-packer/texturePackerCacheBuster.ts +++ b/packages/assetpack/src/texture-packer/texturePackerCacheBuster.ts @@ -39,7 +39,7 @@ export function texturePackerCacheBuster(): AssetPipe return [asset]; }, - async finish(asset: Asset) + async finish(asset: Asset, options, pipeSystem) { // first we retrieve the final transformed children - so the atlas files that have been copied // to the output folder. @@ -59,8 +59,17 @@ export function texturePackerCacheBuster(): AssetPipe const texture = json.meta.image; - const textureAssets = findAssets((asset) => - asset.filename === texture, asset, true); + const textureAssets = findAssets((assetObj) =>{ + if(assetObj.filename !== texture)return false; + + // check json & image file directory + let jsonDir = jsonAsset.directory.replaceAll(pipeSystem.outputPath, ""); + jsonDir = jsonDir.replaceAll(/(^[\\\/])|([\\\/]$)/ig, "") + + let dirName = assetObj.directory.replaceAll(/\.?assetpack[\/\\]texture-packer\//ig, ""); + dirName = dirName.replaceAll(/{.*}/ig, ""); + return jsonDir == dirName + }, asset, true); // last transformed child is the renamed texture const cacheBustedTexture = textureAssets[0].getFinalTransformedChildren()[0];