mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 10:07:52 +08:00
Creating method in ModUtils to calculate the rate for the song
This commit is contained in:
parent
7dd18a84f6
commit
860afb8123
@ -13,6 +13,7 @@ using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Utils;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Beatmaps.Drawables
|
||||
@ -123,13 +124,7 @@ namespace osu.Game.Beatmaps.Drawables
|
||||
difficultyFillFlowContainer.Show();
|
||||
miscFillFlowContainer.Show();
|
||||
|
||||
double rate = 1;
|
||||
|
||||
if (displayedContent.Mods != null)
|
||||
{
|
||||
foreach (var mod in displayedContent.Mods.OfType<IApplicableToRate>())
|
||||
rate = mod.ApplyToRate(0, rate);
|
||||
}
|
||||
double rate = ModUtils.CalculateRateWithMods(displayedContent.Mods);
|
||||
|
||||
double bpmAdjusted = displayedContent.BeatmapInfo.BPM * rate;
|
||||
|
||||
|
@ -8,6 +8,7 @@ using Humanizer;
|
||||
using Humanizer.Localisation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Utils;
|
||||
|
||||
namespace osu.Game.Online.Rooms
|
||||
{
|
||||
@ -40,17 +41,14 @@ namespace osu.Game.Online.Rooms
|
||||
: GetUpcomingItems(playlist).First();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the total duration from the <see cref="PlaylistItem"/> in playlist order from the supplied <paramref name="playlist"/>,
|
||||
/// </summary>
|
||||
public static string GetTotalDuration(this BindableList<PlaylistItem> playlist) =>
|
||||
playlist.Select(p =>
|
||||
{
|
||||
var ruleset = p.Beatmap.Ruleset.CreateInstance();
|
||||
double rate = 1;
|
||||
if (p.RequiredMods.Count() > 0)
|
||||
{
|
||||
List<Mod> mods = p.RequiredMods.Select(mod => mod.ToMod(ruleset)).ToList();
|
||||
foreach (var mod in mods.OfType<IApplicableToRate>())
|
||||
rate = mod.ApplyToRate(0, rate);
|
||||
}
|
||||
double rate = ModUtils.CalculateRateWithMods(p.RequiredMods.Select(mod => mod.ToMod(ruleset)).ToList());
|
||||
return p.Beatmap.Length / rate;
|
||||
}).Sum().Milliseconds().Humanize(minUnit: TimeUnit.Second, maxUnit: TimeUnit.Hour, precision: 2);
|
||||
}
|
||||
|
@ -165,9 +165,7 @@ namespace osu.Game.Overlays.Mods
|
||||
starRatingDisplay.FinishTransforms(true);
|
||||
});
|
||||
|
||||
double rate = 1;
|
||||
foreach (var mod in Mods.Value.OfType<IApplicableToRate>())
|
||||
rate = mod.ApplyToRate(0, rate);
|
||||
double rate = ModUtils.CalculateRateWithMods(Mods.Value.ToList());
|
||||
|
||||
bpmDisplay.Current.Value = FormatUtils.RoundBPM(BeatmapInfo.Value.BPM, rate);
|
||||
|
||||
|
@ -402,9 +402,7 @@ namespace osu.Game.Screens.Select
|
||||
return;
|
||||
|
||||
// this doesn't consider mods which apply variable rates, yet.
|
||||
double rate = 1;
|
||||
foreach (var mod in mods.Value.OfType<IApplicableToRate>())
|
||||
rate = mod.ApplyToRate(0, rate);
|
||||
double rate = ModUtils.CalculateRateWithMods(mods.Value.ToList());
|
||||
|
||||
int bpmMax = FormatUtils.RoundBPM(beatmap.ControlPointInfo.BPMMaximum, rate);
|
||||
int bpmMin = FormatUtils.RoundBPM(beatmap.ControlPointInfo.BPMMinimum, rate);
|
||||
|
@ -27,6 +27,7 @@ using osu.Game.Configuration;
|
||||
using osu.Game.Resources.Localisation.Web;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Overlays.Mods;
|
||||
using osu.Game.Utils;
|
||||
|
||||
namespace osu.Game.Screens.Select.Details
|
||||
{
|
||||
@ -179,9 +180,7 @@ namespace osu.Game.Screens.Select.Details
|
||||
|
||||
if (Ruleset.Value != null)
|
||||
{
|
||||
double rate = 1;
|
||||
foreach (var mod in mods.Value.OfType<IApplicableToRate>())
|
||||
rate = mod.ApplyToRate(0, rate);
|
||||
double rate = ModUtils.CalculateRateWithMods(mods.Value);
|
||||
|
||||
adjustedDifficulty = Ruleset.Value.CreateInstance().GetRateAdjustedDisplayDifficulty(originalDifficulty, rate);
|
||||
|
||||
|
@ -276,5 +276,21 @@ namespace osu.Game.Utils
|
||||
|
||||
return scoreMultiplier.ToLocalisableString("0.00x");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the rate for the song with the selected mods.
|
||||
/// </summary>
|
||||
/// <param name="mods">The list of selected mods.</param>
|
||||
/// <returns>The rate with mods.</returns>
|
||||
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);
|
||||
}
|
||||
return rate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user