Skip to content

Commit

Permalink
Merge branch 'main' into chore/clean
Browse files Browse the repository at this point in the history
  • Loading branch information
Zyie committed Apr 22, 2024
2 parents e8c3076 + 973ef7d commit f20f95b
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 20 deletions.
4 changes: 2 additions & 2 deletions packages/compress/src/utils/compressSharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export async function compressSharp(
{
// optimising the PNG image and using that as the source of the WebP and AVIF images
// will result in a smaller file size and increase the speed of the compression.
sharpImage = sharp(await image.sharpImage.png(options.png as PngOptions).toBuffer());
sharpImage = sharp(await image.sharpImage.png({ ...options.png as PngOptions, force: true }).toBuffer());

compressed.push({
format: '.png',
resolution: image.resolution,
sharpImage
sharpImage: sharpImage.clone(),
});
}

Expand Down
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
16 changes: 11 additions & 5 deletions packages/core/src/AssetPack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ export class AssetPack
{
Logger.info('cache found.');
}
else
{
Logger.warn('cache not found, clearing output folder');

// 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 @@ -164,6 +171,8 @@ export class AssetPack
const all = assetsToTransform.map((asset) =>
(async () =>
{
if (asset.skip) return;

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

Expand Down Expand Up @@ -194,12 +203,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
2 changes: 1 addition & 1 deletion packages/texture-packer/src/packer/createJsons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function createJsons(
w: rect.width,
h: rect.height
},
rotated: false,
rotated: rect.rot,
trimmed: rect.textureData.trimmed,
spriteSourceSize: {
x: rect.textureData.trimOffsetLeft,
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
6 changes: 4 additions & 2 deletions packages/texture-packer/test/texturePacker.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AssetPack } from '@play-co/assetpack-core';
import { AssetPack, Logger } from '@play-co/assetpack-core';
import { existsSync, readJSONSync } from 'fs-extra';
import sharp from 'sharp';
import type { File } from '../../../shared/test/index';
Expand Down Expand Up @@ -70,6 +70,8 @@ describe('Texture Packer', () =>
const sheet2Exists = existsSync(`${outputDir}/sprites-1.json`);

expect(sheet2Exists).toBe(false);

expect(existsSync(`${outputDir}/sprites`)).toBe(false);
});

it('should adjust the size of the textures outputted based on maximumTextureSize', async () =>
Expand Down Expand Up @@ -567,7 +569,7 @@ describe('Texture Packer', () =>
});

// Mock console.warn
const mockWarn = jest.spyOn(console, 'warn').mockImplementation();
const mockWarn = jest.spyOn(Logger, 'warn').mockImplementation();

await assetpack.run();

Expand Down

0 comments on commit f20f95b

Please sign in to comment.