Skip to content

Commit

Permalink
fix mipmapping and json
Browse files Browse the repository at this point in the history
  • Loading branch information
Zyie committed Apr 19, 2024
1 parent c948d74 commit bb15444
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
5 changes: 1 addition & 4 deletions packages/json/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ export function json(_options: JsonOptions = {}): AssetPipe
{
try
{
let json = JSON.parse(asset.buffer.toString());

json = JSON.stringify(json);

const json = JSON.parse(asset.buffer.toString());
const compressedJsonAsset = createNewAssetAt(asset, asset.filename);

compressedJsonAsset.buffer = Buffer.from(JSON.stringify(json, null, 2));
Expand Down
23 changes: 9 additions & 14 deletions packages/mipmap-compress/src/mipmapCompress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,13 @@ export interface MipmapCompressImageData

const defaultMipmapOptions: Required<MipmapOptions> = {
template: '@%%x',
resolutions: { default: 1 },
resolutions: { default: 1, low: 0.5 },
fixedResolution: 'default'
};

export function mipmapCompress(_options: MipmapCompressOptions = {}): AssetPipe<MipmapCompressOptions>
{
const mipmap = resolveOptions(_options.mipmap, {
template: '@%%x',
resolutions: { default: 1, low: 0.5 },
fixedResolution: 'default'
});
const mipmap = resolveOptions(_options.mipmap, defaultMipmapOptions);

const compress = resolveOptions<CompressOptions>(_options.compress, {
png: true,
Expand Down Expand Up @@ -91,17 +87,16 @@ export function mipmapCompress(_options: MipmapCompressOptions = {}): AssetPipe<

return {
folder: true,
name: 'mipmap-compress',
name: 'mip-compress',
defaultOptions,
test(asset: Asset, options)
{
return (options.mipmap || options.compress) && checkExt(asset.path, '.png', '.jpg', '.jpeg');
},
async transform(asset: Asset, options)
{
const mip = options.mipmap && !asset.metaData[options.tags.fix as any];

const compress = options.compress && !asset.metaData[options.tags.nc as any];
const shouldMipmap = mipmap && !asset.metaData[options.tags.fix as any];
const shouldCompress = compress && !asset.metaData[options.tags.nc as any];

let processedImages: MipmapCompressImageData[];

Expand All @@ -114,10 +109,10 @@ export function mipmapCompress(_options: MipmapCompressOptions = {}): AssetPipe<
// first mipmap if we want..
try
{
if (mip)
if (shouldMipmap)
{
const { resolutions, fixedResolution } = options.mipmap as Required<MipmapOptions>
|| defaultMipmapOptions;
|| defaultOptions.mipmap;

const fixedResolutions: {[x: string]: number} = {};

Expand All @@ -131,7 +126,7 @@ export function mipmapCompress(_options: MipmapCompressOptions = {}): AssetPipe<

image.resolution = largestResolution;

processedImages = mip ? await mipmapSharp(image, resolutionHash, largestResolution) : [image];
processedImages = shouldMipmap ? await mipmapSharp(image, resolutionHash, largestResolution) : [image];
}
else
{
Expand All @@ -145,7 +140,7 @@ export function mipmapCompress(_options: MipmapCompressOptions = {}): AssetPipe<

try
{
if (compress)
if (shouldCompress)
{
processedImages = (await Promise.all(
processedImages.map((image) => compressSharp(image, options.compress as CompressOptions))
Expand Down

0 comments on commit bb15444

Please sign in to comment.