Skip to content

Commit b548782

Browse files
committed
Added .cs parser
1 parent 98389ce commit b548782

File tree

1 file changed

+40
-23
lines changed

1 file changed

+40
-23
lines changed

development/sonlvl.js

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,29 @@ const folders = [
1616
'objSLZ.ini',
1717
'objSYZ.ini',
1818
];
19-
const pathMod = (str) => str.slice(3).replace(/&/g, '&').replace(/\|.+/, '');
2019
const basePalette = [
2120
{ path: 'palette/Sonic.bin', length: 1 }
2221
];
22+
const pathMod = (str) => str.slice(3).replace(/&/g, '&').replace(/\|.+/, '');
23+
24+
const baseObj = {
25+
name: '???',
26+
format,
27+
art: {
28+
path: '',
29+
compression: defaultCmp,
30+
offset: 0,
31+
},
32+
mappings: {
33+
path: '',
34+
label: '',
35+
},
36+
dplcs: {
37+
enabled: false,
38+
path: '',
39+
label: '',
40+
},
41+
};
2342

2443
function parseINI(ini) {
2544
ini = ini.match(/\[.+\][^[]+/gm);
@@ -63,27 +82,26 @@ folders.forEach(filename => {
6382

6483
const ini = readFileSync(join(base, filename), 'utf8');
6584
parseINI(ini).forEach(obj => {
66-
if (obj.xmlfile) {
85+
if (obj.codefile) {
86+
const cs = readFileSync(join(base, obj.codefile), 'utf8');
87+
const flexObj = { ...baseObj, palettes };
88+
const name = cs.match(/Name\s+{\s+get { return "(.+?)"/)
89+
if (name) {
90+
flexObj.name = name[1];
91+
}
92+
const art = cs.match(/OpenArtFile\("(.+?)"/);
93+
if (art) {
94+
flexObj.art.path = pathMod(art[1]);
95+
}
96+
const map = cs.match(/artfile,(.+)?"(.+?)",/);
97+
if (map) {
98+
flexObj.mappings.path = pathMod(map[2]);
99+
}
100+
folder.children.push(flexObj);
101+
102+
} else if (obj.xmlfile) {
67103
const xml = readFileSync(join(base, obj.xmlfile), 'utf8');
68-
const flexObj = {
69-
name: '???',
70-
palettes,
71-
format,
72-
art: {
73-
path: '',
74-
compression: defaultCmp,
75-
offset: 0,
76-
},
77-
mappings: {
78-
path: '',
79-
label: '',
80-
},
81-
dplcs: {
82-
enabled: false,
83-
path: '',
84-
label: '',
85-
},
86-
};
104+
const flexObj = { ...baseObj, palettes };
87105

88106
const name = xml.match(/Name="(.+?)"/);
89107
if (name) {
@@ -99,8 +117,7 @@ folders.forEach(filename => {
99117
}
100118

101119
folder.children.push(flexObj);
102-
}
103-
if (obj.art && obj.mapasm) {
120+
} else if (obj.art && obj.mapasm) {
104121
const flexObj = {
105122
name: obj.name || '???',
106123
palettes,

0 commit comments

Comments
 (0)