Skip to content

Commit

Permalink
- add skip property and skipChildren
Browse files Browse the repository at this point in the history
- fixed json and test
- fixed texture packer still creating individual images
- ensure output is removed if the cache key changes
  • Loading branch information
GoodBoyDigital committed Apr 19, 2024
1 parent a7a646e commit 8aca520
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 15 deletions.
13 changes: 12 additions & 1 deletion packages/core/src/Asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export class Asset
// file based..
parent: Asset | null = null;
children: Asset[] = [];
ignoreChildren = false;

// transform based..
transformParent: Asset | null = null;
Expand All @@ -37,6 +36,7 @@ export class Asset

isFolder: boolean;
path = '';
skip = false;

private _state: 'deleted' | 'added' | 'modified' | 'normal' = 'added';
private _buffer?: Buffer | null = null;
Expand Down Expand Up @@ -178,6 +178,17 @@ export class Asset
return asset;
}

skipChildren()
{
for (let i = 0; i < this.children.length; i++)
{
const child = this.children[i];

child.skip = true;
child.skipChildren();
}
}

getFinalTransformedChildren(asset: Asset = this, finalChildren: Asset[] = []): Asset[]
{
if (asset.transformChildren.length > 0)
Expand Down
14 changes: 9 additions & 5 deletions packages/core/src/AssetPack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ export class AssetPack
{
Logger.info('cache found.');
}
else
{
// to be safe - lets nuke the folder as the cache is empty
fs.removeSync(this._outputPath);
}
}

// make sure the output folders exists
Expand Down Expand Up @@ -170,6 +175,8 @@ export class AssetPack
const all = assetsToTransform.map((asset) =>
(async () =>
{
if (asset.skip) return;

await this._pipeSystem.transform(asset);
index++;

Expand Down Expand Up @@ -200,12 +207,9 @@ export class AssetPack
output.push(asset);
}

if (!asset.ignoreChildren)
for (let i = 0; i < asset.children.length; i++)
{
for (let i = 0; i < asset.children.length; i++)
{
this.deleteAndCollectAssetsToTransform(asset.children[i], output);
}
this.deleteAndCollectAssetsToTransform(asset.children[i], output);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/json/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function json(_options: JsonOptions = {}): AssetPipe
const json = JSON.parse(asset.buffer.toString());
const compressedJsonAsset = createNewAssetAt(asset, asset.filename);

compressedJsonAsset.buffer = Buffer.from(JSON.stringify(json, null, 2));
compressedJsonAsset.buffer = Buffer.from(JSON.stringify(json));

return [compressedJsonAsset];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/json/test/Json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,6 @@ describe('Json', () =>

const data = readFileSync(`${outputDir}/json/json.json`, 'utf8');

expect(data.replace(/\\/g, '').trim()).toEqual(`"{"hello":"world","Im":"not broken"}"`);
expect(data.replace(/\\/g, '').trim()).toEqual(`{\"hello\":\"world\",\"Im\":\"not broken\"}`);
});
});
11 changes: 5 additions & 6 deletions packages/manifest/src/pixiManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ function collectAssets(
bundle: PixiManifest,
)
{
if (asset.skip) return;

let localBundle = bundle;

if (asset.metaData.m || asset.metaData.manifest)
Expand Down Expand Up @@ -111,13 +113,10 @@ function collectAssets(
}
}

if (!asset.ignoreChildren)
asset.children.forEach((child) =>
{
asset.children.forEach((child) =>
{
collectAssets(child, options, outputPath, entryPath, bundles, localBundle);
});
}
collectAssets(child, options, outputPath, entryPath, bundles, localBundle);
});
}

function getTexturePackedAssets(assets: Asset[])
Expand Down
3 changes: 2 additions & 1 deletion packages/texture-packer/src/texturePacker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export function texturePacker(_options: TexturePackerOptions = {}): AssetPipe<Te
// eslint-disable-next-line max-len
fixedResolutions[resolutionOptions.fixedResolution as any] = resolutionOptions.resolutions[resolutionOptions.fixedResolution];

asset.ignoreChildren = true;
// skip the children so that they do not get processed!
asset.skipChildren();

const largestResolution = Math.max(...Object.values(resolutionOptions.resolutions));
const resolutionHash = asset.allMetaData[tags.fix as any] ? fixedResolutions : resolutionOptions.resolutions;
Expand Down

0 comments on commit 8aca520

Please sign in to comment.