Simplify flashlight parameter passing flow

This commit is contained in:
Bartłomiej Dach 2022-01-24 20:55:24 +01:00
parent 5874475dff
commit a227af75ed
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
5 changed files with 37 additions and 40 deletions

View File

@ -35,7 +35,7 @@ namespace osu.Game.Rulesets.Catch.Mods
public override float DefaultFlashlightSize => 350; public override float DefaultFlashlightSize => 350;
public override Flashlight CreateFlashlight() => new CatchFlashlight(playfield, ComboBasedSize.Value, SizeMultiplier.Value, DefaultFlashlightSize); protected override Flashlight CreateFlashlight() => new CatchFlashlight(this, playfield);
private CatchPlayfield playfield; private CatchPlayfield playfield;
@ -49,11 +49,11 @@ namespace osu.Game.Rulesets.Catch.Mods
{ {
private readonly CatchPlayfield playfield; private readonly CatchPlayfield playfield;
public CatchFlashlight(CatchPlayfield playfield, bool isRadiusBasedOnCombo, float initialRadius, float defaultFlashlightSize) public CatchFlashlight(CatchModFlashlight modFlashlight, CatchPlayfield playfield)
: base(isRadiusBasedOnCombo, initialRadius, defaultFlashlightSize) : base(modFlashlight)
{ {
this.playfield = playfield; this.playfield = playfield;
FlashlightSize = new Vector2(0, GetRadiusFor(0)); FlashlightSize = new Vector2(0, GetSizeFor(0));
} }
protected override void Update() protected override void Update()
@ -65,7 +65,7 @@ namespace osu.Game.Rulesets.Catch.Mods
protected override void OnComboChange(ValueChangedEvent<int> e) protected override void OnComboChange(ValueChangedEvent<int> e)
{ {
this.TransformTo(nameof(FlashlightSize), new Vector2(0, GetRadiusFor(e.NewValue)), FLASHLIGHT_FADE_DURATION); this.TransformTo(nameof(FlashlightSize), new Vector2(0, GetSizeFor(e.NewValue)), FLASHLIGHT_FADE_DURATION);
} }
protected override string FragmentShader => "CircularFlashlight"; protected override string FragmentShader => "CircularFlashlight";

View File

@ -36,16 +36,16 @@ namespace osu.Game.Rulesets.Mania.Mods
public override float DefaultFlashlightSize => 50; public override float DefaultFlashlightSize => 50;
public override Flashlight CreateFlashlight() => new ManiaFlashlight(ComboBasedSize.Value, SizeMultiplier.Value, DefaultFlashlightSize); protected override Flashlight CreateFlashlight() => new ManiaFlashlight(this);
private class ManiaFlashlight : Flashlight private class ManiaFlashlight : Flashlight
{ {
private readonly LayoutValue flashlightProperties = new LayoutValue(Invalidation.DrawSize); private readonly LayoutValue flashlightProperties = new LayoutValue(Invalidation.DrawSize);
public ManiaFlashlight(bool isRadiusBasedOnCombo, float initialRadius, float defaultFlashlightSize) public ManiaFlashlight(ManiaModFlashlight modFlashlight)
: base(isRadiusBasedOnCombo, initialRadius, defaultFlashlightSize) : base(modFlashlight)
{ {
FlashlightSize = new Vector2(DrawWidth, GetRadiusFor(0)); FlashlightSize = new Vector2(DrawWidth, GetSizeFor(0));
AddLayout(flashlightProperties); AddLayout(flashlightProperties);
} }
@ -65,7 +65,7 @@ namespace osu.Game.Rulesets.Mania.Mods
protected override void OnComboChange(ValueChangedEvent<int> e) protected override void OnComboChange(ValueChangedEvent<int> e)
{ {
this.TransformTo(nameof(FlashlightSize), new Vector2(DrawWidth, GetRadiusFor(e.NewValue)), FLASHLIGHT_FADE_DURATION); this.TransformTo(nameof(FlashlightSize), new Vector2(DrawWidth, GetSizeFor(e.NewValue)), FLASHLIGHT_FADE_DURATION);
} }
protected override string FragmentShader => "RectangularFlashlight"; protected override string FragmentShader => "RectangularFlashlight";

View File

@ -51,7 +51,7 @@ namespace osu.Game.Rulesets.Osu.Mods
private OsuFlashlight flashlight; private OsuFlashlight flashlight;
public override Flashlight CreateFlashlight() => flashlight = new OsuFlashlight(ComboBasedSize.Value, SizeMultiplier.Value, FollowDelay.Value, DefaultFlashlightSize); protected override Flashlight CreateFlashlight() => flashlight = new OsuFlashlight(this);
public void ApplyToDrawableHitObject(DrawableHitObject drawable) public void ApplyToDrawableHitObject(DrawableHitObject drawable)
{ {
@ -61,17 +61,14 @@ namespace osu.Game.Rulesets.Osu.Mods
private class OsuFlashlight : Flashlight, IRequireHighFrequencyMousePosition private class OsuFlashlight : Flashlight, IRequireHighFrequencyMousePosition
{ {
public double FollowDelay { private get; set; } private readonly double followDelay;
//public float InitialRadius { private get; set; } public OsuFlashlight(OsuModFlashlight modFlashlight)
public bool ChangeRadius { private get; set; } : base(modFlashlight)
public OsuFlashlight(bool isRadiusBasedOnCombo, float initialRadius, double followDelay, float defaultFlashlightSize)
: base(isRadiusBasedOnCombo, initialRadius, defaultFlashlightSize)
{ {
FollowDelay = followDelay; followDelay = modFlashlight.FollowDelay.Value;
FlashlightSize = new Vector2(0, GetRadiusFor(0)); FlashlightSize = new Vector2(0, GetSizeFor(0));
} }
public void OnSliderTrackingChange(ValueChangedEvent<bool> e) public void OnSliderTrackingChange(ValueChangedEvent<bool> e)
@ -86,14 +83,14 @@ namespace osu.Game.Rulesets.Osu.Mods
var destination = e.MousePosition; var destination = e.MousePosition;
FlashlightPosition = Interpolation.ValueAt( FlashlightPosition = Interpolation.ValueAt(
Math.Min(Math.Abs(Clock.ElapsedFrameTime), FollowDelay), position, destination, 0, FollowDelay, Easing.Out); Math.Min(Math.Abs(Clock.ElapsedFrameTime), followDelay), position, destination, 0, followDelay, Easing.Out);
return base.OnMouseMove(e); return base.OnMouseMove(e);
} }
protected override void OnComboChange(ValueChangedEvent<int> e) protected override void OnComboChange(ValueChangedEvent<int> e)
{ {
this.TransformTo(nameof(FlashlightSize), new Vector2(0, GetRadiusFor(e.NewValue)), FLASHLIGHT_FADE_DURATION); this.TransformTo(nameof(FlashlightSize), new Vector2(0, GetSizeFor(e.NewValue)), FLASHLIGHT_FADE_DURATION);
} }
protected override string FragmentShader => "CircularFlashlight"; protected override string FragmentShader => "CircularFlashlight";

View File

@ -36,7 +36,7 @@ namespace osu.Game.Rulesets.Taiko.Mods
public override float DefaultFlashlightSize => 250; public override float DefaultFlashlightSize => 250;
public override Flashlight CreateFlashlight() => new TaikoFlashlight(playfield, ComboBasedSize.Value, SizeMultiplier.Value, DefaultFlashlightSize); protected override Flashlight CreateFlashlight() => new TaikoFlashlight(this, playfield);
private TaikoPlayfield playfield; private TaikoPlayfield playfield;
@ -51,8 +51,8 @@ namespace osu.Game.Rulesets.Taiko.Mods
private readonly LayoutValue flashlightProperties = new LayoutValue(Invalidation.DrawSize); private readonly LayoutValue flashlightProperties = new LayoutValue(Invalidation.DrawSize);
private readonly TaikoPlayfield taikoPlayfield; private readonly TaikoPlayfield taikoPlayfield;
public TaikoFlashlight(TaikoPlayfield taikoPlayfield, bool isRadiusBasedOnCombo, float initialRadius, float defaultFlashlightSize) public TaikoFlashlight(TaikoModFlashlight modFlashlight, TaikoPlayfield taikoPlayfield)
: base(isRadiusBasedOnCombo, initialRadius, defaultFlashlightSize) : base(modFlashlight)
{ {
this.taikoPlayfield = taikoPlayfield; this.taikoPlayfield = taikoPlayfield;
FlashlightSize = getSizeFor(0); FlashlightSize = getSizeFor(0);
@ -63,7 +63,7 @@ namespace osu.Game.Rulesets.Taiko.Mods
private Vector2 getSizeFor(int combo) private Vector2 getSizeFor(int combo)
{ {
// Preserve flashlight size through the playfield's aspect adjustment. // Preserve flashlight size through the playfield's aspect adjustment.
return new Vector2(0, GetRadiusFor(combo) * taikoPlayfield.DrawHeight / TaikoPlayfield.DEFAULT_HEIGHT); return new Vector2(0, GetSizeFor(combo) * taikoPlayfield.DrawHeight / TaikoPlayfield.DEFAULT_HEIGHT);
} }
protected override void OnComboChange(ValueChangedEvent<int> e) protected override void OnComboChange(ValueChangedEvent<int> e)

View File

@ -88,7 +88,7 @@ namespace osu.Game.Rulesets.Mods
flashlight.Breaks = drawableRuleset.Beatmap.Breaks; flashlight.Breaks = drawableRuleset.Beatmap.Breaks;
} }
public abstract Flashlight CreateFlashlight(); protected abstract Flashlight CreateFlashlight();
public abstract class Flashlight : Drawable public abstract class Flashlight : Drawable
{ {
@ -102,17 +102,15 @@ namespace osu.Game.Rulesets.Mods
public List<BreakPeriod> Breaks; public List<BreakPeriod> Breaks;
public readonly bool IsRadiusBasedOnCombo; private readonly float defaultFlashlightSize;
private readonly float sizeMultiplier;
private readonly bool comboBasedSize;
public readonly float InitialRadius; protected Flashlight(ModFlashlight modFlashlight)
public readonly float DefaultFlashlightSize;
protected Flashlight(bool isRadiusBasedOnCombo, float initialRadius, float defaultFlashlightSize)
{ {
IsRadiusBasedOnCombo = isRadiusBasedOnCombo; defaultFlashlightSize = modFlashlight.DefaultFlashlightSize;
InitialRadius = initialRadius; sizeMultiplier = modFlashlight.SizeMultiplier.Value;
DefaultFlashlightSize = defaultFlashlightSize; comboBasedSize = modFlashlight.ComboBasedSize.Value;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -146,17 +144,19 @@ namespace osu.Game.Rulesets.Mods
protected abstract string FragmentShader { get; } protected abstract string FragmentShader { get; }
protected float GetRadiusFor(int combo) protected float GetSizeFor(int combo)
{ {
if (IsRadiusBasedOnCombo) float size = defaultFlashlightSize * sizeMultiplier;
if (comboBasedSize)
{ {
if (combo > 200) if (combo > 200)
return InitialRadius * 0.8f * DefaultFlashlightSize; size *= 0.8f;
else if (combo > 100) else if (combo > 100)
return InitialRadius * 0.9f * DefaultFlashlightSize; size *= 0.9f;
} }
return InitialRadius * DefaultFlashlightSize; return size;
} }
private Vector2 flashlightPosition; private Vector2 flashlightPosition;