UNPKG

plistunpacker

Version:

这个包目前可以将texturepacker打包导出的plist文件分割成对应的小图片

111 lines (100 loc) 2.38 kB
const fs = require('fs'); const Command = require('./utils/Command'); const UnPacker = require('./utils/UnPacker'); const Help = require('./utils/Help'); function CreateCommand(cm) { var command = {}; command.command = cm[0]; command.split = false; cm.splice(0, 1); var it = ''; for(var i = 0; i<cm.length; i++) { it = cm[i]; if(it.substring(0, 1) == '-') { it = it.split(/-+/); if (it.length == 0) { console.error('错误的参数信息:-'); return; } else { it = it[1]; } if (it === 'infofile') { if (++i<cm.length) { command.infofile = cm[i]; } else { console.error('错误的参数信息:'+it); return; } } else if (it === 'output') { if (++i<cm.length) { command.output = cm[i]; } else { console.error('错误的参数信息:'+it); return; } } else if (it === 'split') { if (++i<cm.length) { if(cm[i] === 'true') { command.split = true; } else { command.split = false; } } else { console.error('错误的参数信息:'+it); return; } } else if (it === 'detail') { if (++i<cm.length) { if(cm[i] === 'true') { command.detail = true; } else { command.detail = false; } } else { console.error('错误的参数信息:'+it); return; } } } } return command; } var arguments = process.argv; arguments.splice(0, 2); if (arguments.length == 0) { Command.StdOut("TexturePackerV1.0.0\n 使用 -u 参数获取使用帮助\n"); Command.StdOut(Help.UseHelp); Command.StdOut("请输入命令:\n"); Command.StdIn(chunk => { var cm = chunk.substring(0, chunk.length-1).split(/ +/); if(cm[0] === '') { cm.splice(0,1); } if (cm[cm.length-1] === '') { cm.splice(cm.length-1, 1); } var command = CreateCommand(cm); if(command) { if(command.command === 'unpacker') { Command.StdOut('Unpacker...\n'); new UnPacker(command); } else { Command.StdOut("无法识别命令\n"); } } else { Command.StdOut("无法识别命令\n"); } }); } else { var command = CreateCommand(arguments); if(command) { if(command.command === 'unpacker') { Command.StdOut('Unpacker...\n'); new UnPacker(command); } else { Command.StdOut("无法识别命令\n"); } } else { Command.StdOut("无法识别命令\n"); } }