Skip to content

Commit

Permalink
fix: change asset accordingly to fixed and largest esolutions, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
f0nar committed Oct 15, 2024
1 parent c45d3d4 commit 47fb25c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
26 changes: 15 additions & 11 deletions packages/assetpack/src/image/mipmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,34 @@ export function mipmap(_options: MipmapOptions = {}): AssetPipe<MipmapOptions, '
sharpImage: sharp(asset.buffer),
};

const { resolutions, fixedResolution } = options as Required<MipmapOptions>
|| this.defaultOptions;

const fixedResolutions = {
[fixedResolution]: resolutions[fixedResolution]
};

const largestResolution = Math.max(...Object.values(resolutions));

try
{
if (shouldMipmap)
{
const { resolutions, fixedResolution } = options as Required<MipmapOptions>
|| this.defaultOptions;

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

fixedResolutions[fixedResolution] = resolutions[fixedResolution];

const resolutionHash = asset.allMetaData[this.tags!.fix]
? fixedResolutions
: resolutions;

const largestResolution = Math.max(...Object.values(resolutions));

image.resolution = largestResolution;

processedImages = shouldMipmap ? await mipmapSharp(image, resolutionHash, largestResolution) : [image];
processedImages = await mipmapSharp(image, resolutionHash, largestResolution);
}
else
{
processedImages = [image];
image.resolution = fixedResolutions[fixedResolution];

processedImages = image.resolution === 1
? [image]
: processedImages = await mipmapSharp(image, fixedResolutions, largestResolution);
}
}
catch (error)
Expand Down
6 changes: 3 additions & 3 deletions packages/assetpack/test/image/Mipmap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ describe('Mipmap', () =>
name: testName,
files: [
{
name: 'testPng.png',
name: 'testPng{fix}.png',
content: assetPath('image/png-1.png'),
},
],
folders: [],
});

const mipmapOpts = {
resolutions: { low: 0.5 },
resolutions: { low: 0.5, default: 1 },
fixedResolution: 'low'
};

Expand Down Expand Up @@ -147,7 +147,7 @@ describe('Mipmap', () =>

it('should prevent mipmaps on file when tagged with fix', async () =>
{
const testName = 'mip-fixed';
const testName = 'mip-fixed-prevent';
const inputDir = getInputDir(pkg, testName);
const outputDir = getOutputDir(pkg, testName);

Expand Down

0 comments on commit 47fb25c

Please sign in to comment.