Skip to content

Commit

Permalink
feat: add frame names to spritesheet manifest data
Browse files Browse the repository at this point in the history
  • Loading branch information
Zyie committed Aug 30, 2024
1 parent 90ffd66 commit 089c388
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/assetpack/src/texture-packer/texturePacker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export interface TexturePackerOptions extends PluginOptions
/** The maximum size a sprite sheet can be before its split out */
maximumTextureSize?: number;
}
/** If true, the frame names for the sprite sheet will be added to the asset meta data. */
addFrameNames?: boolean;
}

function checkForTexturePackerShortcutClashes(
Expand Down Expand Up @@ -67,6 +69,7 @@ export function texturePacker(_options: TexturePackerOptions = {}): AssetPipe<Te
nameStyle: 'relative',
..._options.texturePacker,
},
addFrameNames: false,
},
tags: {
tps: 'tps',
Expand Down Expand Up @@ -130,6 +133,7 @@ export function texturePacker(_options: TexturePackerOptions = {}): AssetPipe<Te
const assets: Asset[] = [];

let checkedForClashes = false;
const imageNames: string[] = [];

Object.values(resolutionHash).sort((a, b) => b - a).forEach((resolution) =>
{
Expand Down Expand Up @@ -160,6 +164,8 @@ export function texturePacker(_options: TexturePackerOptions = {}): AssetPipe<Te

const { json, name: jsonName } = out.jsons[i];

imageNames.push(...Object.keys(json.frames));

const jsonAsset = createNewAssetAt(asset, jsonName);

if (!checkedForClashes)
Expand All @@ -184,6 +190,11 @@ export function texturePacker(_options: TexturePackerOptions = {}): AssetPipe<Te

await Promise.all(promises);

if (options.addFrameNames)
{
asset.metaData.frameNames = imageNames;
}

return assets;
},

Expand Down
2 changes: 2 additions & 0 deletions packages/docs/docs/guide/pipes/texture-packer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export default {
| resolutionOptions.resolutions | `object` | An object containing the resolutions that the images will be resized to.<br />Defaults to `{ default: 1, low: 0.5 }`. |
| resolutionOptions.fixedResolution | `string` | A resolution used if the fix tag is applied. Resolution must match one found in resolutions.<br />Defaults to `default`. |
| resolutionOptions.maximumTextureSize | `number` | The maximum size a sprite sheet can be before its split out.<br />Defaults to `4096`. |
| | | |
| addFrameNames | `boolean` | Whether to add frame names to the data in the manifest<br />Defaults to `false`. |

## Tags

Expand Down

0 comments on commit 089c388

Please sign in to comment.