Fix code quality and null handling

This commit is contained in:
Dean Herbert 2024-06-06 23:59:15 +08:00
parent 860afb8123
commit dd3f4bcdab
No known key found for this signature in database
5 changed files with 10 additions and 11 deletions

View File

@ -124,7 +124,9 @@ public void SetContent(DifficultyIconTooltipContent content)
difficultyFillFlowContainer.Show();
miscFillFlowContainer.Show();
double rate = ModUtils.CalculateRateWithMods(displayedContent.Mods);
double rate = 1;
if (displayedContent.Mods != null)
rate = ModUtils.CalculateRateWithMods(displayedContent.Mods);
double bpmAdjusted = displayedContent.BeatmapInfo.BPM * rate;

View File

@ -1,13 +1,11 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using Humanizer;
using Humanizer.Localisation;
using osu.Framework.Bindables;
using osu.Game.Rulesets.Mods;
using osu.Game.Utils;
namespace osu.Game.Online.Rooms
@ -48,7 +46,7 @@ public static string GetTotalDuration(this BindableList<PlaylistItem> playlist)
playlist.Select(p =>
{
var ruleset = p.Beatmap.Ruleset.CreateInstance();
double rate = ModUtils.CalculateRateWithMods(p.RequiredMods.Select(mod => mod.ToMod(ruleset)).ToList());
double rate = ModUtils.CalculateRateWithMods(p.RequiredMods.Select(mod => mod.ToMod(ruleset)));
return p.Beatmap.Length / rate;
}).Sum().Milliseconds().Humanize(minUnit: TimeUnit.Second, maxUnit: TimeUnit.Hour, precision: 2);
}

View File

@ -165,7 +165,7 @@ private void updateValues() => Scheduler.AddOnce(() =>
starRatingDisplay.FinishTransforms(true);
});
double rate = ModUtils.CalculateRateWithMods(Mods.Value.ToList());
double rate = ModUtils.CalculateRateWithMods(Mods.Value);
bpmDisplay.Current.Value = FormatUtils.RoundBPM(BeatmapInfo.Value.BPM, rate);

View File

@ -402,7 +402,7 @@ private void refreshBPMAndLengthLabel()
return;
// this doesn't consider mods which apply variable rates, yet.
double rate = ModUtils.CalculateRateWithMods(mods.Value.ToList());
double rate = ModUtils.CalculateRateWithMods(mods.Value);
int bpmMax = FormatUtils.RoundBPM(beatmap.ControlPointInfo.BPMMaximum, rate);
int bpmMin = FormatUtils.RoundBPM(beatmap.ControlPointInfo.BPMMinimum, rate);

View File

@ -285,11 +285,10 @@ public static LocalisableString FormatScoreMultiplier(double scoreMultiplier)
public static double CalculateRateWithMods(IEnumerable<Mod> mods)
{
double rate = 1;
if (mods != null)
{
foreach (var mod in mods.OfType<IApplicableToRate>())
rate = mod.ApplyToRate(0, rate);
}
foreach (var mod in mods.OfType<IApplicableToRate>())
rate = mod.ApplyToRate(0, rate);
return rate;
}
}