Skip to content

Commit

Permalink
cache bust at start of file (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodBoyDigital authored Apr 30, 2024
1 parent b9ca16d commit 4924576
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/texture-packer/src/packer/createTextureData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export async function createTextureData(options: Required<PackTexturesOptions>)
const newWidth = Math.ceil(metaData.width * scale);
const newHeight = Math.ceil(metaData.height * scale);

const allowTrim = options.allowTrim && newWidth >= 3 && newHeight >= 3;

if (scale < 1)
{
sharpImage = sharpImage
Expand All @@ -37,13 +39,13 @@ export async function createTextureData(options: Required<PackTexturesOptions>)
height: newHeight,
});

if (options.allowTrim)
if (allowTrim)
{
sharpImage = sharp(await sharpImage.toBuffer());
}
}

if (options.allowTrim)
if (allowTrim)
{
sharpImage = sharpImage
.trim({
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions packages/texture-packer/test/texturePacker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,4 +582,77 @@ describe('Texture Packer', () =>
// Restore console.warn
mockWarn.mockRestore();
});

it.only('should handle smaller than 3x3 textures if trimming is enabled', async () =>
{
const testName = 'tp-small-trim';
const inputDir = getInputDir(pkg, testName);
const outputDir = getOutputDir(pkg, testName);

const sprites: File[] = [];

sprites.push({
name: `sprite.png`,
content: assetPath(pkg, `sp-1.png`),
});

sprites.push({
name: `empty2x2.png`,
content: assetPath(pkg, `2x2-small-empty-texture.png`),
});

createFolder(
pkg,
{
name: testName,
files: [],
folders: [
{
name: 'sprites{tps}',
files: sprites,
folders: [],
},
],
});

const assetpack = new AssetPack({
entry: inputDir,
output: outputDir,
cache: false,
pipes: [
texturePacker({
resolutionOptions: { resolutions: { default: 1 } },
}),
]
});

// Mock console.warn

await assetpack.run();

const sheet1 = readJSONSync(`${outputDir}/sprites.json`);

expect(sheet1.frames['empty2x2.png']).toEqual({
frame: {
x: 2,
y: 2,
w: 2,
h: 2
},
rotated: false,
trimmed: false,
spriteSourceSize: {
x: 0,
y: 0,
w: 2,
h: 2
},
sourceSize: {
w: 2,
h: 2
}
},
);
});
});

0 comments on commit 4924576

Please sign in to comment.