Skip to content

Commit 742fc5a

Browse files
committed
Split parse method logic into two methods.
1 parent ff5eeda commit 742fc5a

File tree

1 file changed

+70
-44
lines changed

1 file changed

+70
-44
lines changed

includes/RhythmGameUtilities/Parsers.hpp

Lines changed: 70 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -99,97 +99,123 @@ std::vector<ChartSection> ParseSectionsFromChart(const char *contents)
9999
return sections;
100100
}
101101

102-
std::map<int, int>
103-
ParseTimeSignaturesFromChartSections(std::vector<ChartSection> sections)
102+
std::map<int, int> ParseTimeSignaturesFromChartSection(ChartSection section)
104103
{
105104
auto timeSignatures = std::map<int, int>();
106105

106+
for (auto &line : section.lines)
107+
{
108+
if (line.second.front() == ToString(TypeCode::TimeSignatureMarker))
109+
{
110+
timeSignatures.insert(
111+
{std::stoi(line.first), std::stoi(line.second.at(1))});
112+
}
113+
}
114+
115+
return timeSignatures;
116+
}
117+
118+
std::map<int, int>
119+
ParseTimeSignaturesFromChartSections(std::vector<ChartSection> sections)
120+
{
107121
for (auto &section : sections)
108122
{
109123
if (section.name == ToString(NamedSection::SyncTrack))
110124
{
111-
for (auto &line : section.lines)
112-
{
113-
if (line.second.front() ==
114-
ToString(TypeCode::TimeSignatureMarker))
115-
{
116-
timeSignatures.insert(
117-
{std::stoi(line.first), std::stoi(line.second.at(1))});
118-
}
119-
}
125+
return ParseTimeSignaturesFromChartSection(section);
120126
}
121127
}
122128

123-
return timeSignatures;
129+
return std::map<int, int>();
124130
}
125131

126-
std::map<int, int> ParseBpmFromChartSections(std::vector<ChartSection> sections)
132+
std::map<int, int> ParseBpmFromChartSection(ChartSection section)
127133
{
128134
auto bpm = std::map<int, int>();
129135

136+
for (auto &line : section.lines)
137+
{
138+
if (line.second.front() == ToString(TypeCode::BPM_Marker))
139+
{
140+
bpm.insert({std::stoi(line.first), std::stoi(line.second.at(1))});
141+
}
142+
}
143+
144+
return bpm;
145+
}
146+
147+
std::map<int, int> ParseBpmFromChartSections(std::vector<ChartSection> sections)
148+
{
130149
for (auto &section : sections)
131150
{
132151
if (section.name == ToString(NamedSection::SyncTrack))
133152
{
134-
for (auto &line : section.lines)
135-
{
136-
if (line.second.front() == ToString(TypeCode::BPM_Marker))
137-
{
138-
bpm.insert(
139-
{std::stoi(line.first), std::stoi(line.second.at(1))});
140-
}
141-
}
153+
return ParseBpmFromChartSection(section);
142154
}
143155
}
144156

145-
return bpm;
157+
return std::map<int, int>();
158+
}
159+
160+
std::vector<Note> ParseNotesFromChartSection(ChartSection section)
161+
{
162+
auto notes = std::vector<Note>();
163+
164+
for (auto &line : section.lines)
165+
{
166+
if (line.second.front() == ToString(TypeCode::NoteMarker))
167+
{
168+
notes.push_back({std::stoi(line.first),
169+
std::stoi(line.second.at(1)),
170+
std::stoi(line.second.at(2))});
171+
}
172+
}
173+
174+
return notes;
146175
}
147176

148177
std::vector<Note>
149178
ParseNotesFromChartSections(std::vector<ChartSection> sections,
150179
Difficulty difficulty)
151180
{
152-
auto notes = std::vector<Note>();
153-
154181
for (auto &section : sections)
155182
{
156183
if (section.name == ToString(difficulty) + "Single")
157184
{
158-
for (auto &line : section.lines)
159-
{
160-
if (line.second.front() == ToString(TypeCode::NoteMarker))
161-
{
162-
notes.push_back({std::stoi(line.first),
163-
std::stoi(line.second.at(1)),
164-
std::stoi(line.second.at(2))});
165-
}
166-
}
185+
return ParseNotesFromChartSection(section);
167186
}
168187
}
169188

170-
return notes;
189+
return std::vector<Note>();
171190
}
172191

173-
std::map<int, std::string>
174-
ParseLyricsFromChartSections(std::vector<ChartSection> sections)
192+
std::map<int, std::string> ParseLyricsFromChartSection(ChartSection section)
175193
{
176194
auto lyrics = std::map<int, std::string>();
177195

196+
for (auto &line : section.lines)
197+
{
198+
if (line.second.back().rfind("lyric", 0) == 0)
199+
{
200+
lyrics.insert({std::stoi(line.first), line.second.at(1)});
201+
}
202+
}
203+
204+
return lyrics;
205+
}
206+
207+
std::map<int, std::string>
208+
ParseLyricsFromChartSections(std::vector<ChartSection> sections)
209+
{
178210
for (auto &section : sections)
179211
{
180212
if (section.name == ToString(NamedSection::Events))
181213
{
182-
for (auto &line : section.lines)
183-
{
184-
if (line.second.back().rfind("lyric", 0) == 0)
185-
{
186-
lyrics.insert({std::stoi(line.first), line.second.at(1)});
187-
}
188-
}
214+
return ParseLyricsFromChartSection(section);
189215
}
190216
}
191217

192-
return lyrics;
218+
return std::map<int, std::string>();
193219
}
194220

195221
} // namespace RhythmGameUtilities

0 commit comments

Comments
 (0)