Skip to content

Commit c646a8c

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

File tree

1 file changed

+79
-39
lines changed

1 file changed

+79
-39
lines changed

includes/RhythmGameUtilities/Parsers.hpp

Lines changed: 79 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -99,97 +99,137 @@ 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

107-
for (auto &section : sections)
106+
if (section.name == ToString(NamedSection::SyncTrack))
108107
{
109-
if (section.name == ToString(NamedSection::SyncTrack))
108+
for (auto &line : section.lines)
110109
{
111-
for (auto &line : section.lines)
110+
if (line.second.front() == ToString(TypeCode::TimeSignatureMarker))
112111
{
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-
}
112+
timeSignatures.insert(
113+
{std::stoi(line.first), std::stoi(line.second.at(1))});
119114
}
120115
}
121116
}
122117

123118
return timeSignatures;
124119
}
125120

126-
std::map<int, int> ParseBpmFromChartSections(std::vector<ChartSection> sections)
121+
std::map<int, int>
122+
ParseTimeSignaturesFromChartSections(std::vector<ChartSection> sections)
123+
{
124+
for (auto &section : sections)
125+
{
126+
if (section.name == ToString(NamedSection::SyncTrack))
127+
{
128+
return ParseTimeSignaturesFromChartSection(section);
129+
}
130+
}
131+
132+
return std::map<int, int>();
133+
}
134+
135+
std::map<int, int> ParseBpmFromChartSection(ChartSection section)
127136
{
128137
auto bpm = std::map<int, int>();
129138

139+
if (section.name == ToString(NamedSection::SyncTrack))
140+
{
141+
for (auto &line : section.lines)
142+
{
143+
if (line.second.front() == ToString(TypeCode::BPM_Marker))
144+
{
145+
bpm.insert(
146+
{std::stoi(line.first), std::stoi(line.second.at(1))});
147+
}
148+
}
149+
}
150+
151+
return bpm;
152+
}
153+
154+
std::map<int, int> ParseBpmFromChartSections(std::vector<ChartSection> sections)
155+
{
130156
for (auto &section : sections)
131157
{
132158
if (section.name == ToString(NamedSection::SyncTrack))
133159
{
134-
for (auto &line : section.lines)
160+
return ParseBpmFromChartSection(section);
161+
}
162+
}
163+
164+
return std::map<int, int>();
165+
}
166+
167+
std::vector<Note> ParseNotesFromChartSection(ChartSection section,
168+
Difficulty difficulty)
169+
{
170+
auto notes = std::vector<Note>();
171+
172+
if (section.name == ToString(difficulty) + "Single")
173+
{
174+
for (auto &line : section.lines)
175+
{
176+
if (line.second.front() == ToString(TypeCode::NoteMarker))
135177
{
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-
}
178+
notes.push_back({std::stoi(line.first),
179+
std::stoi(line.second.at(1)),
180+
std::stoi(line.second.at(2))});
141181
}
142182
}
143183
}
144184

145-
return bpm;
185+
return notes;
146186
}
147187

148188
std::vector<Note>
149189
ParseNotesFromChartSections(std::vector<ChartSection> sections,
150190
Difficulty difficulty)
151191
{
152-
auto notes = std::vector<Note>();
153-
154192
for (auto &section : sections)
155193
{
156194
if (section.name == ToString(difficulty) + "Single")
157195
{
158-
for (auto &line : section.lines)
196+
return ParseNotesFromChartSection(section, difficulty);
197+
}
198+
}
199+
200+
return std::vector<Note>();
201+
}
202+
203+
std::map<int, std::string> ParseLyricsFromChartSection(ChartSection section)
204+
{
205+
auto lyrics = std::map<int, std::string>();
206+
207+
if (section.name == ToString(NamedSection::Events))
208+
{
209+
for (auto &line : section.lines)
210+
{
211+
if (line.second.back().rfind("lyric", 0) == 0)
159212
{
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-
}
213+
lyrics.insert({std::stoi(line.first), line.second.at(1)});
166214
}
167215
}
168216
}
169217

170-
return notes;
218+
return lyrics;
171219
}
172220

173221
std::map<int, std::string>
174222
ParseLyricsFromChartSections(std::vector<ChartSection> sections)
175223
{
176-
auto lyrics = std::map<int, std::string>();
177-
178224
for (auto &section : sections)
179225
{
180226
if (section.name == ToString(NamedSection::Events))
181227
{
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-
}
228+
return ParseLyricsFromChartSection(section);
189229
}
190230
}
191231

192-
return lyrics;
232+
return std::map<int, std::string>();
193233
}
194234

195235
} // namespace RhythmGameUtilities

0 commit comments

Comments
 (0)