// Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE 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 { public abstract class DifficultyCalculator { protected double TimeRate = 1; public abstract double Calculate(Dictionary categoryDifficulty = null); } public abstract class DifficultyCalculator : DifficultyCalculator where T : HitObject { protected readonly Beatmap Beatmap; protected readonly Mod[] Mods; protected DifficultyCalculator(Beatmap beatmap, Mod[] mods = null) { Beatmap = CreateBeatmapConverter(beatmap).Convert(beatmap); Mods = mods ?? new Mod[0]; ApplyMods(Mods); PreprocessHitObjects(); } protected virtual void ApplyMods(Mod[] mods) { var clock = new StopwatchClock(); mods.OfType().ForEach(m => m.ApplyToClock(clock)); TimeRate = clock.Rate; foreach (var mod in Mods.OfType()) mod.ApplyToDifficulty(Beatmap.BeatmapInfo.BaseDifficulty); foreach (var h in Beatmap.HitObjects) h.ApplyDefaults(Beatmap.ControlPointInfo, Beatmap.BeatmapInfo.BaseDifficulty); foreach (var mod in mods.OfType>()) foreach (var obj in Beatmap.HitObjects) mod.ApplyToHitObject(obj); } protected virtual void PreprocessHitObjects() { } protected abstract BeatmapConverter CreateBeatmapConverter(Beatmap beatmap); } }