-
Notifications
You must be signed in to change notification settings - Fork 0
/
smReader.js
267 lines (219 loc) · 5.81 KB
/
smReader.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
//Proprietary script to convert Stepmania SM files to JSON objects usable in faerie.FM
//Format for the Output Data
var obj = {
greenDust:{
name: 'greenDust',
fileName: 'greenDust',
color: 'red',
quantity: 50,
animated: false,
frames: undefined,
x:[],
y:[],
ix:[],
iy:[]
},
wall: {
name: 'wall',
fileName: 'wall',
color: 'blue',
quantity: 50,
animated: false,
frames: undefined,
x: [],
y: [],
ix: [],
iy: []
},
settings: {
name: 'settings',
bpm: BPM
}
}
//globals
var fs = require('fs');
var filePath = process.argv[2];
var path = require('path');
var fileName = path.basename(filePath, '.sm');
var outFile = path.join("levels" + '.json');
var noteSection = false;
var doubleSection = false;
var beginnerSong = false;
var beginnerNotes = [];
var mediumNotes = [];
var beginnerBox=[];
var titleBox=[];
var linePos = 0;
var fileData, splitData, BPM, lineTotal, measureNum, measureLength, noteTime;
//First take in Data from the command line
fileData = fs.readFileSync(filePath, 'utf8');
//Process the data
splitData = fileData.split(" ");
console.log(splitData);
var arrayLength = splitData.length;
for(var i=0; i<arrayLength; i++){
if(splitData[i]== '----------------\r\n#NOTES:\r\n'){
console.log("Notes section found...");
noteSection = true;
}
else if(i==1){
var titleData = splitData[i];
titleBox = titleData.split("\r\n");
for(var k=0; k<titleBox.length; k++){
var bpmBox = titleBox[k];
if(bpmBox.indexOf("BPMS") >= 0){
var bpmBoxSplit = bpmBox.split("=");
BPM = parseInt(bpmBoxSplit[1]);
console.log("BPM found: " + BPM);
}
}
}
else if(splitData[i]=='dance-double:\r\n' && noteSection==true){
console.log("Doubles section found...");
doubleSection = true;
}
else if(splitData[i]=='Beginner:\r\n' && doubleSection==true){
beginnerSong = true;
mediumSong = false;
}
else if(splitData[i]=='Medium:\r\n'){
mediumSong = true;
beginnerSong = false;
}
else if(splitData[i]=='measure' && noteSection==true && doubleSection==true) {
var j = i+1;
if(beginnerSong==true){
beginnerNotes.push(splitData[j]);
}
else if(mediumSong==true){
mediumNotes.push(splitData[j]);
}
}
else if(splitData[i]=='dance-single:\r\n'){
noteSection = false;
doubleSection = false;
beginnerSong = false;
mediumSong = false;
}
}
//Error Messages go here
if(noteSection=false){
console.log("Notes section not found!");
}
console.log(beginnerNotes);
function splitNotes(){
for(var i=0; i<beginnerNotes.length; i++){
var currentString = beginnerNotes[i];
var beginnerSplit = currentString.split("\r\n");
beginnerBox.push(beginnerSplit);
}
console.log(beginnerBox);
}
splitNotes();
//Convert Data to actual times here
//BPM, measureLength, linePos, lineTotal, measureNum
function getMeasureLength(){
measureLength = (60/BPM)*4;
}
getMeasureLength();
function getNoteTime(){
for(i=0; i<beginnerBox.length; i++){
linePos = 0;
for(j=1; j<=beginnerBox[i].length-2; j++){
linePos++;
lineTotal = beginnerBox[i].length-2;
measureNum = parseInt(beginnerBox[i][0]);
if(beginnerBox[i][j].indexOf("1")>=0){
//calculate y time
noteTime = (linePos-1)*(measureLength/lineTotal)+(measureNum*measureLength);
//calculate x position
let ix = [];
let pushCount = 1;
let boxline = beginnerBox[i][j];
for(q=0; q<boxline.length; q++){
if(boxline.charAt(q)=="1"){
switch(q){
case 0:
ix.push(87);
break;
case 1:
ix.push(222);
break;
case 2:
ix.push(359);
break;
case 3:
ix.push(496);
break;
case 4:
ix.push(633);
break;
case 5:
break;
case 6:
break;
}
}
}
pushCount = ix.length;
for(k=0; k<ix.length; k++){
obj['greenDust']['ix'].push(ix[k]);
}
for(l=0; l<pushCount; l++){
obj['greenDust']['iy'].push(noteTime);
}
}
if(beginnerBox[i][j].indexOf("M")>=0){
//calculate y time of the Wall obstacle
noteTime = (linePos-1)*(measureLength/lineTotal)+(measureNum*measureLength);
//calculate x position of the wall obstacle
let ix = [];
let pushCount = 1;
let boxline = beginnerBox[i][j];
for(p=0; p<boxline.length; p++){
if(boxline.charAt(p)=="M"){
switch(p){
case 0:
ix.push(87);
break;
case 1:
ix.push(222);
break;
case 2:
ix.push(359);
break;
case 3:
ix.push(496);
break;
case 4:
ix.push(633);
break;
case 5:
break;
case 6:
break;
}
}
}
pushCount = ix.length;
for(m=0; m<ix.length; m++){
obj['wall']['ix'].push(ix[m]);
}
for(n=0; n<pushCount; n++){
obj['wall']['iy'].push(noteTime);
}
}
}
}
}
obj['settings']['bpm'] = BPM;
getNoteTime();
console.log(obj);
//Error Messages go here
if(noteSection=false){
console.log("Notes section not found!");
}
//Write then data to a new file
var JSONobj = JSON.stringify(obj);
var inData = "\r\n" + "var " + fileName + " = " + "'" + JSONobj + "'";
fs.appendFileSync(outFile, inData, 'utf-8');