mirror of
https://github.com/ppy/osu.git
synced 2026-05-27 07:09:54 +08:00
9727d95ad9
- Part of https://github.com/ppy/osu/issues/37818
During review, I would like to direct particular attention to the
following changes:
## [Migrate song select to new score multiplier
API](https://github.com/ppy/osu/commit/945fd78539da3ae57d1550a5bbfb0f859d153cc4)
This was a confusing change to write because of the way song selects
hook their mod overlays up to global bindables. In particular different
things happen in different circumstances.
- When going through `SongSelect.CreateModOverlay()`, which is called by
the base `SongSelect`, the mod overlay is automatically bound to global
bindables via `SongSelect.on{ArrivingAt,Leaving}Screen()`.
- For multiplayer user mod select overlays, which are bolted on by
subclasses of `SongSelect`, manual hook-up is required.
- As for free mod select overlays, they don't show mod multipliers at
all, and don't have easy access to the ruleset, and thus the hookup is
skipped entirely as redundant.
## [Fix score multiplier registrations being shared between
implementations via superclass static
fields](https://github.com/ppy/osu/commit/ba0a7ad421e0c84c2d8162b6bbdd3a0683f5a6a6)
Revealed by `ScoreMultiplierCalculatorTest` starting to fail due to
interference from `OsuScoreMultiplierCalculator`.
It's not ideal from a performance standpoint but it's the simplest
choice for now. Tricks could be pulled to salvage the static. One is
```csharp
public class ScoreMultiplierCalculator<T>
where T : ScoreMultiplierCalculator<T>
{
}
```
This works because of generics internals; static instance members are
not shared between different specialisations of a generic class. It is
also very unintuitive, so I would rather not. (It trips a ReSharper
inspection too, which would have to be silenced.)
From a performance standpoint this is not ideal, but a significant chunk
of migrated usages already precede the construction of the calculator
via the known-expensive `RulesetInfo.CreateInstance()`, and the paths
that actually construct the calculator do not appear to be that hot. If
need be, this can be handled by actually caching ruleset instances and
their derivative subcomponents.
## [Introduce passing of context to score multiplier
calculator](https://github.com/ppy/osu/pull/37845/changes/9e9242b3221dddacd226f4b3b9c5632d7350e998)
This is required for two reasons:
- The upcoming mod rebalance will require out-of-band supplementary
information that is not available for reading from the mod instances
themselves for calculating the multiplier.
- This context, namely passing of `ScoreInfo`, will be used for
implementing backwards compatibility with old scores and their score
multipliers. This is required because it has turned out under inspection
that all server-side lazer replays recorded until now are missing
`TotalScoreWithoutMods` due to an omission of not sending it across the
wire to spectator server.
Because the score import flow uses replays, filtered through
`LegacyScoreDecoder`, to populate total score in the realm database, it
is basically impossible to ignore scores that are missing
`TotalScoreWithoutMods`, because that will result in bug reports that
the scores do not have the new score multipliers applied.
Thus, passing of `ScoreInfo` will facilitate implementation of
versioning score multipliers, which should result in less breakage than
not doing so.
An example of this is added in 341b2d6e55,
which should handle the case of mania mod multipliers having been
changed without any attempt to facilitate for it in
https://github.com/ppy/osu/pull/30506.
---------
Co-authored-by: Dean Herbert <pe@ppy.sh>
140 lines
6.7 KiB
C#
140 lines
6.7 KiB
C#
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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 NUnit.Framework;
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Testing;
|
|
using osu.Game.Graphics.Sprites;
|
|
using osu.Game.Overlays;
|
|
using osu.Game.Overlays.Mods;
|
|
using osu.Game.Rulesets;
|
|
using osu.Game.Rulesets.Mods;
|
|
using osu.Game.Rulesets.Osu;
|
|
using osu.Game.Rulesets.Osu.Mods;
|
|
using osu.Game.Rulesets.Scoring;
|
|
using osu.Game.Screens.Select;
|
|
using osu.Game.Utils;
|
|
|
|
namespace osu.Game.Tests.Visual.SongSelect
|
|
{
|
|
public partial class TestSceneFooterButtonMods : OsuTestScene
|
|
{
|
|
private readonly FooterButtonMods footerButtonMods;
|
|
|
|
[Cached]
|
|
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Aquamarine);
|
|
|
|
public TestSceneFooterButtonMods()
|
|
{
|
|
Add(footerButtonMods = new FooterButtonMods(new TestModSelectOverlay())
|
|
{
|
|
Anchor = Anchor.Centre,
|
|
Origin = Anchor.CentreLeft,
|
|
Action = () => { },
|
|
X = -100,
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public void TestDisplay()
|
|
{
|
|
AddStep("one mod", () => changeMods(new List<Mod> { new OsuModHidden() }));
|
|
AddStep("two mods", () => changeMods(new List<Mod> { new OsuModHidden(), new OsuModHardRock() }));
|
|
AddStep("three mods", () => changeMods(new List<Mod> { new OsuModHidden(), new OsuModHardRock(), new OsuModDoubleTime() }));
|
|
AddStep("four mods", () => changeMods(new List<Mod> { new OsuModHidden(), new OsuModHardRock(), new OsuModDoubleTime(), new OsuModClassic() }));
|
|
AddStep("five mods", () => changeMods(new List<Mod> { new OsuModHidden(), new OsuModHardRock(), new OsuModDoubleTime(), new OsuModClassic(), new OsuModDifficultyAdjust() }));
|
|
|
|
AddStep("modified", () => changeMods(new List<Mod> { new OsuModDoubleTime { SpeedChange = { Value = 1.2 } } }));
|
|
AddStep("modified + one", () => changeMods(new List<Mod> { new OsuModHidden(), new OsuModDoubleTime { SpeedChange = { Value = 1.2 } } }));
|
|
AddStep("modified + two", () => changeMods(new List<Mod> { new OsuModHidden(), new OsuModHardRock(), new OsuModDoubleTime { SpeedChange = { Value = 1.2 } } }));
|
|
AddStep("modified + five", () => changeMods(new List<Mod> { new OsuModHidden(), new OsuModHardRock(), new OsuModDoubleTime { SpeedChange = { Value = 1.2 } }, new OsuModClassic(), new OsuModDifficultyAdjust(), new OsuModRandom() }));
|
|
AddStep("modified + six", () => changeMods(new List<Mod> { new OsuModHidden(), new OsuModHardRock(), new OsuModDoubleTime { SpeedChange = { Value = 1.2 } }, new OsuModClassic(), new OsuModDifficultyAdjust(), new OsuModRandom(), new OsuModAlternate() }));
|
|
|
|
AddStep("clear mods", () => changeMods(Array.Empty<Mod>()));
|
|
AddWaitStep("wait", 3);
|
|
AddStep("one mod", () => changeMods(new List<Mod> { new OsuModHidden() }));
|
|
|
|
AddStep("clear mods", () => changeMods(Array.Empty<Mod>()));
|
|
AddWaitStep("wait", 3);
|
|
AddStep("five mods", () => changeMods(new List<Mod> { new OsuModHidden(), new OsuModHardRock(), new OsuModDoubleTime(), new OsuModClassic(), new OsuModDifficultyAdjust() }));
|
|
}
|
|
|
|
[Test]
|
|
public void TestIncrementMultiplier()
|
|
{
|
|
var ruleset = new OsuRuleset();
|
|
var hiddenMod = new Mod[] { new OsuModHidden() };
|
|
|
|
AddStep("Set ruleset", () => footerButtonMods.Ruleset.Value = ruleset.RulesetInfo);
|
|
|
|
AddStep(@"Add Hidden", () => changeMods(hiddenMod));
|
|
assertModsMultiplier(ruleset, hiddenMod);
|
|
|
|
var hardRockMod = new Mod[] { new OsuModHardRock() };
|
|
AddStep(@"Add HardRock", () => changeMods(hardRockMod));
|
|
assertModsMultiplier(ruleset, hardRockMod);
|
|
|
|
var doubleTimeMod = new Mod[] { new OsuModDoubleTime() };
|
|
AddStep(@"Add DoubleTime", () => changeMods(doubleTimeMod));
|
|
assertModsMultiplier(ruleset, doubleTimeMod);
|
|
|
|
var multipleIncrementMods = new Mod[] { new OsuModDoubleTime(), new OsuModHidden(), new OsuModHardRock() };
|
|
AddStep(@"Add multiple Mods", () => changeMods(multipleIncrementMods));
|
|
assertModsMultiplier(ruleset, multipleIncrementMods);
|
|
}
|
|
|
|
[Test]
|
|
public void TestDecrementMultiplier()
|
|
{
|
|
var ruleset = new OsuRuleset();
|
|
var easyMod = new Mod[] { new OsuModEasy() };
|
|
|
|
AddStep("Set ruleset", () => footerButtonMods.Ruleset.Value = ruleset.RulesetInfo);
|
|
|
|
AddStep(@"Add Easy", () => changeMods(easyMod));
|
|
assertModsMultiplier(ruleset, easyMod);
|
|
|
|
var noFailMod = new Mod[] { new OsuModNoFail() };
|
|
AddStep(@"Add NoFail", () => changeMods(noFailMod));
|
|
assertModsMultiplier(ruleset, noFailMod);
|
|
|
|
var multipleDecrementMods = new Mod[] { new OsuModEasy(), new OsuModNoFail() };
|
|
AddStep(@"Add Multiple Mods", () => changeMods(multipleDecrementMods));
|
|
assertModsMultiplier(ruleset, multipleDecrementMods);
|
|
}
|
|
|
|
[Test]
|
|
public void TestUnrankedBadge()
|
|
{
|
|
AddStep(@"Add unranked mod", () => changeMods(new[] { new OsuModDeflate() }));
|
|
AddUntilStep("Unranked badge shown", () => footerButtonMods.ChildrenOfType<FooterButtonMods.UnrankedBadge>().Single().Alpha == 1);
|
|
AddStep(@"Clear selected mod", () => changeMods(Array.Empty<Mod>()));
|
|
AddUntilStep("Unranked badge not shown", () => footerButtonMods.ChildrenOfType<FooterButtonMods.UnrankedBadge>().Single().Alpha == 0);
|
|
}
|
|
|
|
private void changeMods(IReadOnlyList<Mod> mods) => footerButtonMods.Mods.Value = mods;
|
|
|
|
private void assertModsMultiplier(Ruleset ruleset, IEnumerable<Mod> mods)
|
|
{
|
|
var scoreMultiplierCalculator = ruleset.CreateScoreMultiplierCalculator(new ScoreMultiplierContext());
|
|
double multiplier = scoreMultiplierCalculator.CalculateFor(mods);
|
|
string expectedValue = ModUtils.FormatScoreMultiplier(multiplier).ToString();
|
|
|
|
AddAssert($"Displayed multiplier is {expectedValue}", () => footerButtonMods.ChildrenOfType<OsuSpriteText>().First(t => t.Text.ToString().Contains('x')).Text.ToString(), () => Is.EqualTo(expectedValue));
|
|
}
|
|
|
|
private partial class TestModSelectOverlay : UserModSelectOverlay
|
|
{
|
|
public TestModSelectOverlay()
|
|
: base(OverlayColourScheme.Aquamarine)
|
|
{
|
|
ShowPresets = true;
|
|
}
|
|
}
|
|
}
|
|
}
|