Skip to content

Commit

Permalink
Fix: Errors resulting from identical TPS file names in different dire…
Browse files Browse the repository at this point in the history
…ctories
  • Loading branch information
h1ve2 committed Jan 6, 2025
1 parent d8cf767 commit c8266fa
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/assetpack/src/texture-packer/texturePackerCacheBuster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function texturePackerCacheBuster(): AssetPipe<any, 'tps'>
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.
Expand All @@ -59,8 +59,17 @@ export function texturePackerCacheBuster(): AssetPipe<any, 'tps'>

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];
Expand Down

0 comments on commit c8266fa

Please sign in to comment.