Skip to content

Commit b2fac3d

Browse files
committed
Removed ParseFromChartSections helper methods.
1 parent 0dd8451 commit b2fac3d

File tree

8 files changed

+143
-174
lines changed

8 files changed

+143
-174
lines changed

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ int main()
213213

214214
auto sections = ParseSectionsFromChart(content.c_str());
215215

216-
auto metaData = ParseMetaDataFromChartSections(sections);
216+
auto metaData = ParseMetaDataFromChartSection(
217+
sections.at(ToString(NamedSection::Song)));
217218

218219
std::cout << metaData["Name"] << std::endl; // Example Song
219220
std::cout << metaData["Resolution"] << std::endl; // 192
@@ -255,7 +256,8 @@ int main()
255256

256257
auto sections = ParseSectionsFromChart(content.c_str());
257258

258-
auto timeSignatures = ParseTimeSignaturesFromChartSections(sections);
259+
auto timeSignatures = ParseTimeSignaturesFromChartSection(
260+
sections.at(ToString(NamedSection::SyncTrack)));
259261

260262
std::cout << size(timeSignatures) << std::endl; // 4
261263

@@ -295,7 +297,8 @@ int main()
295297

296298
auto sections = ParseSectionsFromChart(content.c_str());
297299

298-
auto bpm = ParseBpmFromChartSections(sections);
300+
auto bpm = ParseBpmFromChartSection(
301+
sections.at(ToString(NamedSection::SyncTrack)));
299302

300303
std::cout << size(bpm) << std::endl; // 7
301304

@@ -335,7 +338,8 @@ int main()
335338

336339
auto sections = ParseSectionsFromChart(content.c_str());
337340

338-
auto notes = ParseNotesFromChartSections(sections, Expert);
341+
auto notes = ParseNotesFromChartSection(
342+
sections.at(ToString(Difficulty::Expert) + "Single"));
339343

340344
for (auto &note : notes)
341345
{
@@ -383,7 +387,8 @@ int main()
383387

384388
auto sections = ParseSectionsFromChart(content.c_str());
385389

386-
auto lyrics = ParseLyricsFromChartSections(sections);
390+
auto lyrics = ParseLyricsFromChartSection(
391+
sections.at(ToString(NamedSection::Events)));
387392

388393
std::cout << size(lyrics) << std::endl; // 12
389394

RhythmGameUtilities.Tests/ParsersTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void TestParseSectionsFromChart()
2222
}
2323

2424
[Test]
25-
public void TestParseValuesFromChartSections()
25+
public void TestParseValuesFromChartSection()
2626
{
2727
var sections = Parsers.ParseSectionsFromChart(Mocks.SONG_CHART);
2828

@@ -58,7 +58,7 @@ public void TestParseTimeSignaturesFromChartSection()
5858
}
5959

6060
[Test]
61-
public void TestParseBpmFromChartSections()
61+
public void TestParseBpmFromChartSection()
6262
{
6363
var sections = Parsers.ParseSectionsFromChart(Mocks.SONG_CHART);
6464

@@ -68,7 +68,7 @@ public void TestParseBpmFromChartSections()
6868
}
6969

7070
[Test]
71-
public void TestParseNotesFromChartSections()
71+
public void TestParseNotesFromChartSection()
7272
{
7373
var sections = Parsers.ParseSectionsFromChart(Mocks.SONG_CHART);
7474

@@ -78,7 +78,7 @@ public void TestParseNotesFromChartSections()
7878
}
7979

8080
[Test]
81-
public void TestParseLyricsFromChartSections()
81+
public void TestParseLyricsFromChartSection()
8282
{
8383
var sections = Parsers.ParseSectionsFromChart(Mocks.SONG_CHART);
8484

UnityPackage/Editor/Tests/ParsersTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void TestParseSectionsFromChart()
2222
}
2323

2424
[Test]
25-
public void TestParseValuesFromChartSections()
25+
public void TestParseValuesFromChartSection()
2626
{
2727
var sections = Parsers.ParseSectionsFromChart(Mocks.SONG_CHART);
2828

@@ -58,7 +58,7 @@ public void TestParseTimeSignaturesFromChartSection()
5858
}
5959

