Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
MrVauxs committed Jan 29, 2025
1 parent 718a634 commit 4106c79
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 70 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](<https://semver.org/spec/v2.0.

## [Unreleased]

### Fixed

- `offset` and `anchor` not being properly set as numbers.

## [1.0.0-alpha.3] - 2025-01-29

### Fixed
Expand Down
140 changes: 70 additions & 70 deletions scripts/generateSpritesheetJSON.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
#!/usr/bin/env node
import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'node:fs';
import * as path from 'node:path';

interface Frame {
frame: {
x: number;
y: number;
w: number;
h: number;
};
rotated: boolean;
trimmed: boolean;
spriteSourceSize: {
x: number;
y: number;
w: number;
h: number;
};
sourceSize: {
w: number;
h: number;
};
frame: {
x: number;
y: number;
w: number;
h: number;
};
rotated: boolean;
trimmed: boolean;
spriteSourceSize: {
x: number;
y: number;
w: number;
h: number;
};
sourceSize: {
w: number;
h: number;
};
}

interface SpritesheetJSON {
frames: { [key: string]: Frame };
animations: { [key: string]: string[] };
meta: {
frameRate: number;
image: string;
format: string;
size: { w: number; h: number };
scale: string;
};
frames: { [key: string]: Frame };
animations: { [key: string]: string[] };
meta: {
frameRate: number;
image: string;
format: string;
size: { w: number; h: number };
scale: string;
};
}

const args = process.argv.slice(2);
if (args.length !== 6) {
console.error('Usage: generateSpritesheetJSON.ts <name> <imageWidth> <imageHeight> <gridWidth> <gridHeight> <frameCount>');
process.exit(1);
console.error('Usage: generateSpritesheetJSON.ts <name> <imageWidth> <imageHeight> <gridWidth> <gridHeight> <frameCount>');
process.exit(1);
}

const [name, imageWidth, imageHeight, gridWidth, gridHeight, frameCount] = args;
Expand All @@ -51,56 +51,56 @@ const frameNames: string[] = [];
const framesPerRow = Math.floor(Number(imageWidth) / Number(gridWidth));

for (let i = 0; i < Number(frameCount); i++) {
const frameName = `${name}-${i}`;
frameNames.push(frameName);
const frameName = `${name}-${i}`;
frameNames.push(frameName);

// Calculate position in spritesheet
const row = Math.floor(i / framesPerRow);
const col = i % framesPerRow;
// Calculate position in spritesheet
const row = Math.floor(i / framesPerRow);
const col = i % framesPerRow;

frames[frameName] = {
frame: {
x: col * Number(gridWidth),
y: row * Number(gridHeight),
w: Number(gridWidth),
h: Number(gridHeight)
},
rotated: false,
trimmed: false,
spriteSourceSize: {
x: 0,
y: 0,
w: Number(gridWidth),
h: Number(gridHeight)
},
sourceSize: {
w: Number(gridWidth),
h: Number(gridHeight)
}
};
frames[frameName] = {
frame: {
x: col * Number(gridWidth),
y: row * Number(gridHeight),
w: Number(gridWidth),
h: Number(gridHeight),
},
rotated: false,
trimmed: false,
spriteSourceSize: {
x: 0,
y: 0,
w: Number(gridWidth),
h: Number(gridHeight),
},
sourceSize: {
w: Number(gridWidth),
h: Number(gridHeight),
},
};
}

animations[name] = frameNames;

const spritesheet: SpritesheetJSON = {
meta: {
frameRate: 60,
image: `${name}.webp`,
format: "RGBA8888",
size: {
w: Number(imageWidth),
h: Number(imageHeight)
},
scale: "1"
},
frames,
animations
meta: {
frameRate: 60,
image: `${name}.webp`,
format: 'RGBA8888',
size: {
w: Number(imageWidth),
h: Number(imageHeight),
},
scale: '1',
},
frames,
animations,
};

// Write to file
fs.writeFileSync(
path.join(process.cwd(), `${name}.json`),
JSON.stringify(spritesheet, null, '\t')
path.join(process.cwd(), `${name}.json`),
JSON.stringify(spritesheet, null, '\t'),
);

console.log(`Generated spritesheet JSON for ${name}`);

0 comments on commit 4106c79

Please sign in to comment.