mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 20:13:22 +08:00
Fix and refactor star difficulty calculation boilerplate
Moves star difficulty calculation entry-point to Beatmap, and sets star difficulty at the correct place for song select to display.
This commit is contained in:
parent
edbd27210b
commit
f7d985fe18
@ -19,7 +19,7 @@ namespace osu.Game.Modes.Catch
|
||||
|
||||
protected override HitObjectConverter<CatchBaseHit> Converter => new CatchConverter();
|
||||
|
||||
protected override double ComputeDifficulty(Dictionary<String, String> categoryDifficulty)
|
||||
protected override double CalculateInternal(Dictionary<String, String> categoryDifficulty)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ namespace osu.Game.Modes.Mania
|
||||
|
||||
protected override HitObjectConverter<ManiaBaseHit> Converter => new ManiaConverter(columns);
|
||||
|
||||
protected override double ComputeDifficulty(Dictionary<String, String> categoryDifficulty)
|
||||
protected override double CalculateInternal(Dictionary<String, String> categoryDifficulty)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ namespace osu.Game.Modes.Osu
|
||||
((Slider)h).Curve.Calculate();
|
||||
}
|
||||
|
||||
protected override double ComputeDifficulty(Dictionary<String, String> categoryDifficulty)
|
||||
protected override double CalculateInternal(Dictionary<String, String> categoryDifficulty)
|
||||
{
|
||||
// Fill our custom DifficultyHitObject class, that carries additional information
|
||||
DifficultyHitObjects.Clear();
|
||||
|
@ -19,7 +19,7 @@ namespace osu.Game.Modes.Taiko
|
||||
|
||||
protected override HitObjectConverter<TaikoBaseHit> Converter => new TaikoConverter();
|
||||
|
||||
protected override double ComputeDifficulty(Dictionary<String, String> categoryDifficulty)
|
||||
protected override double CalculateInternal(Dictionary<String, String> categoryDifficulty)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ using OpenTK.Graphics;
|
||||
using osu.Game.Beatmaps.Timing;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Modes.Objects;
|
||||
using osu.Game.Modes;
|
||||
|
||||
namespace osu.Game.Beatmaps
|
||||
{
|
||||
@ -57,5 +58,7 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
return timingPoint ?? ControlPoint.Default;
|
||||
}
|
||||
|
||||
public double CalculateStarDifficulty() => Ruleset.GetRuleset(BeatmapInfo.Mode).CreateDifficultyCalculator(this).Calculate();
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
protected double TimeRate = 1;
|
||||
|
||||
protected abstract double ComputeDifficulty(Dictionary<String, String> categoryDifficulty);
|
||||
protected abstract double CalculateInternal(Dictionary<String, String> categoryDifficulty);
|
||||
|
||||
private void loadTiming()
|
||||
{
|
||||
@ -23,10 +23,10 @@ namespace osu.Game.Beatmaps
|
||||
TimeRate = audioRate / 100.0;
|
||||
}
|
||||
|
||||
public double GetDifficulty(Dictionary<string, string> categoryDifficulty = null)
|
||||
public double Calculate(Dictionary<string, string> categoryDifficulty = null)
|
||||
{
|
||||
loadTiming();
|
||||
double difficulty = ComputeDifficulty(categoryDifficulty);
|
||||
double difficulty = CalculateInternal(categoryDifficulty);
|
||||
return difficulty;
|
||||
}
|
||||
}
|
||||
|
@ -59,16 +59,21 @@ namespace osu.Game.Beatmaps.Drawables
|
||||
}
|
||||
}
|
||||
|
||||
public BeatmapGroup(WorkingBeatmap beatmap)
|
||||
public BeatmapGroup(BeatmapSetInfo beatmapSet, BeatmapDatabase database)
|
||||
{
|
||||
BeatmapSet = beatmapSet;
|
||||
WorkingBeatmap beatmap = database.GetWorkingBeatmap(BeatmapSet.Beatmaps.FirstOrDefault());
|
||||
foreach (var b in BeatmapSet.Beatmaps)
|
||||
b.StarDifficulty = (float)database.GetWorkingBeatmap(b).Beatmap.CalculateStarDifficulty();
|
||||
|
||||
Header = new BeatmapSetHeader(beatmap)
|
||||
{
|
||||
GainedSelection = headerGainedSelection,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
};
|
||||
|
||||
BeatmapSet = beatmap.BeatmapSetInfo;
|
||||
BeatmapPanels = beatmap.BeatmapSetInfo.Beatmaps.Select(b => new BeatmapPanel(b)
|
||||
|
||||
BeatmapSet.Beatmaps = BeatmapSet.Beatmaps.OrderBy(b => b.StarDifficulty).ToList();
|
||||
BeatmapPanels = BeatmapSet.Beatmaps.Select(b => new BeatmapPanel(b)
|
||||
{
|
||||
Alpha = 0,
|
||||
GainedSelection = panelGainedSelection,
|
||||
|
@ -73,7 +73,6 @@ namespace osu.Game.Database
|
||||
// Metadata
|
||||
public string Version { get; set; }
|
||||
|
||||
//todo: background threaded computation of this
|
||||
private float starDifficulty = -1;
|
||||
public float StarDifficulty
|
||||
{
|
||||
@ -85,11 +84,6 @@ namespace osu.Game.Database
|
||||
set { starDifficulty = value; }
|
||||
}
|
||||
|
||||
internal void ComputeDifficulty(BeatmapDatabase database)
|
||||
{
|
||||
StarDifficulty = (float)Ruleset.GetRuleset(Mode).CreateDifficultyCalculator(database.GetWorkingBeatmap(this).Beatmap).GetDifficulty();
|
||||
}
|
||||
|
||||
public bool Equals(BeatmapInfo other)
|
||||
{
|
||||
return ID == other?.ID;
|
||||
|
@ -325,11 +325,7 @@ namespace osu.Game.Screens.Select
|
||||
if (b.Metadata == null) b.Metadata = beatmapSet.Metadata;
|
||||
});
|
||||
|
||||
foreach (var b in beatmapSet.Beatmaps)
|
||||
b.ComputeDifficulty(database);
|
||||
beatmapSet.Beatmaps = beatmapSet.Beatmaps.OrderBy(b => b.StarDifficulty).ToList();
|
||||
|
||||
var group = new BeatmapGroup(database.GetWorkingBeatmap(beatmapSet.Beatmaps.FirstOrDefault()))
|
||||
var group = new BeatmapGroup(beatmapSet, database)
|
||||
{
|
||||
SelectionChanged = selectionChanged,
|
||||
StartRequested = b => footer.StartButton.TriggerClick()
|
||||
|
Loading…
Reference in New Issue
Block a user