6060
[Test]
61-
public void TestParseBpmFromChartSections()
61+
public void TestParseBpmFromChartSection()
6262
{
6363
var sections = Parsers.ParseSectionsFromChart(Mocks.SONG_CHART);
6464

@@ -68,7 +68,7 @@ public void TestParseBpmFromChartSections()
6868
}
6969

7070
[Test]
71-
public void TestParseNotesFromChartSections()
71+
public void TestParseNotesFromChartSection()
7272
{
7373
var sections = Parsers.ParseSectionsFromChart(Mocks.SONG_CHART);
7474

@@ -78,7 +78,7 @@ public void TestParseNotesFromChartSections()
7878
}
7979

8080
[Test]
81-
public void TestParseLyricsFromChartSections()
81+
public void TestParseLyricsFromChartSection()
8282
{
8383
var sections = Parsers.ParseSectionsFromChart(Mocks.SONG_CHART);
8484

UnityPackage/README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ int main()
213213

214214
auto sections = ParseSectionsFromChart(content.c_str());
215215

216-
auto metaData = ParseMetaDataFromChartSections(sections);
216+
auto metaData = ParseMetaDataFromChartSection(
217+
sections.at(ToString(NamedSection::Song)));
217218

218219
std::cout << metaData["Name"] << std::endl; // Example Song
219220
std::cout << metaData["Resolution"] << std::endl; // 192
@@ -255,7 +256,8 @@ int main()
255256

256257
auto sections = ParseSectionsFromChart(content.c_str());
257258

258-
auto timeSignatures = ParseTimeSignaturesFromChartSections(sections);
259+
auto timeSignatures = ParseTimeSignaturesFromChartSection(
260+
sections.at(ToString(NamedSection::SyncTrack)));
259261

260262
std::cout << size(timeSignatures) << std::endl; // 4
261263

@@ -295,7 +297,8 @@ int main()
295297

296298
auto sections = ParseSectionsFromChart(content.c_str());
297299

298-
auto bpm = ParseBpmFromChartSections(sections);
300+
auto bpm = ParseBpmFromChartSection(
301+
sections.at(ToString(NamedSection::SyncTrack)));
299302

300303
std::cout << size(bpm) << std::endl; // 7
301304

@@ -335,7 +338,8 @@ int main()
335338

336339
auto sections = ParseSectionsFromChart(content.c_str());
337340

338-
auto notes = ParseNotesFromChartSections(sections, Expert);
341+
auto notes = ParseNotesFromChartSection(
342+
sections.at(ToString(Difficulty::Expert) + "Single"));
339343

340344
for (auto &note : notes)
341345
{
@@ -383,7 +387,8 @@ int main()
383387

384388
auto sections = ParseSectionsFromChart(content.c_str());
385389

386-
auto lyrics = ParseLyricsFromChartSections(sections);
390+
auto lyrics = ParseLyricsFromChartSection(
391+
sections.at(ToString(NamedSection::Events)));
387392

388393
std::cout << size(lyrics) << std::endl; // 12
389394

includes/RhythmGameUtilities/Parsers.hpp

Lines changed: 24 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,22 @@ typedef struct
3838
int lineCount;
3939
} ChartSectionInternal;
4040

41-
typedef struct
42-
{
43-
std::string name;
44-
std::vector<std::pair<std::string, std::vector<std::string>>> lines;
45-
} ChartSection;
46-
4741
std::regex CHART_SECTION_PATTERN("\\[([a-z]+)\\]\\s*\\{([^\\}]+)\\}",
4842
std::regex_constants::icase);
4943

5044
std::regex CHART_SECTION_LINE_PATTERN("([^=]+)\\s*=([^\\r\\n]+)");
5145

5246
std::regex JSON_VALUE_PATTERN("(\"[^\"]+\"|\\S+)");
5347

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)
5551
{
5652
auto matches = FindAllMatches(contents, CHART_SECTION_PATTERN);
5753

58-
auto sections = std::vector<ChartSection>();
54+
std::map<std::string,
55+
std::vector<std::pair<std::string, std::vector<std::string>>>>
56+
sections;
5957

6058
for (auto i = 0; i < matches.size(); i += 1)
6159
{
@@ -66,15 +64,10 @@ std::vector<ChartSection> ParseSectionsFromChart(const char *contents)
6664
continue;
6765
}
6866

69-
ChartSection section;
70-
71-
section.name = parts[1].c_str();
72-
7367
auto lines =
7468
FindAllMatches(parts[2].c_str(), CHART_SECTION_LINE_PATTERN);
7569

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;
7871

7972
for (auto j = 0; j < lines.size(); j += 1)
8073
{
@@ -91,47 +84,34 @@ std::vector<ChartSection> ParseSectionsFromChart(const char *contents)
9184
std::regex_replace(values[k], std::regex("^\"|\"$"), "");
9285
}
9386

94-
section.lines.push_back(std::make_pair(key, values));
87+
items.push_back(std::make_pair(key, values));
9588
}
9689

