silphius/public/assets/tileset.js

41 lines
847 B
JavaScript
Raw Normal View History

2024-06-11 18:42:48 -05:00
#!/usr/bin/env node
2024-06-11 15:06:43 -05:00
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},
},
};
2024-06-12 14:31:12 -05:00
const extlessPath = join(dirname(tileset), basename(tileset, extname(tileset)));
2024-06-11 15:06:43 -05:00
let i = 0;
for (let y = 0; y < height; y += h) {
for (let x = 0; x < width; x += w) {
2024-06-12 14:31:12 -05:00
json.frames[join(extlessPath, `${i++}`)] = {
2024-06-11 15:06:43 -05:00
frame: {x, y, w, h},
spriteSourceSize: {x: 0, y: 0, w, h},
sourceSize: {w, h},
};
}
}
writeFileSync(
2024-06-12 14:31:12 -05:00
`${extlessPath}.json`,
2024-06-11 15:06:43 -05:00
JSON.stringify(json),
);