cocos的plist转egretjson

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// cocos plist 动画转 egret json文件
function p2e(farr){
for(let f of farr){
fs.readFile(bpath + f, (err,bu)=>{
if(err){
console.log(err);
return;
}
let jn = xml.xml2js(bu, {compact: true});
console.log(jn);
let ejn = {mc:{
run:{frameRate:24,labels:[],frames:[]}
},
file:jn.plist.dict.dict[1].string[0]._text,
res:{}};
let fn = "", frame = 0;
console.log("basefile");
for(let i=0;i<jn.plist.dict.dict[0].key.length;i++){
let pos = jn.plist.dict.dict[0].dict[i].string[0]._text;
pos = pos.substr(2, pos.length-4).replace("},{",",").split(",");
console.log(jn.plist.dict.dict[0].key[i]._text, pos);

ejn.res[jn.plist.dict.dict[0].key[i]._text] = {x:pos[0],y:pos[1],w:pos[2],h:pos[3],r:("true" in jn.plist.dict.dict[0].dict[i])};

pos = jn.plist.dict.dict[0].dict[i].string[2]._text;
pos = pos.substr(2, pos.length-4).replace("},{",",").split(",");
ejn.mc.run.frames.push({res:jn.plist.dict.dict[0].key[i]._text,x:pos[0],y:pos[1]});

if(fn && jn.plist.dict.dict[0].key[i]._text.indexOf(fn) == 0){
continue;
}else{
fn = jn.plist.dict.dict[0].key[i]._text;
if(ejn.mc.run.labels.length > 0){
ejn.mc.run.labels[ejn.mc.run.labels.length-1].end = ejn.mc.run.frames.length-2;
}
}
let pl = fn.lastIndexOf("_");
if(pl != -1){
fn = fn.substr(0, pl);
}
ejn.mc.run.labels.push({name:fn,frame:frame,end:ejn.mc.run.frames.length-1});
frame = ejn.mc.run.frames.length;
if(frame > 20) break;
}
console.log(JSON.stringify(ejn));
});
}
}