From 4106c79c9181242e38c6ff4a868084c1c9960753 Mon Sep 17 00:00:00 2001 From: mrvauxs Date: Wed, 29 Jan 2025 16:43:51 +0100 Subject: [PATCH] lint --- CHANGELOG.md | 4 + scripts/generateSpritesheetJSON.ts | 140 ++++++++++++++--------------- 2 files changed, 74 insertions(+), 70 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05517976..4603cbaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning]( '); - process.exit(1); + console.error('Usage: generateSpritesheetJSON.ts '); + process.exit(1); } const [name, imageWidth, imageHeight, gridWidth, gridHeight, frameCount] = args; @@ -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}`);