#!/usr/bin/env node import {writeFileSync} from 'node:fs'; import {basename, dirname, extname, join} from 'node:path'; import imageSize from 'image-size'; const tileset = process.argv[2]; const w = parseInt(process.argv[3]); const h = parseInt(process.argv[4]); const {width, height} = imageSize(tileset); const json = { frames: {}, meta: { format: 'RGBA8888', image: tileset, scale: 1, size: {w: width, h: height}, }, }; let i = 0; for (let y = 0; y < height; y += h) { for (let x = 0; x < width; x += w) { json.frames[i++] = { frame: {x, y, w, h}, spriteSourceSize: {x: 0, y: 0, w, h}, sourceSize: {w, h}, }; } } writeFileSync( `${join(dirname(tileset), basename(tileset, extname(tileset)))}.json`, JSON.stringify(json), );