-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalcWorkingBeatmap.cs
91 lines (74 loc) · 3.14 KB
/
CalcWorkingBeatmap.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using osu.Framework.Audio;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.UI;
using osu.Game.Storyboards;
using osu.Game.Tests.Beatmaps;
namespace diffcalc_comparer;
public class CalcWorkingBeatmap : TestWorkingBeatmap
{
private readonly Ruleset rulesetInstance;
public CalcWorkingBeatmap(Ruleset rulesetInstance, IBeatmap beatmap, Storyboard? storyboard = null, AudioManager? audioManager = null)
: base(beatmap, storyboard, audioManager)
{
this.rulesetInstance = rulesetInstance;
}
// Copied function from https://github.com/ppy/osu/blob/61bfd2f6b2a94d54b7b4cff574e34ad4c06eb457/osu.Game/Beatmaps/WorkingBeatmap.cs#L245
// but without ruleset instantiation.
public override IBeatmap GetPlayableBeatmap(IRulesetInfo ruleset, IReadOnlyList<Mod> mods, CancellationToken token)
{
var converter = CreateBeatmapConverter(Beatmap, rulesetInstance);
// Check if the beatmap can be converted
if (Beatmap.HitObjects.Count > 0 && !converter.CanConvert())
throw new BeatmapInvalidForRulesetException(
$"{nameof(Beatmap)} can not be converted for the ruleset (ruleset: {ruleset.InstantiationInfo}, converter: {converter}).");
// Apply conversion mods
foreach (var mod in mods.OfType<IApplicableToBeatmapConverter>())
{
token.ThrowIfCancellationRequested();
mod.ApplyToBeatmapConverter(converter);
}
// Convert
var converted = converter.Convert(token);
// Apply conversion mods to the result
foreach (var mod in mods.OfType<IApplicableAfterBeatmapConversion>())
{
token.ThrowIfCancellationRequested();
mod.ApplyToBeatmap(converted);
}
// Apply difficulty mods
if (mods.Any(m => m is IApplicableToDifficulty))
foreach (var mod in mods.OfType<IApplicableToDifficulty>())
{
token.ThrowIfCancellationRequested();
mod.ApplyToDifficulty(converted.Difficulty);
}
var processor = rulesetInstance.CreateBeatmapProcessor(converted);
if (processor != null)
{
foreach (var mod in mods.OfType<IApplicableToBeatmapProcessor>())
mod.ApplyToBeatmapProcessor(processor);
processor.PreProcess();
}
// Compute default values for hitobjects, including creating nested hitobjects in-case they're needed
foreach (var obj in converted.HitObjects)
{
token.ThrowIfCancellationRequested();
obj.ApplyDefaults(converted.ControlPointInfo, converted.Difficulty, token);
}
foreach (var mod in mods.OfType<IApplicableToHitObject>())
foreach (var obj in converted.HitObjects)
{
token.ThrowIfCancellationRequested();
mod.ApplyToHitObject(obj);
}
processor?.PostProcess();
foreach (var mod in mods.OfType<IApplicableToBeatmap>())
{
token.ThrowIfCancellationRequested();
mod.ApplyToBeatmap(converted);
}
return converted;
}
}