Skip to content

Commit

Permalink
Merge pull request #14918 from peppy/beatmap-difficulty-more-interfac…
Browse files Browse the repository at this point in the history
…e-usage

Convert usages of `BeatmapDifficulty` to `IBeatmapDifficultyInfo`
  • Loading branch information
smoogipoo authored Oct 6, 2021
2 parents 13bea78 + ffbb7a9 commit 5eb4210
Show file tree
Hide file tree
Showing 28 changed files with 61 additions and 40 deletions.
4 changes: 2 additions & 2 deletions osu.Game.Rulesets.Catch.Tests/TestSceneCatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,15 @@ public class TestCatcher : Catcher
{
public IEnumerable<CaughtObject> CaughtObjects => this.ChildrenOfType<CaughtObject>();

public TestCatcher(DroppedObjectContainer droppedObjectTarget, BeatmapDifficulty difficulty)
public TestCatcher(DroppedObjectContainer droppedObjectTarget, IBeatmapDifficultyInfo difficulty)
: base(droppedObjectTarget, difficulty)
{
}
}

public class TestKiaiFruit : Fruit
{
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, IBeatmapDifficultyInfo difficulty)
{
controlPointInfo.Add(0, new EffectControlPoint { KiaiMode = true });
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
Expand Down
4 changes: 2 additions & 2 deletions osu.Game.Rulesets.Catch.Tests/TestSceneCatcherArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class TestSceneCatcherArea : CatchSkinnableTestScene

private ScheduledDelegate addManyFruit;

private BeatmapDifficulty beatmapDifficulty;
private IBeatmapDifficultyInfo beatmapDifficulty;

public TestSceneCatcherArea()
{
Expand Down Expand Up @@ -120,7 +120,7 @@ private void load(RulesetStore rulesets)

private class TestCatcherArea : CatcherArea
{
public TestCatcherArea(BeatmapDifficulty beatmapDifficulty)
public TestCatcherArea(IBeatmapDifficultyInfo beatmapDifficulty)
{
var droppedObjectContainer = new DroppedObjectContainer();
Add(droppedObjectContainer);
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Catch/Edit/CatchEditorPlayfield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace osu.Game.Rulesets.Catch.Edit
public class CatchEditorPlayfield : CatchPlayfield
{
// TODO fixme: the size of the catcher is not changed when circle size is changed in setup screen.
public CatchEditorPlayfield(BeatmapDifficulty difficulty)
public CatchEditorPlayfield(IBeatmapDifficultyInfo difficulty)
: base(difficulty)
{
}
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Catch/Objects/CatchHitObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public float Scale
/// </summary>
public int RandomSeed => (int)StartTime;

protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, IBeatmapDifficultyInfo difficulty)
{
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);

Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Catch/Objects/JuiceStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class JuiceStream : CatchHitObject, IHasPathWithRepeats
/// </summary>
public double SpanDuration => Duration / this.SpanCount();

protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, IBeatmapDifficultyInfo difficulty)
{
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);

Expand Down
4 changes: 2 additions & 2 deletions osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) =>

internal CatcherArea CatcherArea { get; private set; }

private readonly BeatmapDifficulty difficulty;
private readonly IBeatmapDifficultyInfo difficulty;

public CatchPlayfield(BeatmapDifficulty difficulty)
public CatchPlayfield(IBeatmapDifficultyInfo difficulty)
{
this.difficulty = difficulty;
}
Expand Down
6 changes: 3 additions & 3 deletions osu.Game.Rulesets.Catch/UI/Catcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public CatcherAnimationState CurrentState
private readonly DrawablePool<CaughtBanana> caughtBananaPool;
private readonly DrawablePool<CaughtDroplet> caughtDropletPool;

public Catcher([NotNull] DroppedObjectContainer droppedObjectTarget, BeatmapDifficulty difficulty = null)
public Catcher([NotNull] DroppedObjectContainer droppedObjectTarget, IBeatmapDifficultyInfo difficulty = null)
{
this.droppedObjectTarget = droppedObjectTarget;

Expand Down Expand Up @@ -172,7 +172,7 @@ private void load(OsuConfigManager config)
/// <summary>
/// Calculates the scale of the catcher based off the provided beatmap difficulty.
/// </summary>
private static Vector2 calculateScale(BeatmapDifficulty difficulty) => new Vector2(1.0f - 0.7f * (difficulty.CircleSize - 5) / 5);
private static Vector2 calculateScale(IBeatmapDifficultyInfo difficulty) => new Vector2(1.0f - 0.7f * (difficulty.CircleSize - 5) / 5);

/// <summary>
/// Calculates the width of the area used for attempting catches in gameplay.
Expand All @@ -184,7 +184,7 @@ private void load(OsuConfigManager config)
/// Calculates the width of the area used for attempting catches in gameplay.
/// </summary>
/// <param name="difficulty">The beatmap difficulty.</param>
public static float CalculateCatchWidth(BeatmapDifficulty difficulty) => CalculateCatchWidth(calculateScale(difficulty));
public static float CalculateCatchWidth(IBeatmapDifficultyInfo difficulty) => CalculateCatchWidth(calculateScale(difficulty));

/// <summary>
/// Determine if this catcher can catch a <see cref="CatchHitObject"/> in the current position.
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Mania/Beatmaps/ManiaBeatmapConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static int GetColumnCountForNonConvert(BeatmapInfo beatmapInfo)

protected override Beatmap<ManiaHitObject> ConvertBeatmap(IBeatmap original, CancellationToken cancellationToken)
{
BeatmapDifficulty difficulty = original.BeatmapInfo.BaseDifficulty;
IBeatmapDifficultyInfo difficulty = original.BeatmapInfo.BaseDifficulty;

int seed = (int)MathF.Round(difficulty.DrainRate + difficulty.CircleSize) * 20 + (int)(difficulty.OverallDifficulty * 41.2) + (int)MathF.Round(difficulty.ApproachRate);
Random = new FastRandom(seed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected double ConversionDifficulty
if (drainTime == 0)
drainTime = 10000;

BeatmapDifficulty difficulty = OriginalBeatmap.BeatmapInfo.BaseDifficulty;
IBeatmapDifficultyInfo difficulty = OriginalBeatmap.BeatmapInfo.BaseDifficulty;
conversionDifficulty = ((difficulty.DrainRate + Math.Clamp(difficulty.ApproachRate, 4, 7)) / 1.5 + (double)OriginalBeatmap.HitObjects.Count / drainTime * 9f) / 38f * 5f / 1.15;
conversionDifficulty = Math.Min(conversionDifficulty.Value, 12);

Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Mania/Objects/HoldNote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public override int Column
/// </summary>
private double tickSpacing = 50;

protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, IBeatmapDifficultyInfo difficulty)
{
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor.Checks
public class CheckTooShortSpinnersTest
{
private CheckTooShortSpinners check;
private BeatmapDifficulty difficulty;
private IBeatmapDifficultyInfo difficulty;

[SetUp]
public void Setup()
Expand Down Expand Up @@ -81,33 +81,33 @@ public void TestTooShortSpinnerVaryingOd()
assertTooShort(new List<HitObject> { spinnerHighOd }, difficultyHighOd);
}

private void assertOk(List<HitObject> hitObjects, BeatmapDifficulty beatmapDifficulty)
private void assertOk(List<HitObject> hitObjects, IBeatmapDifficultyInfo beatmapDifficulty)
{
Assert.That(check.Run(getContext(hitObjects, beatmapDifficulty)), Is.Empty);
}

private void assertVeryShort(List<HitObject> hitObjects, BeatmapDifficulty beatmapDifficulty)
private void assertVeryShort(List<HitObject> hitObjects, IBeatmapDifficultyInfo beatmapDifficulty)
{
var issues = check.Run(getContext(hitObjects, beatmapDifficulty)).ToList();

Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.First().Template is CheckTooShortSpinners.IssueTemplateVeryShort);
}

private void assertTooShort(List<HitObject> hitObjects, BeatmapDifficulty beatmapDifficulty)
private void assertTooShort(List<HitObject> hitObjects, IBeatmapDifficultyInfo beatmapDifficulty)
{
var issues = check.Run(getContext(hitObjects, beatmapDifficulty)).ToList();

Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.First().Template is CheckTooShortSpinners.IssueTemplateTooShort);
}

private BeatmapVerifierContext getContext(List<HitObject> hitObjects, BeatmapDifficulty beatmapDifficulty)
private BeatmapVerifierContext getContext(List<HitObject> hitObjects, IBeatmapDifficultyInfo beatmapDifficulty)
{
var beatmap = new Beatmap<HitObject>
{
HitObjects = hitObjects,
BeatmapInfo = new BeatmapInfo { BaseDifficulty = beatmapDifficulty }
BeatmapInfo = new BeatmapInfo { BaseDifficulty = new BeatmapDifficulty(beatmapDifficulty) }
};

return new BeatmapVerifierContext(beatmap, new TestWorkingBeatmap(beatmap));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ public TestSlider()

private class TestSpinner : Spinner
{
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, IBeatmapDifficultyInfo difficulty)
{
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
SpinsRequired = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public TestSlider()

private class TestSpinner : Spinner
{
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, IBeatmapDifficultyInfo difficulty)
{
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
SpinsRequired = 1;
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void ApplyToHealthProcessor(HealthProcessor healthProcessor)

#region Reduce AR (IApplicableToDifficulty)

public void ReadFromDifficulty(BeatmapDifficulty difficulty)
public void ReadFromDifficulty(IBeatmapDifficultyInfo difficulty)
{
}

Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ protected OsuHitObject()
});
}

protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, IBeatmapDifficultyInfo difficulty)
{
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);

Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Osu/Objects/Slider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public Slider()
Path.Version.ValueChanged += _ => updateNestedPositions();
}

protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, IBeatmapDifficultyInfo difficulty)
{
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);

Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Osu/Objects/SliderEndCircle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected SliderEndCircle(Slider slider)

public double SpanDuration => slider.SpanDuration;

protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, IBeatmapDifficultyInfo difficulty)
{
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);

Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Osu/Objects/SliderTick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class SliderTick : OsuHitObject
public int SpanIndex { get; set; }
public double SpanStartTime { get; set; }

protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, IBeatmapDifficultyInfo difficulty)
{
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);

Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Osu/Objects/Spinner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public double EndTime
/// </summary>
public int MaximumBonusSpins { get; protected set; } = 1;

protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, IBeatmapDifficultyInfo difficulty)
{
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);

Expand Down
5 changes: 3 additions & 2 deletions osu.Game.Rulesets.Taiko/Beatmaps/TaikoBeatmapConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,10 @@ private bool shouldConvertSliderToHits(HitObject obj, IBeatmap beatmap, IHasDist

private class TaikoMutliplierAppliedDifficulty : BeatmapDifficulty
{
public TaikoMutliplierAppliedDifficulty(BeatmapDifficulty difficulty)
public TaikoMutliplierAppliedDifficulty(IBeatmapDifficultyInfo difficulty)
{
difficulty.CopyTo(this);
CopyFrom(difficulty);

SliderMultiplier *= LegacyBeatmapEncoder.LEGACY_TAIKO_VELOCITY_MULTIPLIER;
}
}
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Taiko/Objects/DrumRoll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public double EndTime

private float overallDifficulty = BeatmapDifficulty.DEFAULT_DIFFICULTY;

protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, IBeatmapDifficultyInfo difficulty)
{
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);

Expand Down
20 changes: 20 additions & 0 deletions osu.Game/Beatmaps/BeatmapDifficulty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ public class BeatmapDifficulty : IHasPrimaryKey, IBeatmapDifficultyInfo

private float? approachRate;

public BeatmapDifficulty()
{
}

public BeatmapDifficulty(IBeatmapDifficultyInfo source)
{
CopyFrom(source);
}

public float ApproachRate
{
get => approachRate ?? OverallDifficulty;
Expand All @@ -39,6 +48,17 @@ public BeatmapDifficulty Clone()
return diff;
}

public void CopyFrom(IBeatmapDifficultyInfo difficulty)
{
ApproachRate = difficulty.ApproachRate;
DrainRate = difficulty.DrainRate;
CircleSize = difficulty.CircleSize;
OverallDifficulty = difficulty.OverallDifficulty;

SliderMultiplier = difficulty.SliderMultiplier;
SliderTickRate = difficulty.SliderTickRate;
}

public void CopyTo(BeatmapDifficulty difficulty)
{
difficulty.ApproachRate = ApproachRate;
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Rulesets/Edit/PlacementBlueprint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public virtual void UpdateTimeAndPosition(SnapResult result)
}

/// <summary>
/// Invokes <see cref="Objects.HitObject.ApplyDefaults(ControlPointInfo,BeatmapDifficulty, CancellationToken)"/>,
/// Invokes <see cref="Objects.HitObject.ApplyDefaults(ControlPointInfo,IBeatmapDifficultyInfo,CancellationToken)"/>,
/// refreshing <see cref="Objects.HitObject.NestedHitObjects"/> and parameters for the <see cref="HitObject"/>.
/// </summary>
protected void ApplyDefaultsToHitObject() => HitObject.ApplyDefaults(beatmap.ControlPointInfo, beatmap.BeatmapInfo.BaseDifficulty);
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Rulesets/Mods/ModDifficultyAdjust.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public override string SettingDescription
}
}

public void ReadFromDifficulty(BeatmapDifficulty difficulty)
public void ReadFromDifficulty(IBeatmapDifficultyInfo difficulty)
{
}

Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Rulesets/Mods/ModHardRock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public abstract class ModHardRock : Mod, IApplicableToDifficulty
public override string Description => "Everything just got a bit harder...";
public override Type[] IncompatibleMods => new[] { typeof(ModEasy), typeof(ModDifficultyAdjust) };

public void ReadFromDifficulty(BeatmapDifficulty difficulty)
public void ReadFromDifficulty(IBeatmapDifficultyInfo difficulty)
{
}

Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Rulesets/Objects/HitObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public HitObject()
/// <param name="controlPointInfo">The control points.</param>
/// <param name="difficulty">The difficulty settings to use.</param>
/// <param name="cancellationToken">The cancellation token.</param>
public void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty, CancellationToken cancellationToken = default)
public void ApplyDefaults(ControlPointInfo controlPointInfo, IBeatmapDifficultyInfo difficulty, CancellationToken cancellationToken = default)
{
ApplyDefaultsToSelf(controlPointInfo, difficulty);

Expand Down Expand Up @@ -142,7 +142,7 @@ public void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty d
DefaultsApplied?.Invoke(this);
}

protected virtual void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
protected virtual void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, IBeatmapDifficultyInfo difficulty)
{
Kiai = controlPointInfo.EffectPointAt(StartTime + control_point_leniency).KiaiMode;

Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Rulesets/Objects/Legacy/ConvertSlider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public double Duration

public double Velocity = 1;

protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, IBeatmapDifficultyInfo difficulty)
{
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);

Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Screens/Select/Details/AdvancedStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ private void modsChanged(ValueChangedEvent<IReadOnlyList<Mod>> mods)

private void updateStatistics()
{
BeatmapDifficulty baseDifficulty = BeatmapInfo?.BaseDifficulty;
IBeatmapDifficultyInfo baseDifficulty = BeatmapInfo?.BaseDifficulty;
BeatmapDifficulty adjustedDifficulty = null;

if (baseDifficulty != null && mods.Value.Any(m => m is IApplicableToDifficulty))
{
adjustedDifficulty = baseDifficulty.Clone();
adjustedDifficulty = new BeatmapDifficulty(baseDifficulty);

foreach (var mod in mods.Value.OfType<IApplicableToDifficulty>())
mod.ApplyToDifficulty(adjustedDifficulty);
Expand Down

0 comments on commit 5eb4210

Please sign in to comment.