The /scripts/ directory includes a handful of APIs that can be used either directly via CLI as a standalone tool, or by importing spine2json as a package.
Parses the provided .atlas file, pushes pma: true into the atlas' attributes, and saves it as .pma.atlas
$ node scripts/patch-atlas-json.js assets/admiral/illust_admiral.atlasFixes scaling errors of provided .skel file, converts into json, and saves it as .s2j.json
$ node scripts/parse-spine-skel.js assets/admiral/illust_admiral.skelTip
The modules can be installed as a package via npm:
npm install github:gt-wikia/spine2json// importing
import { atlas } from 'spine2json/spine-atlas';// method: atlas.parse()
// returns: Object representation of atlas text
// Object contents are mutable / re-writable
const atlasTxt = readFileSync('<atlasPath>.atlas', 'utf8');
const atlasJson = atlas.parse(atlasTxt);
console.log(atlasJson);// method: atlas.stringify()
// returns: String representation of Object parsed by atlas.parse()
// String's format is same as standard atlas text
const atlasString = atlas.stringify(atlasJson);
console.log(atlasString);// object structure of parsed atlas
[
{
texture: 'texture.png',
size: [ width, height ],
format: [ 'format' ],
filter: [ 'filter', 'filter' ],
repeat: [ 'repeat' ],
regions: [
{
name: 'sprite',
rotate: [ true|false | 90|180|270 ],
xy: [ x_coord, y_coord ],
size: [ width, height ],
orig: [ padded_width, padded_height ],
offset: [ left_pad, bottom_pad ],
index: [ index ]
},
// { more regions },
]
},
// { more pages },
]// importing
import { skel2json } from 'spine2json/spine-skel';// constructor: SkeletonBinary
// parameters: (buffer, atlas, scale)
// returns: JSON built from the SkeletonBinary after fixing scalings
const skelBin = readFileSync('<skelPath>.skel');
const atlasTxt = readFileSync('<atlasPath>.atlas', 'utf8');
const atlasJson = atlas.parse(atlasTxt);
const skelJson = skel2json(skelBin, atlasJson, 1);Note
This is a legacy module with basic functionality, that was used to check the accuracy of the final parsed json when comparing it against the json exported from Spine. The module was later integrated into spine-skel.js.
// importing
import { json2patch } from 'spine2json/spine-json';