var fs = require("fs")
var readline = require("readline");
var rl = readline.createInterface({
input:process.stdin,
output:process.stdout
});
var path = undefined;
var dbName = undefined;
rl.question("请输入文件名",function(answer){
path = answer;
rl.question("请输入龙骨动画名",function(answer){
dbName = answer;
readAndWriteFile();
rl.close();
})
});
var convert = function(sheetData){
var data = {};
data["imagePath"] = path + ".png";
data["name"] = dbName;
data["SubTexture"] = [];
var frames = sheetData.frames
for(var index in frames){
var frameData = frames[index];
var d = {};
d.name = index;
d.height = frameData.h;
d.width = frameData.w;
d.x = frameData.x;
d.y = frameData.y;
data["SubTexture"].push(d);
}
return data;
}
var readAndWriteFile = function(){
fs.readFile(path + ".json", function (err, data) {
if (err) {
return console.error(err);
}
var d = JSON.parse(data);
if(d["SubTexture"] !== undefined){
console.log(path + "已经转换");
return;
}
var newData = convert(d);
fs.writeFile(path + ".json", JSON.stringify(newData), function(err) {
if (err) {
return console.error(err);
}
});
});
}
Node.JS 文件读写,把Sheet图集转换为龙骨动画图集
原文:http://www.cnblogs.com/xiejunzhao/p/6523325.html