-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30321 from smoogipoo/bat-mods
Make `BeatmapAttributeText` show values inclusive of mods
- Loading branch information
Showing
2 changed files
with
217 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,28 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Newtonsoft.Json; | ||
using NUnit.Framework; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Sprites; | ||
using osu.Framework.Localisation; | ||
using osu.Framework.Testing; | ||
using osu.Game.Beatmaps; | ||
using osu.Game.Configuration; | ||
using osu.Game.Models; | ||
using osu.Game.Rulesets; | ||
using osu.Game.Rulesets.Difficulty; | ||
using osu.Game.Rulesets.Difficulty.Preprocessing; | ||
using osu.Game.Rulesets.Difficulty.Skills; | ||
using osu.Game.Rulesets.Mods; | ||
using osu.Game.Rulesets.Osu; | ||
using osu.Game.Rulesets.Osu.Mods; | ||
using osu.Game.Rulesets.UI; | ||
using osu.Game.Scoring; | ||
using osu.Game.Skinning.Components; | ||
using osu.Game.Tests.Beatmaps; | ||
|
||
|
@@ -30,6 +44,8 @@ public TestSceneBeatmapAttributeText() | |
[SetUp] | ||
public void Setup() => Schedule(() => | ||
{ | ||
SelectedMods.SetDefault(); | ||
Ruleset.Value = new OsuRuleset().RulesetInfo; | ||
Beatmap.Value = CreateWorkingBeatmap(new TestBeatmap(new OsuRuleset().RulesetInfo) | ||
{ | ||
BeatmapInfo = | ||
|
@@ -93,6 +109,126 @@ public void TestChangeBeatmap() | |
AddAssert("check new title", getText, () => Is.EqualTo("Title: Another")); | ||
} | ||
|
||
[Test] | ||
public void TestWithMods() | ||
{ | ||
AddStep("set beatmap", () => Beatmap.Value = CreateWorkingBeatmap(new TestBeatmap(new OsuRuleset().RulesetInfo) | ||
{ | ||
BeatmapInfo = | ||
{ | ||
BPM = 100, | ||
Length = 30000, | ||
Difficulty = | ||
{ | ||
ApproachRate = 10, | ||
CircleSize = 9 | ||
} | ||
} | ||
})); | ||
|
||
test(BeatmapAttribute.BPM, new OsuModDoubleTime(), "BPM: 100.00", "BPM: 150.00"); | ||
test(BeatmapAttribute.Length, new OsuModDoubleTime(), "Length: 00:30", "Length: 00:20"); | ||
test(BeatmapAttribute.ApproachRate, new OsuModDoubleTime(), "Approach Rate: 10.00", "Approach Rate: 11.00"); | ||
test(BeatmapAttribute.CircleSize, new OsuModHardRock(), "Circle Size: 9.00", "Circle Size: 10.00"); | ||
|
||
void test(BeatmapAttribute attribute, Mod mod, string before, string after) | ||
{ | ||
AddStep($"set attribute: {attribute}", () => text.Attribute.Value = attribute); | ||
AddAssert("check text is correct", getText, () => Is.EqualTo(before)); | ||
|
||
AddStep("add DT mod", () => SelectedMods.Value = new[] { mod }); | ||
AddAssert("check text is correct", getText, () => Is.EqualTo(after)); | ||
AddStep("clear mods", () => SelectedMods.SetDefault()); | ||
} | ||
} | ||
|
||
[Test] | ||
public void TestStarRating() | ||
{ | ||
AddStep("set test ruleset", () => Ruleset.Value = new TestRuleset().RulesetInfo); | ||
AddStep("set star rating attribute", () => text.Attribute.Value = BeatmapAttribute.StarRating); | ||
AddAssert("check star rating is 0", getText, () => Is.EqualTo("Star Rating: 0.00")); | ||
|
||
// Adding mod | ||
TestMod mod = null!; | ||
AddStep("add mod with difficulty 1", () => SelectedMods.Value = new[] { mod = new TestMod { Difficulty = { Value = 1 } } }); | ||
AddUntilStep("check star rating is 1", getText, () => Is.EqualTo("Star Rating: 1.00")); | ||
|
||
// Changing mod setting | ||
AddStep("change mod difficulty to 2", () => mod.Difficulty.Value = 2); | ||
AddUntilStep("check star rating is 2", getText, () => Is.EqualTo("Star Rating: 2.00")); | ||
} | ||
|
||
private string getText() => text.ChildrenOfType<SpriteText>().Single().Text.ToString(); | ||
|
||
private class TestRuleset : Ruleset | ||
{ | ||
public override IEnumerable<Mod> GetModsFor(ModType type) => new[] | ||
{ | ||
new TestMod() | ||
}; | ||
|
||
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) | ||
=> new OsuRuleset().CreateBeatmapConverter(beatmap); | ||
|
||
public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) | ||
=> new TestDifficultyCalculator(new TestRuleset().RulesetInfo, beatmap); | ||
|
||
public override PerformanceCalculator CreatePerformanceCalculator() | ||
=> new TestPerformanceCalculator(new TestRuleset()); | ||
|
||
public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod>? mods = null) | ||
=> null!; | ||
|
||
public override string Description => string.Empty; | ||
public override string ShortName => string.Empty; | ||
} | ||
|
||
private class TestDifficultyCalculator : DifficultyCalculator | ||
{ | ||
public TestDifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap beatmap) | ||
: base(ruleset, beatmap) | ||
{ | ||
} | ||
|
||
protected override DifficultyAttributes CreateDifficultyAttributes(IBeatmap beatmap, Mod[] mods, Skill[] skills, double clockRate) | ||
=> new DifficultyAttributes(mods, mods.OfType<TestMod>().SingleOrDefault()?.Difficulty.Value ?? 0); | ||
|
||
protected override IEnumerable<DifficultyHitObject> CreateDifficultyHitObjects(IBeatmap beatmap, double clockRate) | ||
=> Array.Empty<DifficultyHitObject>(); | ||
|
||
protected override Skill[] CreateSkills(IBeatmap beatmap, Mod[] mods, double clockRate) | ||
=> Array.Empty<Skill>(); | ||
} | ||
|
||
private class TestPerformanceCalculator : PerformanceCalculator | ||
{ | ||
public TestPerformanceCalculator(Ruleset ruleset) | ||
: base(ruleset) | ||
{ | ||
} | ||
|
||
protected override PerformanceAttributes CreatePerformanceAttributes(ScoreInfo score, DifficultyAttributes attributes) | ||
=> new PerformanceAttributes { Total = score.Mods.OfType<TestMod>().SingleOrDefault()?.Performance.Value ?? 0 }; | ||
} | ||
|
||
private class TestMod : Mod | ||
{ | ||
[SettingSource("difficulty")] | ||
public BindableDouble Difficulty { get; } = new BindableDouble(0); | ||
|
||
[SettingSource("performance")] | ||
public BindableDouble Performance { get; } = new BindableDouble(0); | ||
|
||
[JsonConstructor] | ||
public TestMod() | ||
{ | ||
} | ||
|
||
public override string Name => string.Empty; | ||
public override LocalisableString Description => string.Empty; | ||
public override double ScoreMultiplier => 1.0; | ||
public override string Acronym => "Test"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters