2017-02-19 16:41:51 +00:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2017-04-18 07:05:58 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2017-02-19 16:41:51 +00:00
|
|
|
|
using System.Collections.Generic;
|
2017-11-16 11:06:32 +00:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
|
using osu.Framework.Timing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2017-02-19 16:41:51 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps
|
|
|
|
|
{
|
|
|
|
|
public abstract class DifficultyCalculator
|
|
|
|
|
{
|
|
|
|
|
protected double TimeRate = 1;
|
|
|
|
|
|
2017-11-21 10:54:53 +00:00
|
|
|
|
public abstract double Calculate(Dictionary<string, double> categoryDifficulty = null);
|
2017-02-19 16:41:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract class DifficultyCalculator<T> : DifficultyCalculator where T : HitObject
|
|
|
|
|
{
|
2017-11-17 05:23:52 +00:00
|
|
|
|
protected readonly Beatmap<T> Beatmap;
|
2017-11-16 11:06:32 +00:00
|
|
|
|
protected readonly Mod[] Mods;
|
2017-08-22 04:34:58 +00:00
|
|
|
|
|
2017-11-17 05:26:33 +00:00
|
|
|
|
protected DifficultyCalculator(Beatmap beatmap, Mod[] mods = null)
|
2017-02-19 16:41:51 +00:00
|
|
|
|
{
|
2017-11-17 05:37:06 +00:00
|
|
|
|
Beatmap = CreateBeatmapConverter(beatmap).Convert(beatmap);
|
2017-11-16 11:06:32 +00:00
|
|
|
|
Mods = mods ?? new Mod[0];
|
2017-08-22 04:34:58 +00:00
|
|
|
|
|
2017-04-26 06:50:08 +00:00
|
|
|
|
|
2017-11-17 03:35:03 +00:00
|
|
|
|
ApplyMods(Mods);
|
2017-11-16 11:06:32 +00:00
|
|
|
|
|
2017-02-19 16:41:51 +00:00
|
|
|
|
PreprocessHitObjects();
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-16 11:06:32 +00:00
|
|
|
|
protected virtual void ApplyMods(Mod[] mods)
|
|
|
|
|
{
|
|
|
|
|
var clock = new StopwatchClock();
|
|
|
|
|
mods.OfType<IApplicableToClock>().ForEach(m => m.ApplyToClock(clock));
|
2017-11-16 11:41:26 +00:00
|
|
|
|
TimeRate = clock.Rate;
|
2017-11-16 11:06:32 +00:00
|
|
|
|
|
2017-11-17 05:23:52 +00:00
|
|
|
|
foreach (var mod in Mods.OfType<IApplicableToDifficulty>())
|
|
|
|
|
mod.ApplyToDifficulty(Beatmap.BeatmapInfo.BaseDifficulty);
|
|
|
|
|
|
2017-11-16 11:35:57 +00:00
|
|
|
|
foreach (var mod in mods.OfType<IApplicableToHitObject<T>>())
|
2017-11-17 05:23:52 +00:00
|
|
|
|
foreach (var obj in Beatmap.HitObjects)
|
2017-11-16 11:35:57 +00:00
|
|
|
|
mod.ApplyToHitObject(obj);
|
2017-11-17 05:23:52 +00:00
|
|
|
|
|
|
|
|
|
foreach (var h in Beatmap.HitObjects)
|
|
|
|
|
h.ApplyDefaults(Beatmap.ControlPointInfo, Beatmap.BeatmapInfo.BaseDifficulty);
|
2017-11-16 11:06:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-19 16:41:51 +00:00
|
|
|
|
protected virtual void PreprocessHitObjects()
|
|
|
|
|
{
|
|
|
|
|
}
|
2017-03-12 05:32:50 +00:00
|
|
|
|
|
2017-11-17 05:37:06 +00:00
|
|
|
|
protected abstract BeatmapConverter<T> CreateBeatmapConverter(Beatmap beatmap);
|
2017-02-19 16:41:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|