From 75b9d0fe6666eba914fc87f5428414d8003c3edf Mon Sep 17 00:00:00 2001 From: rushiiMachine <33725716+rushiiMachine@users.noreply.github.com> Date: Wed, 27 Dec 2023 23:02:45 -0800 Subject: [PATCH] Make flashlight scale with playfield When the playfield is shrunk with mods such as BarrelRoll, flashlight does not account for this, making it significantly easier to play. This makes it scale along with the playfield. --- .../Mods/TestSceneOsuModFlashlight.cs | 26 +++++++++++++++++++ osu.Game/Rulesets/Mods/ModFlashlight.cs | 13 +++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModFlashlight.cs b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModFlashlight.cs index a353914cd5..2438038951 100644 --- a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModFlashlight.cs +++ b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModFlashlight.cs @@ -1,8 +1,13 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Linq; using NUnit.Framework; +using osu.Framework.Utils; +using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Osu.Mods; +using osu.Game.Rulesets.Osu.Objects; +using osuTK; namespace osu.Game.Rulesets.Osu.Tests.Mods { @@ -21,5 +26,26 @@ namespace osu.Game.Rulesets.Osu.Tests.Mods [Test] public void TestComboBasedSize([Values] bool comboBasedSize) => CreateModTest(new ModTestData { Mod = new OsuModFlashlight { ComboBasedSize = { Value = comboBasedSize } }, PassCondition = () => true }); + + [Test] + public void TestPlayfieldBasedSize() + { + ModFlashlight mod = new OsuModFlashlight(); + CreateModTest(new ModTestData + { + Mod = mod, + PassCondition = () => + { + var flashlightOverlay = Player.DrawableRuleset.Overlays + .OfType.Flashlight>() + .First(); + + return Precision.AlmostEquals(mod.DefaultFlashlightSize * .5f, flashlightOverlay.GetSize()); + } + }); + + AddStep("adjust playfield scale", () => + Player.DrawableRuleset.Playfield.Scale = new Vector2(.5f)); + } } } diff --git a/osu.Game/Rulesets/Mods/ModFlashlight.cs b/osu.Game/Rulesets/Mods/ModFlashlight.cs index 95406cc9e6..d714cd3c85 100644 --- a/osu.Game/Rulesets/Mods/ModFlashlight.cs +++ b/osu.Game/Rulesets/Mods/ModFlashlight.cs @@ -86,6 +86,7 @@ namespace osu.Game.Rulesets.Mods flashlight.Depth = float.MinValue; flashlight.Combo.BindTo(Combo); + flashlight.GetPlayfieldScale = () => drawableRuleset.Playfield.Scale; drawableRuleset.Overlays.Add(flashlight); } @@ -102,6 +103,8 @@ namespace osu.Game.Rulesets.Mods public override bool RemoveCompletedTransforms => false; + internal Func? GetPlayfieldScale; + private readonly float defaultFlashlightSize; private readonly float sizeMultiplier; private readonly bool comboBasedSize; @@ -141,10 +144,18 @@ namespace osu.Game.Rulesets.Mods protected abstract string FragmentShader { get; } - protected float GetSize() + public float GetSize() { float size = defaultFlashlightSize * sizeMultiplier; + if (GetPlayfieldScale != null) + { + Vector2 playfieldScale = GetPlayfieldScale(); + float rulesetScaleAvg = (playfieldScale.X + playfieldScale.Y) / 2f; + + size *= rulesetScaleAvg; + } + if (isBreakTime.Value) size *= 2.5f; else if (comboBasedSize)