97-
sections.push_back(section);
90+
sections.insert({parts[1].c_str(), items});
9891
}
9992

10093
return sections;
10194
}
10295

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)
10598
{
10699
auto data = std::map<std::string, std::string>();
107100

108-
for (auto &line : section.lines)
101+
for (auto &line : section)
109102
{
110103
data.insert({line.first, line.second.front()});
111104
}
112105

113106
return data;
114107
}
115108

116-
std::map<std::string, std::string>
117-
ParseMetaDataFromChartSections(std::vector<ChartSection> sections)
118-
{
119-
for (auto &section : 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)
131111
{
132112
auto timeSignatures = std::map<int, int>();
133113

134-
for (auto &line : section.lines)
114+
for (auto &line : section)
135115
{
136116
if (line.second.front() == ToString(TypeCode::TimeSignatureMarker))
137117
{
@@ -143,25 +123,12 @@ std::map<int, int> ParseTimeSignaturesFromChartSection(ChartSection section)
143123
return timeSignatures;
144124
}
145125

146-
std::map<int, int>
147-
ParseTimeSignaturesFromChartSections(std::vector<ChartSection> sections)
148-
{
149-
for (auto &section : 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)
161128
{
162129
auto bpm = std::map<int, int>();
163130

164-
for (auto &line : section.lines)
131+
for (auto &line : section)
165132
{
166133
if (line.second.front() == ToString(TypeCode::BPM_Marker))
167134
{
@@ -172,24 +139,12 @@ std::map<int, int> ParseBpmFromChartSection(ChartSection section)
172139
return bpm;
173140
}
174141

175-
std::map<int, int> ParseBpmFromChartSections(std::vector<ChartSection> sections)
176-
{
177-
for (auto &section : 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)
189144
{
190145
auto notes = std::vector<Note>();
191146

192-
for (auto &line : section.lines)
147+
for (auto &line : section)
193148
{
194149
if (line.second.front() == ToString(TypeCode::NoteMarker))
195150
{
@@ -202,26 +157,12 @@ std::vector<Note> ParseNotesFromChartSection(ChartSection section)
202157
return notes;
203158
}
204159

205-
std::vector<Note>
206-
ParseNotesFromChartSections(std::vector<ChartSection> sections,
207-
Difficulty difficulty)
208-
{
209-
for (auto &section : 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)
221162
{
222163
auto lyrics = std::map<int, std::string>();
223164

224-
for (auto &line : section.lines)
165+
for (auto &line : section)
225166
{
226167
if (line.second.back().rfind("lyric", 0) == 0)
227168
{
@@ -232,18 +173,4 @@ std::map<int, std::string> ParseLyricsFromChartSection(ChartSection section)
232173
return lyrics;
233174
}
234175

235-
std::map<int, std::string>
236-
ParseLyricsFromChartSections(std::vector<ChartSection> sections)
237-
{
238-
for (auto &section : 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-
249176
} // namespace RhythmGameUtilities

0 commit comments

Comments
 (0)