@@ -38,24 +38,22 @@ typedef struct
38
38
int lineCount;
39
39
} ChartSectionInternal;
40
40
41
- typedef struct
42
- {
43
- std::string name;
44
- std::vector<std::pair<std::string, std::vector<std::string>>> lines;
45
- } ChartSection;
46
-
47
41
std::regex CHART_SECTION_PATTERN (" \\ [([a-z]+)\\ ]\\ s*\\ {([^\\ }]+)\\ }" ,
48
42
std::regex_constants::icase);
49
43
50
44
std::regex CHART_SECTION_LINE_PATTERN (" ([^=]+)\\ s*=([^\\ r\\ n]+)" );
51
45
52
46
std::regex JSON_VALUE_PATTERN (" (\" [^\" ]+\" |\\ S+)" );
53
47
54
- std::vector<ChartSection> ParseSectionsFromChart (const char *contents)
48
+ std::map<std::string,
49
+ std::vector<std::pair<std::string, std::vector<std::string>>>>
50
+ ParseSectionsFromChart (const char *contents)
55
51
{
56
52
auto matches = FindAllMatches (contents, CHART_SECTION_PATTERN);
57
53
58
- auto sections = std::vector<ChartSection>();
54
+ std::map<std::string,
55
+ std::vector<std::pair<std::string, std::vector<std::string>>>>
56
+ sections;
59
57
60
58
for (auto i = 0 ; i < matches.size (); i += 1 )
61
59
{
@@ -66,15 +64,10 @@ std::vector<ChartSection> ParseSectionsFromChart(const char *contents)
66
64
continue ;
67
65
}
68
66
69
- ChartSection section;
70
-
71
- section.name = parts[1 ].c_str ();
72
-
73
67
auto lines =
74
68
FindAllMatches (parts[2 ].c_str (), CHART_SECTION_LINE_PATTERN);
75
69
76
- section.lines =
77
- std::vector<std::pair<std::string, std::vector<std::string>>>();
70
+ std::vector<std::pair<std::string, std::vector<std::string>>> items;
78
71
79
72
for (auto j = 0 ; j < lines.size (); j += 1 )
80
73
{
@@ -91,47 +84,34 @@ std::vector<ChartSection> ParseSectionsFromChart(const char *contents)
91
84
std::regex_replace (values[k], std::regex (" ^\" |\" $" ), " " );
92
85
}
93
86
94
- section. lines .push_back (std::make_pair (key, values));
87
+ items .push_back (std::make_pair (key, values));
95
88
}
96
89
97
- sections.push_back (section );
90
+ sections.insert ({parts[ 1 ]. c_str (), items} );
98
91
}
99
92
100
93
return sections;
101
94
}
102
95
103
- std::map<std::string, std::string>
104
- ParseMetaDataFromChartSection (ChartSection section)
96
+ std::map<std::string, std::string> ParseMetaDataFromChartSection (
97
+ std::vector<std::pair<std::string, std::vector<std::string>>> section)
105
98
{
106
99
auto data = std::map<std::string, std::string>();
107
100
108
- for (auto &line : section. lines )
101
+ for (auto &line : section)
109
102
{
110
103
data.insert ({line.first , line.second .front ()});
111
104
}
112
105
113
106
return data;
114
107
}
115
108
116
- std::map<std::string, std::string>
117
- ParseMetaDataFromChartSections (std::vector<ChartSection> sections)
118
- {
119
- for (auto §ion : sections)
120
- {
121
- if (section.name == ToString (NamedSection::Song))
122
- {
123
- return ParseMetaDataFromChartSection (section);
124
- }
125
- }
126
-
127
- return std::map<std::string, std::string>();
128
- }
129
-
130
- std::map<int , int > ParseTimeSignaturesFromChartSection (ChartSection section)
109
+ std::map<int , int > ParseTimeSignaturesFromChartSection (
110
+ std::vector<std::pair<std::string, std::vector<std::string>>> section)
131
111
{
132
112
auto timeSignatures = std::map<int , int >();
133
113
134
- for (auto &line : section. lines )
114
+ for (auto &line : section)
135
115
{
136
116
if (line.second .front () == ToString (TypeCode::TimeSignatureMarker))
137
117
{
@@ -143,25 +123,12 @@ std::map<int, int> ParseTimeSignaturesFromChartSection(ChartSection section)
143
123
return timeSignatures;
144
124
}
145
125
146
- std::map<int , int >
147
- ParseTimeSignaturesFromChartSections (std::vector<ChartSection> sections)
148
- {
149
- for (auto §ion : sections)
150
- {
151
- if (section.name == ToString (NamedSection::SyncTrack))
152
- {
153
- return ParseTimeSignaturesFromChartSection (section);
154
- }
155
- }
156
-
157
- return std::map<int , int >();
158
- }
159
-
160
- std::map<int , int > ParseBpmFromChartSection (ChartSection section)
126
+ std::map<int , int > ParseBpmFromChartSection (
127
+ std::vector<std::pair<std::string, std::vector<std::string>>> section)
161
128
{
162
129
auto bpm = std::map<int , int >();
163
130
164
- for (auto &line : section. lines )
131
+ for (auto &line : section)
165
132
{
166
133
if (line.second .front () == ToString (TypeCode::BPM_Marker))
167
134
{
@@ -172,24 +139,12 @@ std::map<int, int> ParseBpmFromChartSection(ChartSection section)
172
139
return bpm;
173
140
}
174
141
175
- std::map<int , int > ParseBpmFromChartSections (std::vector<ChartSection> sections)
176
- {
177
- for (auto §ion : sections)
178
- {
179
- if (section.name == ToString (NamedSection::SyncTrack))
180
- {
181
- return ParseBpmFromChartSection (section);
182
- }
183
- }
184
-
185
- return std::map<int , int >();
186
- }
187
-
188
- std::vector<Note> ParseNotesFromChartSection (ChartSection section)
142
+ std::vector<Note> ParseNotesFromChartSection (
143
+ std::vector<std::pair<std::string, std::vector<std::string>>> section)
189
144
{
190
145
auto notes = std::vector<Note>();
191
146
192
- for (auto &line : section. lines )
147
+ for (auto &line : section)
193
148
{
194
149
if (line.second .front () == ToString (TypeCode::NoteMarker))
195
150
{
@@ -202,26 +157,12 @@ std::vector<Note> ParseNotesFromChartSection(ChartSection section)
202
157
return notes;
203
158
}
204
159
205
- std::vector<Note>
206
- ParseNotesFromChartSections (std::vector<ChartSection> sections,
207
- Difficulty difficulty)
208
- {
209
- for (auto §ion : sections)
210
- {
211
- if (section.name == ToString (difficulty) + " Single" )
212
- {
213
- return ParseNotesFromChartSection (section);
214
- }
215
- }
216
-
217
- return std::vector<Note>();
218
- }
219
-
220
- std::map<int , std::string> ParseLyricsFromChartSection (ChartSection section)
160
+ std::map<int , std::string> ParseLyricsFromChartSection (
161
+ std::vector<std::pair<std::string, std::vector<std::string>>> section)
221
162
{
222
163
auto lyrics = std::map<int , std::string>();
223
164
224
- for (auto &line : section. lines )
165
+ for (auto &line : section)
225
166
{
226
167
if (line.second .back ().rfind (" lyric" , 0 ) == 0 )
227
168
{
@@ -232,18 +173,4 @@ std::map<int, std::string> ParseLyricsFromChartSection(ChartSection section)
232
173
return lyrics;
233
174
}
234
175
235
- std::map<int , std::string>
236
- ParseLyricsFromChartSections (std::vector<ChartSection> sections)
237
- {
238
- for (auto §ion : sections)
239
- {
240
- if (section.name == ToString (NamedSection::Events))
241
- {
242
- return ParseLyricsFromChartSection (section);
243
- }
244
- }
245
-
246
- return std::map<int , std::string>();
247
- }
248
-
249
176
} // namespace RhythmGameUtilities
0 commit comments