var fs = require("fs"); const { exec } = require("child_process"); var path = require('path'); var name = process.argv[2]; console.log(name); exec(`mkdir ${name}`, null); var plist = name + '.plist'; exec(`plutil -convert json ${plist}`); fs.readFile(path.join(__dirname, name + '.plist'), function(err, bytesRead) { if (err) throw err; var data = JSON.parse(bytesRead); const textureFileName = data.metadata.textureFileName; const frames = data.frames; var textureRectReg = /\{\{(\d+),(\d+)\},\{(\d+),(\d+)\}\}/ var spriteOffsetReg = /\{(-?\d+),(-?\d+)\}/ var spriteSourceSizeReg = /\{(\d+),(\d+)\}/ for (const key in frames) { let info = frames[key]; let textureRect = info.textureRect; let spriteOffset = info.spriteOffset; let spriteSourceSize = info.spriteSourceSize; let textureRotated = info.textureRotated; var [_0, x,y,w,h] = textureRectReg.exec(textureRect); var [_1, ow,oh] = spriteSourceSizeReg.exec(spriteSourceSize); console.log(spriteOffset); var [_2, ix,iy] = spriteOffsetReg.exec(spriteOffset); // var cmd = `convert ${textureFileName} -crop ${w}X${h}+${x}+${y} ${name}/${key}`; var cmd = `convert -size ${ow}${oh} xc:none -composite ${textureFileName}[${w}X${h}+${x}+${y}] -geometry +${ix}+${iy} ${name}/${key}` console.log("gen "+key); exec(cmd, null); } });
以上代码放入 unpacker.js
node unpacker.js xxx