Skip to content

Commit

Permalink
Fix crlf, add testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
VioletXF committed Mar 28, 2024
1 parent 1b025b8 commit b792138
Show file tree
Hide file tree
Showing 6 changed files with 5,451 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ namespace bms_parser
auto lastMeasure = -1;
while (std::getline(stream, line))
{
if (!line.empty() && line.back() == '\r')
{
line.pop_back();
}
if (bCancelled)
{
return;
Expand Down Expand Up @@ -609,6 +613,7 @@ namespace bms_parser
case BpmChangeExtend:
{
auto id = ParseInt(val_view);
// std::cout << "BPM_CHANGE_EXTEND: " << id << ", on measure " << i << std::endl;
if (!CheckResourceIdRange(id))
{
// UE_LOG(LogTemp, Warning, TEXT("Invalid BPM id: %s"), *val);
Expand All @@ -621,6 +626,7 @@ namespace bms_parser
else
{
timeline->Bpm = 0;
// std::cout<<"Undefined BPM: "<<id<<std::endl;
}
// Debug.Log($"BPM_CHANGE_EXTEND: {timeline.Bpm}, on measure {i}, {val}");
timeline->BpmChange = true;
Expand Down Expand Up @@ -804,7 +810,6 @@ namespace bms_parser
{
measure->TimeLines.push_back(timeline);
}
new_chart->Meta.PlayLength = static_cast<long long>(timePassed);

lastPosition = position;
}
Expand All @@ -825,6 +830,7 @@ namespace bms_parser
timeline->Bpm = currentBpm;
measure->TimeLines.push_back(timeline);
}
new_chart->Meta.PlayLength = static_cast<long long>(timePassed);
timePassed += 240000000.0 * (1 - lastPosition) * measure->Scale / currentBpm;
if (!metaOnly)
{
Expand Down Expand Up @@ -1134,7 +1140,7 @@ namespace bms_parser
else if (c >= 'a' && c <= 'z')
{
result = result * 62 + c - 'a' + 36;
}
} else return -1;
}
// std::wcout << "ParseInt62: " << Str << " = " << result << std::endl;
return result;
Expand Down
2 changes: 2 additions & 0 deletions src/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ namespace bms_parser
// bpmTable
std::unordered_map<int, double> BpmTable;
std::unordered_map<int, double> StopLengthTable;
std::unordered_map<int, double> ScrollTable;

bool UseBase62 = false;
int Lnobj = -1;
int Lntype = 1;
Expand Down
5 changes: 5 additions & 0 deletions test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ int main()
auto out = std::stoi(line.substr(6));
ASSERT_EQ(out, chart->Meta.Rank, "rank: ");
}
else if (line.rfind(L"playlength: ", 0) == 0)
{
auto out = std::stoi(line.substr(11));
ASSERT_EQ(out, chart->Meta.PlayLength, "playlength: ");
}
}
delete chart;
std::cout << "\tPass" << std::endl;
Expand Down
Loading

0 comments on commit b792138

Please sign in to comment.