diff --git a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModFlashlight.cs b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModFlashlight.cs index 776d5854d1..3dca179f2f 100644 --- a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModFlashlight.cs +++ b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModFlashlight.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using NUnit.Framework; using osu.Framework.Testing; +using osu.Framework.Utils; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Osu.Beatmaps; @@ -32,6 +33,27 @@ 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)); + } + [Test] public void TestSliderDimsOnlyAfterStartTime() { diff --git a/osu.Game/Rulesets/Mods/ModFlashlight.cs b/osu.Game/Rulesets/Mods/ModFlashlight.cs index 9227af64b8..c3775b0875 100644 --- a/osu.Game/Rulesets/Mods/ModFlashlight.cs +++ b/osu.Game/Rulesets/Mods/ModFlashlight.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Diagnostics; using System.Runtime.InteropServices; using osu.Framework.Allocation; using osu.Framework.Bindables; @@ -13,6 +14,7 @@ using osu.Framework.Graphics.Shaders; using osu.Framework.Graphics.Shaders.Types; using osu.Framework.Graphics.Sprites; using osu.Framework.Localisation; +using osu.Framework.Utils; using osu.Game.Configuration; using osu.Game.Graphics; using osu.Game.Graphics.OpenGL.Vertices; @@ -84,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); } @@ -100,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; @@ -139,10 +144,19 @@ 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(); + + Debug.Assert(Precision.AlmostEquals(Math.Abs(playfieldScale.X), Math.Abs(playfieldScale.Y)), + @"Playfield has non-proportional scaling. Flashlight implementations should be revisited with regard to balance."); + size *= Math.Abs(playfieldScale.X); + } + if (isBreakTime.Value) size *= 2.5f; else if (comboBasedSize)