-
Notifications
You must be signed in to change notification settings - Fork 0
/
Reader.cs
127 lines (123 loc) · 6.95 KB
/
Reader.cs
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
using System;
using System.Collections.Generic;
using System.IO;
namespace chartMerger {
class Reader {
public static Song ReadChart(string path) {
var s = new Song();
var file = new StreamReader(path);
string line;
while((line = file.ReadLine()) != null) {
line = line.Trim();
try {
if(line == "[Song]") {
line = file.ReadLine();
line = file.ReadLine();
while(line != "}") {
var tmp = line.Split('=');
if (tmp[0].Trim() == "Name") {
s.name = tmp[1].Trim().Substring(1,tmp[1].Length-3);
}
line = file.ReadLine();
}
}
if(line == "[SyncTrack]") {
line = file.ReadLine();
line = file.ReadLine();
while(line != "}") {
var tmp = line.Split('=');
if (tmp[1].Trim().Split(' ')[0] != "A") {
s.sync.Add(CreateEvent(tmp));
}
line = file.ReadLine();
}
}
if(line == "[Events]") {
line = file.ReadLine();
line = file.ReadLine();
while(line != "}") {
var tmp = line.Split('=');
if(tmp[1].Trim() == "E \"CHARTMERGER_START\"") {
s.start = Convert.ToInt64(tmp[0].Trim());
} else if(tmp[1].Trim() == "E \"CHARTMERGER_END\"") {
s.end = Convert.ToInt64(tmp[0].Trim());
} else {
s.events.Add(CreateEvent(tmp));
}
line = file.ReadLine();
}
}
if(line == "[EasySingle]") s.single[0] = ReadDiff(line,file);
if(line == "[MediumSingle]") s.single[1] = ReadDiff(line,file);
if(line == "[HardSingle]") s.single[2] = ReadDiff(line,file);
if(line == "[ExpertSingle]") s.single[3] = ReadDiff(line,file);
if(line == "[EasyDoubleGuitar]") s.doubleGuitar[0] = ReadDiff(line,file);
if(line == "[MediumDoubleGuitar]") s.doubleGuitar[1] = ReadDiff(line,file);
if(line == "[HardDoubleGuitar]") s.doubleGuitar[2] = ReadDiff(line,file);
if(line == "[ExpertDoubleGuitar]") s.doubleGuitar[3] = ReadDiff(line,file);
if(line == "[EasyDoubleBass]") s.doubleBass[0] = ReadDiff(line,file);
if(line == "[MediumDoubleBass]") s.doubleBass[1] = ReadDiff(line,file);
if(line == "[HardDoubleBass]") s.doubleBass[2] = ReadDiff(line,file);
if(line == "[ExpertDoubleBass]") s.doubleBass[3] = ReadDiff(line,file);
if(line == "[EasyEnhancedGuitar]") s.enhancedGuitar[0] = ReadDiff(line,file);
if(line == "[MediumEnhancedGuitar]") s.enhancedGuitar[1] = ReadDiff(line,file);
if(line == "[HardEnhancedGuitar]") s.enhancedGuitar[2] = ReadDiff(line,file);
if(line == "[ExpertEnhancedGuitar]") s.enhancedGuitar[3] = ReadDiff(line,file);
if(line == "[EasyCoopLead]") s.coopLead[0] = ReadDiff(line,file);
if(line == "[MediumCoopLead]") s.coopLead[1] = ReadDiff(line,file);
if(line == "[HardCoopLead]") s.coopLead[2] = ReadDiff(line,file);
if(line == "[ExpertCoopLead]") s.coopLead[3] = ReadDiff(line,file);
if(line == "[EasyCoopBass]") s.coopBass[0] = ReadDiff(line,file);
if(line == "[MediumCoopBass]") s.coopBass[1] = ReadDiff(line,file);
if(line == "[HardCoopBass]") s.coopBass[2] = ReadDiff(line,file);
if(line == "[ExpertCoopBass]") s.coopBass[3] = ReadDiff(line,file);
if(line == "[Easy10KeyGuitar]") s.tenKeyGuitar[0] = ReadDiff(line,file);
if(line == "[Medium10KeyGuitar]") s.tenKeyGuitar[1] = ReadDiff(line,file);
if(line == "[Hard10KeyGuitar]") s.tenKeyGuitar[2] = ReadDiff(line,file);
if(line == "[Expert10KeyGuitar]") s.tenKeyGuitar[3] = ReadDiff(line,file);
if(line == "[EasyDrums]") s.drums[0] = ReadDiff(line,file);
if(line == "[MediumDrums]") s.drums[1] = ReadDiff(line,file);
if(line == "[HardDrums]") s.drums[2] = ReadDiff(line,file);
if(line == "[ExpertDrums]") s.drums[3] = ReadDiff(line,file);
if(line == "[EasyDoubleDrums]") s.doubleDrums[0] = ReadDiff(line,file);
if(line == "[MediumDoubleDrums]") s.doubleDrums[1] = ReadDiff(line,file);
if(line == "[HardDoubleDrums]") s.doubleDrums[2] = ReadDiff(line,file);
if(line == "[ExpertDoubleDrums]") s.doubleDrums[3] = ReadDiff(line,file);
if(line == "[EasyVocals]") s.vocals[0] = ReadDiff(line,file);
if(line == "[MediumVocals]") s.vocals[1] = ReadDiff(line,file);
if(line == "[HardVocals]") s.vocals[2] = ReadDiff(line,file);
if(line == "[ExpertVocals]") s.vocals[3] = ReadDiff(line,file);
if(line == "[EasyKeyboard]") s.keyboard[0] = ReadDiff(line,file);
if(line == "[MediumKeyboard]") s.keyboard[1] = ReadDiff(line,file);
if(line == "[HardKeyboard]") s.keyboard[2] = ReadDiff(line,file);
if(line == "[ExpertKeyboard]") s.keyboard[3] = ReadDiff(line,file);
} catch(Exception e) {
if(line != "}") Console.WriteLine("Error parsing line {0} - ignoring it",line);
}
}
return s;
}
private static List<Event> ReadDiff(string line,StreamReader file) {
List <Event> diff = new List<Event>();
line = file.ReadLine();
line = file.ReadLine();
while(line != "}") {
var tmp = line.Split('=');
diff.Add(CreateEvent(tmp));
line = file.ReadLine();
}
return diff;
}
private static Event CreateEvent(string[] tmp) {
long tick = 0;
tick = Convert.ToInt64(tmp[0].Trim());
string data = tmp[1];
if(tmp.Length > 2) {
for(int i = 2; i < tmp.Length; i++) {
data += tmp[i];
}
}
return new Event(tick,data.Trim());
}
}
}