Skip to content

Commit

Permalink
Fix spinners not loading and timing point judgement
Browse files Browse the repository at this point in the history
  • Loading branch information
Rian8337 committed Feb 26, 2021
1 parent 1f1a962 commit 39803a4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
<string name="app_run_code_error">Fatal error encountered</string>
<string name="osu_parser_error">The difficulty parsing error</string>
<string name="osu_parser_music_not_found" formatted="false">Failed loading %s: Could not find audio file</string>
<string name="osu_parser_timing_error" formatted="false">Failed loading %s: First timing point is inherited</string>
<string name="osu_parser_timing_error" formatted="false">Failed loading %s: No uninherited timing point found</string>
<string name="require_storage_permission">Game wont run without storage permission, please enable it manually</string>

<string name="update_dialog_title">New Version Available</string>
Expand Down
37 changes: 29 additions & 8 deletions src/ru/nsu/ccfit/zuev/osu/OSUParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,35 @@ private boolean loadEventsSection(final TrackInfo track) {
private boolean loadTimingPointsSection(final TrackInfo track) {
timingPoints.clear();

// Get the first uninherited timing point
for (final String tempString : data.getData("TimingPoints")) {
String[] rawData = tempString.split("[,]");
// Handle malformed timing point
if (rawData.length < 2) {
return false;
}
float bpm = tryParseFloat(rawData[1], Float.NaN);
if (Float.isNaN(bpm)) {
return false;
}

// Uninherited: bpm > 0
if (bpm > 0) {
float offset = tryParseFloat(rawData[0], Float.NaN);
if (Float.isNaN(offset)) {
return false;
}
currentTimingPoint = new TimingPoint(bpm, offset, 1f);
break;
}
}

if (currentTimingPoint == null) {
ToastLogger.showText(StringTable.format(R.string.osu_parser_timing_error,
file.getName().substring(0, file.getName().length() - 4)), true);
return false;
}

for (final String tempString : data.getData("TimingPoints")) {
String[] rawData = tempString.split("[,]");
// Handle malformed timing point
Expand All @@ -376,14 +405,6 @@ private boolean loadTimingPointsSection(final TrackInfo track) {
float speed = 1.0f;
boolean inherited = bpm < 0;

// The first timing point should always be uninherited,
// otherwise the beatmap is invalid
if (currentTimingPoint == null && inherited) {
ToastLogger.showText(StringTable.format(R.string.osu_parser_timing_error,
file.getName().substring(0, file.getName().length() - 4)), true);
return false;
}

if (inherited) {
speed = -100.0f / bpm;
bpm = currentTimingPoint.getBpm();
Expand Down
4 changes: 1 addition & 3 deletions src/test/tpdifficulty/hitobject/HitObjectType.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ public static HitObjectType valueOf(int value) {
return NormalNewCombo;
case 6:
return SliderNewCombo;
case 8:
return Spinner;
default:
return null;
return Spinner;
}
}

Expand Down

0 comments on commit 39803a4

Please sign in to comment.