1
0
mirror of https://github.com/ppy/osu.git synced 2026-06-01 19:00:05 +08:00

Code quality pass

This commit is contained in:
Dean Herbert
2025-03-18 16:49:27 +09:00
Unverified
parent 533b0e0f88
commit a4ced55640
4 changed files with 77 additions and 80 deletions
+3 -3
View File
@@ -18,7 +18,7 @@ namespace osu.Game.Screens.Menu
[Resolved]
private GameHost host { get; set; } = null!;
private StarFountainSfx sfx = null!;
private StarFountainSounds sounds = null!;
[BackgroundDependencyLoader]
private void load()
@@ -39,7 +39,7 @@ namespace osu.Game.Screens.Menu
Origin = Anchor.BottomRight,
X = -250,
},
sfx = new StarFountainSfx()
sounds = new StarFountainSounds()
};
}
@@ -83,7 +83,7 @@ namespace osu.Game.Screens.Menu
// Don't play SFX when game is in background, as it can be a bit noisy.
if (host.IsActive.Value)
sfx.Trigger();
sounds.Play();
}
}
}
-74
View File
@@ -1,74 +0,0 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Threading;
using osu.Game.Audio;
using osu.Game.Skinning;
namespace osu.Game.Screens.Menu
{
public partial class StarFountainSfx : Container
{
private const int shoot_retrigger_delay = 500;
private const int loop_fade_duration = 500;
private double? lastPlayback;
private SkinnableSound? shootSample;
private PausableSkinnableSound? loopSample;
private ScheduledDelegate? loopFadeDelegate;
private ScheduledDelegate? loopStopDelegate;
public void Trigger()
{
loopFadeDelegate?.Cancel();
loopStopDelegate?.Cancel();
// Only play 'shootSample' if enough time has passed since last `Trigger()` call.
if (lastPlayback == null || Time.Current - lastPlayback > shoot_retrigger_delay)
{
loopSample?.Stop();
shootSample?.Play();
lastPlayback = Time.Current;
return;
}
if (loopSample == null) return;
// Only call `Play()` if `loopSample` is not already playing, to prevent restarting the sample each time.
if (!loopSample.RequestedPlaying)
{
loopSample.Volume.Value = 1f;
loopSample.Play();
}
// Schedule a volume fadeout, followed by a `Stop()`.
loopFadeDelegate = Scheduler.AddDelayed(() =>
{
this.TransformBindableTo(loopSample.Volume, 0, loop_fade_duration);
loopStopDelegate = Scheduler.AddDelayed(() =>
{
loopSample?.Stop();
}, loop_fade_duration);
}, shoot_retrigger_delay);
lastPlayback = Time.Current;
}
[BackgroundDependencyLoader]
private void load()
{
Children = new Drawable[]
{
shootSample = new SkinnableSound(new SampleInfo("Gameplay/fountain-shoot")),
loopSample = new PausableSkinnableSound(new SampleInfo("Gameplay/fountain-loop")) { Looping = true },
};
}
}
}
@@ -0,0 +1,71 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Threading;
using osu.Game.Audio;
using osu.Game.Skinning;
namespace osu.Game.Screens.Menu
{
public partial class StarFountainSounds : CompositeComponent
{
private const int shoot_retrigger_delay = 500;
private const int loop_fade_duration = 500;
private double? lastPlayback;
private SkinnableSound shootSample = null!;
private PausableSkinnableSound loopSample = null!;
private ScheduledDelegate? loopFadeDelegate;
private ScheduledDelegate? loopStopDelegate;
[BackgroundDependencyLoader]
private void load()
{
InternalChildren = new Drawable[]
{
shootSample = new SkinnableSound(new SampleInfo("Gameplay/fountain-shoot")),
loopSample = new PausableSkinnableSound(new SampleInfo("Gameplay/fountain-loop")) { Looping = true },
};
}
public void Play()
{
loopFadeDelegate?.Cancel();
loopStopDelegate?.Cancel();
try
{
// Only play 'shootSample' if enough time has passed since last `Play()` call.
if (lastPlayback == null || Time.Current - lastPlayback > shoot_retrigger_delay)
{
loopSample.Stop();
shootSample.Play();
return;
}
// Only call `Play()` if `loopSample` is not already playing, to prevent restarting the sample each time.
if (!loopSample.RequestedPlaying)
{
this.TransformBindableTo(loopSample.Volume, 1);
loopSample.Play();
}
// Schedule a volume fadeout, followed by a `Stop()`.
loopFadeDelegate = Scheduler.AddDelayed(() =>
{
this.TransformBindableTo(loopSample.Volume, 0, loop_fade_duration);
loopStopDelegate = Scheduler.AddDelayed(() => loopSample.Stop(), loop_fade_duration);
}, shoot_retrigger_delay);
}
finally
{
lastPlayback = Time.Current;
}
}
}
}
@@ -19,7 +19,7 @@ namespace osu.Game.Screens.Play
private Bindable<bool> kiaiStarFountains = null!;
private StarFountainSfx sfx = null!;
private StarFountainSounds sounds = null!;
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
@@ -42,7 +42,7 @@ namespace osu.Game.Screens.Play
Origin = Anchor.BottomRight,
X = -75,
},
sfx = new StarFountainSfx(),
sounds = new StarFountainSounds(),
};
}
@@ -70,7 +70,7 @@ namespace osu.Game.Screens.Play
leftFountain.Shoot(1);
rightFountain.Shoot(-1);
sfx.Trigger();
sounds.Play();
}
public partial class GameplayStarFountain : StarFountain