mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 14:46:38 +09:00
Make DifficultyCalculator support mod applications
Fixes https://github.com/ppy/osu/issues/476.
This commit is contained in:
@ -3,6 +3,10 @@
|
||||
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Framework.Timing;
|
||||
using System.Linq;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
|
||||
namespace osu.Game.Beatmaps
|
||||
{
|
||||
@ -10,41 +14,44 @@ namespace osu.Game.Beatmaps
|
||||
{
|
||||
protected double TimeRate = 1;
|
||||
|
||||
protected abstract double CalculateInternal(Dictionary<string, string> categoryDifficulty);
|
||||
|
||||
private void loadTiming()
|
||||
{
|
||||
// TODO: Handle mods
|
||||
const int audio_rate = 100;
|
||||
TimeRate = audio_rate / 100.0;
|
||||
}
|
||||
|
||||
public double Calculate(Dictionary<string, string> categoryDifficulty = null)
|
||||
{
|
||||
loadTiming();
|
||||
double difficulty = CalculateInternal(categoryDifficulty);
|
||||
return difficulty;
|
||||
}
|
||||
public abstract double Calculate(Dictionary<string, string> categoryDifficulty = null);
|
||||
}
|
||||
|
||||
public abstract class DifficultyCalculator<T> : DifficultyCalculator where T : HitObject
|
||||
{
|
||||
protected readonly Beatmap Beatmap;
|
||||
protected readonly Mod[] Mods;
|
||||
|
||||
protected List<T> Objects;
|
||||
|
||||
protected DifficultyCalculator(Beatmap beatmap)
|
||||
: this(beatmap, null)
|
||||
{
|
||||
}
|
||||
|
||||
protected DifficultyCalculator(Beatmap beatmap, Mod[] mods)
|
||||
{
|
||||
Beatmap = beatmap;
|
||||
Mods = mods ?? new Mod[0];
|
||||
|
||||
Objects = CreateBeatmapConverter().Convert(beatmap).HitObjects;
|
||||
|
||||
foreach (var h in Objects)
|
||||
h.ApplyDefaults(beatmap.ControlPointInfo, beatmap.BeatmapInfo.BaseDifficulty);
|
||||
|
||||
ApplyMods(mods);
|
||||
|
||||
PreprocessHitObjects();
|
||||
}
|
||||
|
||||
protected virtual void ApplyMods(Mod[] mods)
|
||||
{
|
||||
var clock = new StopwatchClock();
|
||||
mods.OfType<IApplicableToClock>().ForEach(m => m.ApplyToClock(clock));
|
||||
|
||||
TimeRate = clock.Rate;
|
||||
}
|
||||
|
||||
protected virtual void PreprocessHitObjects()
|
||||
{
|
||||
}
|
||||
|
Reference in New Issue
Block a user