Skip to content

Commit

Permalink
Misc: Automatically use correct overload if applicable in pp calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotrekol committed Aug 13, 2020
1 parent 2e86550 commit ffa93db
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions PpCalculator/PpCalculator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using osu.Game.Beatmaps;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Difficulty;
using osu.Game.Rulesets.Mods;
Expand Down Expand Up @@ -59,6 +59,10 @@ public void PreProcess(ProcessorWorkingBeatmap workingBeatmap)

public double Calculate(double startTime, double endTime = double.NaN, Dictionary<string, double> categoryAttribs = null)
{
if (double.IsNaN(startTime) || startTime <= 0d)
{
return Calculate(endTime, categoryAttribs);
}

var orginalWorkingBeatmap = WorkingBeatmap;
var tempMap = new Beatmap();
Expand All @@ -80,7 +84,7 @@ public double Calculate(double startTime, double endTime = double.NaN, Dictionar
return result;
}

public double Calculate(double? time = null, Dictionary<string, double> categoryAttribs = null)
public double Calculate(double? endTime = null, Dictionary<string, double> categoryAttribs = null)
{
if (WorkingBeatmap == null)
return -1d;
Expand All @@ -104,8 +108,8 @@ public double Calculate(double? time = null, Dictionary<string, double> category
createPerformanceCalculator = true;
}

IReadOnlyList<HitObject> hitObjects = time.HasValue
? PlayableBeatmap.HitObjects.Where(h => h.StartTime <= time).ToList()
IReadOnlyList<HitObject> hitObjects = endTime.HasValue
? PlayableBeatmap.HitObjects.Where(h => h.StartTime <= endTime).ToList()
: PlayableBeatmap.HitObjects;

int beatmapMaxCombo = GetMaxCombo(hitObjects);
Expand All @@ -128,23 +132,16 @@ public double Calculate(double? time = null, Dictionary<string, double> category
ResetPerformanceCalculator = false;
}

double pp;

if (time.HasValue)
pp = PerformanceCalculator.Calculate(time.Value, categoryAttribs);
else
try
{
try
{
pp = PerformanceCalculator.Calculate(categoryAttribs);
}
catch (InvalidOperationException)
{
pp = -1;
}
return endTime.HasValue
? PerformanceCalculator.Calculate(endTime.Value, categoryAttribs)
: PerformanceCalculator.Calculate(categoryAttribs);
}
catch (InvalidOperationException)
{
return -1;
}

return pp;
}


Expand Down

0 comments on commit ffa93db

Please sign in to comment.