From e3ba7d9ba56c334b2fe815ca1d15e59539bd9f65 Mon Sep 17 00:00:00 2001 From: mk-56 Date: Mon, 24 Jan 2022 10:24:40 +0100 Subject: [PATCH 001/278] Wiggle mod expansion Free dlc! --- osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs | 31 ++++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs index ff6ba6e121..e0b09213b7 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs @@ -2,8 +2,10 @@ // See the LICENCE file in the repository root for full licence text. using System; +using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; +using osu.Game.Configuration; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Types; @@ -22,8 +24,21 @@ namespace osu.Game.Rulesets.Osu.Mods public override double ScoreMultiplier => 1; public override Type[] IncompatibleMods => new[] { typeof(OsuModTransform) }; - private const int wiggle_duration = 90; // (ms) Higher = fewer wiggles - private const int wiggle_strength = 10; // Higher = stronger wiggles + [SettingSource("Wiggle strength", "something")] + public BindableDouble WiggleStrength { get; } = new BindableDouble(10) + { + MinValue = 1f, + MaxValue = 15f, + Precision = .5f + }; + + [SettingSource("Wiggle duration", "milliseconds per wiggle")] + public BindableInt WiggleDuration { get; } = new BindableInt(90) + { + MinValue = 40, + MaxValue = 300, + Precision = 5 + }; protected override void ApplyIncreasedVisibilityState(DrawableHitObject hitObject, ArmedState state) => drawableOnApplyCustomUpdateState(hitObject, state); @@ -42,18 +57,18 @@ namespace osu.Game.Rulesets.Osu.Mods Random objRand = new Random((int)osuObject.StartTime); // Wiggle all objects during TimePreempt - int amountWiggles = (int)osuObject.TimePreempt / wiggle_duration; + int amountWiggles = (int)osuObject.TimePreempt / WiggleDuration.Value; void wiggle() { float nextAngle = (float)(objRand.NextDouble() * 2 * Math.PI); - float nextDist = (float)(objRand.NextDouble() * wiggle_strength); - drawable.MoveTo(new Vector2((float)(nextDist * Math.Cos(nextAngle) + origin.X), (float)(nextDist * Math.Sin(nextAngle) + origin.Y)), wiggle_duration); + float nextDist = (float)(objRand.NextDouble() * WiggleStrength.Value); + drawable.MoveTo(new Vector2((float)(nextDist * Math.Cos(nextAngle) + origin.X), (float)(nextDist * Math.Sin(nextAngle) + origin.Y)), WiggleDuration.Value); } for (int i = 0; i < amountWiggles; i++) { - using (drawable.BeginAbsoluteSequence(osuObject.StartTime - osuObject.TimePreempt + i * wiggle_duration)) + using (drawable.BeginAbsoluteSequence(osuObject.StartTime - osuObject.TimePreempt + i * WiggleDuration.Value)) wiggle(); } @@ -61,11 +76,11 @@ namespace osu.Game.Rulesets.Osu.Mods if (!(osuObject is IHasDuration endTime)) return; - amountWiggles = (int)(endTime.Duration / wiggle_duration); + amountWiggles = (int)(endTime.Duration / WiggleDuration.Value); for (int i = 0; i < amountWiggles; i++) { - using (drawable.BeginAbsoluteSequence(osuObject.StartTime + i * wiggle_duration)) + using (drawable.BeginAbsoluteSequence(osuObject.StartTime + i * WiggleDuration.Value)) wiggle(); } } From a427e20090fc6ea3a3161f1f90bfa3df35bcf9ef Mon Sep 17 00:00:00 2001 From: mk-56 Date: Mon, 24 Jan 2022 10:38:11 +0100 Subject: [PATCH 002/278] Fixes --- osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs index e0b09213b7..7116ee819c 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs @@ -24,7 +24,7 @@ namespace osu.Game.Rulesets.Osu.Mods public override double ScoreMultiplier => 1; public override Type[] IncompatibleMods => new[] { typeof(OsuModTransform) }; - [SettingSource("Wiggle strength", "something")] + [SettingSource("Strength")] public BindableDouble WiggleStrength { get; } = new BindableDouble(10) { MinValue = 1f, @@ -32,7 +32,7 @@ namespace osu.Game.Rulesets.Osu.Mods Precision = .5f }; - [SettingSource("Wiggle duration", "milliseconds per wiggle")] + [SettingSource("Duration", "Milliseconds per wiggle")] public BindableInt WiggleDuration { get; } = new BindableInt(90) { MinValue = 40, From 836cb1ee323416b71d2f649bfd725d098fa8dad9 Mon Sep 17 00:00:00 2001 From: mk-56 Date: Mon, 24 Jan 2022 12:16:29 +0100 Subject: [PATCH 003/278] Suggested boundary change --- osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs index 7116ee819c..10806318b0 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs @@ -25,11 +25,11 @@ namespace osu.Game.Rulesets.Osu.Mods public override Type[] IncompatibleMods => new[] { typeof(OsuModTransform) }; [SettingSource("Strength")] - public BindableDouble WiggleStrength { get; } = new BindableDouble(10) + public BindableDouble WiggleStrength { get; } = new BindableDouble(1) { - MinValue = 1f, - MaxValue = 15f, - Precision = .5f + MinValue = .1f, + MaxValue = 2f, + Precision = .1f }; [SettingSource("Duration", "Milliseconds per wiggle")] @@ -62,7 +62,7 @@ namespace osu.Game.Rulesets.Osu.Mods void wiggle() { float nextAngle = (float)(objRand.NextDouble() * 2 * Math.PI); - float nextDist = (float)(objRand.NextDouble() * WiggleStrength.Value); + float nextDist = (float)(objRand.NextDouble() * WiggleStrength.Value * 7); drawable.MoveTo(new Vector2((float)(nextDist * Math.Cos(nextAngle) + origin.X), (float)(nextDist * Math.Sin(nextAngle) + origin.Y)), WiggleDuration.Value); } From 35be0f24d02a5474b05b997526f662021311bb4d Mon Sep 17 00:00:00 2001 From: mk-56 Date: Thu, 27 Jan 2022 00:10:15 +0100 Subject: [PATCH 004/278] fixed leading "0"s not being present infront of decimal floats --- osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs index 10806318b0..853c974a04 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs @@ -27,9 +27,9 @@ namespace osu.Game.Rulesets.Osu.Mods [SettingSource("Strength")] public BindableDouble WiggleStrength { get; } = new BindableDouble(1) { - MinValue = .1f, + MinValue = 0.1f, MaxValue = 2f, - Precision = .1f + Precision = 0.1f }; [SettingSource("Duration", "Milliseconds per wiggle")] From dd8fc710fafc1319bb16613f056b3cf9285d4308 Mon Sep 17 00:00:00 2001 From: mk-56 Date: Fri, 4 Feb 2022 15:48:46 +0100 Subject: [PATCH 005/278] removed wiggle duration --- osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs index 853c974a04..fae9d785fb 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs @@ -31,15 +31,6 @@ namespace osu.Game.Rulesets.Osu.Mods MaxValue = 2f, Precision = 0.1f }; - - [SettingSource("Duration", "Milliseconds per wiggle")] - public BindableInt WiggleDuration { get; } = new BindableInt(90) - { - MinValue = 40, - MaxValue = 300, - Precision = 5 - }; - protected override void ApplyIncreasedVisibilityState(DrawableHitObject hitObject, ArmedState state) => drawableOnApplyCustomUpdateState(hitObject, state); protected override void ApplyNormalVisibilityState(DrawableHitObject hitObject, ArmedState state) => drawableOnApplyCustomUpdateState(hitObject, state); @@ -57,18 +48,18 @@ namespace osu.Game.Rulesets.Osu.Mods Random objRand = new Random((int)osuObject.StartTime); // Wiggle all objects during TimePreempt - int amountWiggles = (int)osuObject.TimePreempt / WiggleDuration.Value; + int amountWiggles = (int)osuObject.TimePreempt / 70; void wiggle() { float nextAngle = (float)(objRand.NextDouble() * 2 * Math.PI); float nextDist = (float)(objRand.NextDouble() * WiggleStrength.Value * 7); - drawable.MoveTo(new Vector2((float)(nextDist * Math.Cos(nextAngle) + origin.X), (float)(nextDist * Math.Sin(nextAngle) + origin.Y)), WiggleDuration.Value); + drawable.MoveTo(new Vector2((float)(nextDist * Math.Cos(nextAngle) + origin.X), (float)(nextDist * Math.Sin(nextAngle) + origin.Y)), 70); } for (int i = 0; i < amountWiggles; i++) { - using (drawable.BeginAbsoluteSequence(osuObject.StartTime - osuObject.TimePreempt + i * WiggleDuration.Value)) + using (drawable.BeginAbsoluteSequence(osuObject.StartTime - osuObject.TimePreempt + i * 70)) wiggle(); } @@ -76,11 +67,11 @@ namespace osu.Game.Rulesets.Osu.Mods if (!(osuObject is IHasDuration endTime)) return; - amountWiggles = (int)(endTime.Duration / WiggleDuration.Value); + amountWiggles = (int)(endTime.Duration / 70); for (int i = 0; i < amountWiggles; i++) { - using (drawable.BeginAbsoluteSequence(osuObject.StartTime + i * WiggleDuration.Value)) + using (drawable.BeginAbsoluteSequence(osuObject.StartTime + i * 70)) wiggle(); } } From d213f56f79001d79267940372a472238a58d7df8 Mon Sep 17 00:00:00 2001 From: Alden Wu Date: Tue, 19 Jul 2022 02:08:53 -0700 Subject: [PATCH 006/278] Align legacy followcircle anims to slider ticks --- .../Skinning/Default/DefaultFollowCircle.cs | 42 ++++++-------- .../Skinning/FollowCircle.cs | 31 +++++++--- .../Skinning/Legacy/LegacyFollowCircle.cs | 39 +++++++------ .../Skinning/TickFollowCircle.cs | 58 +++++++++++++++++++ 4 files changed, 119 insertions(+), 51 deletions(-) create mode 100644 osu.Game.Rulesets.Osu/Skinning/TickFollowCircle.cs diff --git a/osu.Game.Rulesets.Osu/Skinning/Default/DefaultFollowCircle.cs b/osu.Game.Rulesets.Osu/Skinning/Default/DefaultFollowCircle.cs index b77d4addee..0acd1a56b6 100644 --- a/osu.Game.Rulesets.Osu/Skinning/Default/DefaultFollowCircle.cs +++ b/osu.Game.Rulesets.Osu/Skinning/Default/DefaultFollowCircle.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Diagnostics; -using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; @@ -32,37 +30,31 @@ namespace osu.Game.Rulesets.Osu.Skinning.Default }; } - protected override void OnTrackingChanged(ValueChangedEvent tracking) + protected override void OnSliderPress() { - Debug.Assert(ParentObject != null); - const float duration = 300f; - if (ParentObject.Judged) - return; + if (Precision.AlmostEquals(0, Alpha)) + this.ScaleTo(1); - if (tracking.NewValue) - { - if (Precision.AlmostEquals(0, Alpha)) - this.ScaleTo(1); - - this.ScaleTo(DrawableSliderBall.FOLLOW_AREA, duration, Easing.OutQuint) - .FadeTo(1f, duration, Easing.OutQuint); - } - else - { - this.ScaleTo(DrawableSliderBall.FOLLOW_AREA * 1.2f, duration / 2, Easing.OutQuint) - .FadeTo(0, duration / 2, Easing.OutQuint); - } + this.ScaleTo(DrawableSliderBall.FOLLOW_AREA, duration, Easing.OutQuint) + .FadeIn(duration, Easing.OutQuint); } - protected override void OnSliderEnd() + protected override void OnSliderRelease() { - const float fade_duration = 300; + const float duration = 150; - // intentionally pile on an extra FadeOut to make it happen much faster - this.ScaleTo(1, fade_duration, Easing.OutQuint); - this.FadeOut(fade_duration / 2, Easing.OutQuint); + this.ScaleTo(DrawableSliderBall.FOLLOW_AREA * 1.2f, duration, Easing.OutQuint) + .FadeTo(0, duration, Easing.OutQuint); + } + + protected override void OnSliderTail() + { + const float duration = 300; + + this.ScaleTo(1, duration, Easing.OutQuint) + .FadeOut(duration / 2, Easing.OutQuint); } } } diff --git a/osu.Game.Rulesets.Osu/Skinning/FollowCircle.cs b/osu.Game.Rulesets.Osu/Skinning/FollowCircle.cs index 321705d25e..ca903b678d 100644 --- a/osu.Game.Rulesets.Osu/Skinning/FollowCircle.cs +++ b/osu.Game.Rulesets.Osu/Skinning/FollowCircle.cs @@ -1,8 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Diagnostics; using osu.Framework.Allocation; -using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Rulesets.Objects.Drawables; @@ -23,7 +23,17 @@ namespace osu.Game.Rulesets.Osu.Skinning [BackgroundDependencyLoader] private void load() { - ((DrawableSlider?)ParentObject)?.Tracking.BindValueChanged(OnTrackingChanged, true); + ((DrawableSlider?)ParentObject)?.Tracking.BindValueChanged(tracking => + { + Debug.Assert(ParentObject != null); + if (ParentObject.Judged) + return; + + if (tracking.NewValue) + OnSliderPress(); + else + OnSliderRelease(); + }, true); } protected override void LoadComplete() @@ -48,13 +58,18 @@ namespace osu.Game.Rulesets.Osu.Skinning private void updateStateTransforms(DrawableHitObject drawableObject, ArmedState state) { - // Gets called by slider ticks, tails, etc., leading to duplicated - // animations which may negatively affect performance if (drawableObject is not DrawableSlider) return; using (BeginAbsoluteSequence(drawableObject.HitStateUpdateTime)) - OnSliderEnd(); + { + switch (state) + { + case ArmedState.Hit: + OnSliderTail(); + break; + } + } } protected override void Dispose(bool isDisposing) @@ -68,8 +83,10 @@ namespace osu.Game.Rulesets.Osu.Skinning } } - protected abstract void OnTrackingChanged(ValueChangedEvent tracking); + protected abstract void OnSliderPress(); - protected abstract void OnSliderEnd(); + protected abstract void OnSliderRelease(); + + protected abstract void OnSliderTail(); } } diff --git a/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacyFollowCircle.cs b/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacyFollowCircle.cs index 5b7da5a1ba..965f2a9cbe 100644 --- a/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacyFollowCircle.cs +++ b/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacyFollowCircle.cs @@ -3,12 +3,11 @@ using System; using System.Diagnostics; -using osu.Framework.Bindables; using osu.Framework.Graphics; namespace osu.Game.Rulesets.Osu.Skinning.Legacy { - public class LegacyFollowCircle : FollowCircle + public class LegacyFollowCircle : TickFollowCircle { public LegacyFollowCircle(Drawable animationContent) { @@ -21,35 +20,37 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy InternalChild = animationContent; } - protected override void OnTrackingChanged(ValueChangedEvent tracking) + protected override void OnSliderPress() { Debug.Assert(ParentObject != null); - if (ParentObject.Judged) - return; - double remainingTime = Math.Max(0, ParentObject.HitStateUpdateTime - Time.Current); // Note that the scale adjust here is 2 instead of DrawableSliderBall.FOLLOW_AREA to match legacy behaviour. // This means the actual tracking area for gameplay purposes is larger than the sprite (but skins may be accounting for this). - if (tracking.NewValue) - { - // TODO: Follow circle should bounce on each slider tick. - this.ScaleTo(0.5f).ScaleTo(2f, Math.Min(180f, remainingTime), Easing.Out) - .FadeTo(0).FadeTo(1f, Math.Min(60f, remainingTime)); - } - else - { - // TODO: Should animate only at the next slider tick if we want to match stable perfectly. - this.ScaleTo(4f, 100) - .FadeTo(0f, 100); - } + this.ScaleTo(0.5f).ScaleTo(2f, Math.Min(180f, remainingTime), Easing.Out) + .FadeTo(0).FadeTo(1f, Math.Min(60f, remainingTime)); } - protected override void OnSliderEnd() + protected override void OnSliderTail() { this.ScaleTo(1.6f, 200, Easing.Out) .FadeOut(200, Easing.In); } + + protected override void OnSliderTick() + { + // TODO: Follow circle should bounce on each slider tick. + + // TEMP DUMMY ANIMS + this.ScaleTo(2.2f) + .ScaleTo(2f, 175f); + } + + protected override void OnSliderBreak() + { + this.ScaleTo(4f, 100) + .FadeTo(0f, 100); + } } } diff --git a/osu.Game.Rulesets.Osu/Skinning/TickFollowCircle.cs b/osu.Game.Rulesets.Osu/Skinning/TickFollowCircle.cs new file mode 100644 index 0000000000..39d62064ab --- /dev/null +++ b/osu.Game.Rulesets.Osu/Skinning/TickFollowCircle.cs @@ -0,0 +1,58 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Game.Rulesets.Objects.Drawables; +using osu.Game.Rulesets.Osu.Objects.Drawables; + +namespace osu.Game.Rulesets.Osu.Skinning +{ + public abstract class TickFollowCircle : FollowCircle + { + protected override void LoadComplete() + { + base.LoadComplete(); + + if (ParentObject != null) + ParentObject.ApplyCustomUpdateState += updateStateTransforms; + } + + private void updateStateTransforms(DrawableHitObject drawableObject, ArmedState state) + { + using (BeginAbsoluteSequence(drawableObject.HitStateUpdateTime)) + { + switch (state) + { + case ArmedState.Hit: + if (drawableObject is DrawableSliderTick or DrawableSliderRepeat) + OnSliderTick(); + break; + + case ArmedState.Miss: + if (drawableObject is DrawableSlider or DrawableSliderTick or DrawableSliderRepeat) + OnSliderBreak(); + break; + } + } + } + + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + + if (ParentObject != null) + ParentObject.ApplyCustomUpdateState -= updateStateTransforms; + } + + /// + /// Sealed empty. Override instead, since animations + /// should only play on slider ticks. + /// + protected sealed override void OnSliderRelease() + { + } + + protected abstract void OnSliderTick(); + + protected abstract void OnSliderBreak(); + } +} From e1f7db6e7df40777fb743e90e50cf51251c301aa Mon Sep 17 00:00:00 2001 From: Alden Wu Date: Tue, 19 Jul 2022 02:25:14 -0700 Subject: [PATCH 007/278] Fix around some comments --- osu.Game.Rulesets.Osu/Skinning/FollowCircle.cs | 3 +++ osu.Game.Rulesets.Osu/Skinning/TickFollowCircle.cs | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Skinning/FollowCircle.cs b/osu.Game.Rulesets.Osu/Skinning/FollowCircle.cs index ca903b678d..ec9d188c6b 100644 --- a/osu.Game.Rulesets.Osu/Skinning/FollowCircle.cs +++ b/osu.Game.Rulesets.Osu/Skinning/FollowCircle.cs @@ -58,6 +58,9 @@ namespace osu.Game.Rulesets.Osu.Skinning private void updateStateTransforms(DrawableHitObject drawableObject, ArmedState state) { + // We only want DrawableSlider here. DrawableSliderTail doesn't quite work because its + // HitStateUpdateTime is ~36ms before DrawableSlider's HitStateUpdateTime (aka slider + // end leniency). if (drawableObject is not DrawableSlider) return; diff --git a/osu.Game.Rulesets.Osu/Skinning/TickFollowCircle.cs b/osu.Game.Rulesets.Osu/Skinning/TickFollowCircle.cs index 39d62064ab..3aeb0c7c0a 100644 --- a/osu.Game.Rulesets.Osu/Skinning/TickFollowCircle.cs +++ b/osu.Game.Rulesets.Osu/Skinning/TickFollowCircle.cs @@ -44,8 +44,8 @@ namespace osu.Game.Rulesets.Osu.Skinning } /// - /// Sealed empty. Override instead, since animations - /// should only play on slider ticks. + /// Sealed empty intentionally. Override instead, since + /// animations should only play on slider ticks. /// protected sealed override void OnSliderRelease() { From 5cb0920cfbdd18da5b3254f27bdbeb94dd281880 Mon Sep 17 00:00:00 2001 From: Alden Wu Date: Tue, 19 Jul 2022 02:27:04 -0700 Subject: [PATCH 008/278] Revert OnSliderTail() to OnSliderEnd() In light of the comment added in the previous commit, slider tail and end are not actually the same. --- osu.Game.Rulesets.Osu/Skinning/Default/DefaultFollowCircle.cs | 2 +- osu.Game.Rulesets.Osu/Skinning/FollowCircle.cs | 4 ++-- osu.Game.Rulesets.Osu/Skinning/Legacy/LegacyFollowCircle.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Skinning/Default/DefaultFollowCircle.cs b/osu.Game.Rulesets.Osu/Skinning/Default/DefaultFollowCircle.cs index 0acd1a56b6..51cfb2568b 100644 --- a/osu.Game.Rulesets.Osu/Skinning/Default/DefaultFollowCircle.cs +++ b/osu.Game.Rulesets.Osu/Skinning/Default/DefaultFollowCircle.cs @@ -49,7 +49,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Default .FadeTo(0, duration, Easing.OutQuint); } - protected override void OnSliderTail() + protected override void OnSliderEnd() { const float duration = 300; diff --git a/osu.Game.Rulesets.Osu/Skinning/FollowCircle.cs b/osu.Game.Rulesets.Osu/Skinning/FollowCircle.cs index ec9d188c6b..d7685c1724 100644 --- a/osu.Game.Rulesets.Osu/Skinning/FollowCircle.cs +++ b/osu.Game.Rulesets.Osu/Skinning/FollowCircle.cs @@ -69,7 +69,7 @@ namespace osu.Game.Rulesets.Osu.Skinning switch (state) { case ArmedState.Hit: - OnSliderTail(); + OnSliderEnd(); break; } } @@ -90,6 +90,6 @@ namespace osu.Game.Rulesets.Osu.Skinning protected abstract void OnSliderRelease(); - protected abstract void OnSliderTail(); + protected abstract void OnSliderEnd(); } } diff --git a/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacyFollowCircle.cs b/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacyFollowCircle.cs index 965f2a9cbe..9e1c2e7e9d 100644 --- a/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacyFollowCircle.cs +++ b/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacyFollowCircle.cs @@ -32,7 +32,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy .FadeTo(0).FadeTo(1f, Math.Min(60f, remainingTime)); } - protected override void OnSliderTail() + protected override void OnSliderEnd() { this.ScaleTo(1.6f, 200, Easing.Out) .FadeOut(200, Easing.In); From 53e61c5041954c570fb1b5f08a73dbc43da5ed8a Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 3 Jul 2022 22:42:41 +0800 Subject: [PATCH 009/278] Remove the nullable annotation in the catch ruleset. --- osu.Game.Rulesets.Catch/Mods/CatchModAutoplay.cs | 2 -- osu.Game.Rulesets.Catch/Mods/CatchModCinema.cs | 2 -- osu.Game.Rulesets.Catch/Mods/CatchModClassic.cs | 2 -- osu.Game.Rulesets.Catch/Mods/CatchModDaycore.cs | 2 -- osu.Game.Rulesets.Catch/Mods/CatchModDifficultyAdjust.cs | 2 -- osu.Game.Rulesets.Catch/Mods/CatchModDoubleTime.cs | 2 -- osu.Game.Rulesets.Catch/Mods/CatchModEasy.cs | 2 -- osu.Game.Rulesets.Catch/Mods/CatchModFlashlight.cs | 2 -- osu.Game.Rulesets.Catch/Mods/CatchModFloatingFruits.cs | 2 -- osu.Game.Rulesets.Catch/Mods/CatchModHalfTime.cs | 2 -- osu.Game.Rulesets.Catch/Mods/CatchModHardRock.cs | 2 -- osu.Game.Rulesets.Catch/Mods/CatchModHidden.cs | 2 -- osu.Game.Rulesets.Catch/Mods/CatchModMirror.cs | 2 -- osu.Game.Rulesets.Catch/Mods/CatchModMuted.cs | 2 -- osu.Game.Rulesets.Catch/Mods/CatchModNightcore.cs | 2 -- osu.Game.Rulesets.Catch/Mods/CatchModNoFail.cs | 2 -- osu.Game.Rulesets.Catch/Mods/CatchModNoScope.cs | 2 -- osu.Game.Rulesets.Catch/Mods/CatchModPerfect.cs | 2 -- osu.Game.Rulesets.Catch/Mods/CatchModRelax.cs | 2 -- osu.Game.Rulesets.Catch/Mods/CatchModSuddenDeath.cs | 2 -- 20 files changed, 40 deletions(-) diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModAutoplay.cs b/osu.Game.Rulesets.Catch/Mods/CatchModAutoplay.cs index c5ca595fd6..50e48101d3 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModAutoplay.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModAutoplay.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Collections.Generic; using osu.Game.Beatmaps; using osu.Game.Rulesets.Catch.Replays; diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModCinema.cs b/osu.Game.Rulesets.Catch/Mods/CatchModCinema.cs index 10a0809e05..7eda6b37d3 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModCinema.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModCinema.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Collections.Generic; using osu.Game.Beatmaps; using osu.Game.Rulesets.Catch.Objects; diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModClassic.cs b/osu.Game.Rulesets.Catch/Mods/CatchModClassic.cs index 904656993e..9624e84018 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModClassic.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModClassic.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Catch.Mods diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModDaycore.cs b/osu.Game.Rulesets.Catch/Mods/CatchModDaycore.cs index 8d4b57c244..cae19e9468 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModDaycore.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModDaycore.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Catch.Mods diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModDifficultyAdjust.cs b/osu.Game.Rulesets.Catch/Mods/CatchModDifficultyAdjust.cs index 6927d7953f..e59a0a0431 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModDifficultyAdjust.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModDifficultyAdjust.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Linq; using osu.Framework.Bindables; using osu.Game.Beatmaps; diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModDoubleTime.cs b/osu.Game.Rulesets.Catch/Mods/CatchModDoubleTime.cs index c58ce9b07d..57c06e1cd1 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModDoubleTime.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModDoubleTime.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Catch.Mods diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModEasy.cs b/osu.Game.Rulesets.Catch/Mods/CatchModEasy.cs index bea9b094fa..16ef56d845 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModEasy.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModEasy.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Catch.Mods diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModFlashlight.cs b/osu.Game.Rulesets.Catch/Mods/CatchModFlashlight.cs index d166646eaf..7f7c04fb52 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModFlashlight.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModFlashlight.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Game.Configuration; diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModFloatingFruits.cs b/osu.Game.Rulesets.Catch/Mods/CatchModFloatingFruits.cs index 1fe892c9b5..63203dd57c 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModFloatingFruits.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModFloatingFruits.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; using osu.Game.Rulesets.Catch.Objects; diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModHalfTime.cs b/osu.Game.Rulesets.Catch/Mods/CatchModHalfTime.cs index 0c7886be10..ce06b841aa 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModHalfTime.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModHalfTime.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Catch.Mods diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModHardRock.cs b/osu.Game.Rulesets.Catch/Mods/CatchModHardRock.cs index 39b992b3f5..93eadcc13e 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModHardRock.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModHardRock.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; using osu.Game.Beatmaps; using osu.Game.Rulesets.Catch.Beatmaps; diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModHidden.cs b/osu.Game.Rulesets.Catch/Mods/CatchModHidden.cs index b4fbc9d566..51516edacd 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModHidden.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModHidden.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Linq; using osu.Framework.Graphics; using osu.Game.Rulesets.Catch.Objects; diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModMirror.cs b/osu.Game.Rulesets.Catch/Mods/CatchModMirror.cs index 89fc40356d..a97e940a64 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModMirror.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModMirror.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Linq; using osu.Game.Beatmaps; using osu.Game.Rulesets.Catch.Beatmaps; diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModMuted.cs b/osu.Game.Rulesets.Catch/Mods/CatchModMuted.cs index 6b28d1a127..6d2565440a 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModMuted.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModMuted.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.Mods; diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModNightcore.cs b/osu.Game.Rulesets.Catch/Mods/CatchModNightcore.cs index 1fd2227eb7..9e38913be7 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModNightcore.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModNightcore.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.Mods; diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModNoFail.cs b/osu.Game.Rulesets.Catch/Mods/CatchModNoFail.cs index 89e7e4bcd6..3c02646e99 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModNoFail.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModNoFail.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Catch.Mods diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModNoScope.cs b/osu.Game.Rulesets.Catch/Mods/CatchModNoScope.cs index 385d4c50c0..a24a6227fe 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModNoScope.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModNoScope.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using osu.Framework.Bindables; using osu.Game.Rulesets.Mods; diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModPerfect.cs b/osu.Game.Rulesets.Catch/Mods/CatchModPerfect.cs index 0a74ee4fbb..fb92399102 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModPerfect.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModPerfect.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Catch.Mods diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModRelax.cs b/osu.Game.Rulesets.Catch/Mods/CatchModRelax.cs index f4d6fb9ab3..d0a94767d1 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModRelax.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModRelax.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Graphics; using osu.Framework.Input; using osu.Framework.Input.Bindings; diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModSuddenDeath.cs b/osu.Game.Rulesets.Catch/Mods/CatchModSuddenDeath.cs index d98829137c..68e01391ce 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModSuddenDeath.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModSuddenDeath.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Catch.Mods From 91bc7b9381093ca30fb0e501be9a7b6dad4440d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=82=BA=E4=BB=80=E9=BA=BC?= Date: Sun, 10 Jul 2022 23:18:27 +0800 Subject: [PATCH 010/278] Mark the class as non-nullable. Not the safe way but got no better idea. --- osu.Game.Rulesets.Catch/Mods/CatchModFlashlight.cs | 2 +- osu.Game.Rulesets.Catch/Mods/CatchModRelax.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModFlashlight.cs b/osu.Game.Rulesets.Catch/Mods/CatchModFlashlight.cs index 7f7c04fb52..abe391ba4e 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModFlashlight.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModFlashlight.cs @@ -37,7 +37,7 @@ namespace osu.Game.Rulesets.Catch.Mods protected override Flashlight CreateFlashlight() => new CatchFlashlight(this, playfield); - private CatchPlayfield playfield; + private CatchPlayfield playfield = null!; public override void ApplyToDrawableRuleset(DrawableRuleset drawableRuleset) { diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModRelax.cs b/osu.Game.Rulesets.Catch/Mods/CatchModRelax.cs index d0a94767d1..60f1614d98 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModRelax.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModRelax.cs @@ -18,7 +18,7 @@ namespace osu.Game.Rulesets.Catch.Mods { public override string Description => @"Use the mouse to control the catcher."; - private DrawableRuleset drawableRuleset; + private DrawableRuleset drawableRuleset = null!; public void ApplyToDrawableRuleset(DrawableRuleset drawableRuleset) { From 6a096cf11fad6feb5847266a7f66bb113573b7c6 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 20 Jul 2022 20:30:04 +0800 Subject: [PATCH 011/278] Remove nullable disable annotation in the Catch test case. --- osu.Game.Rulesets.Catch.Tests/Mods/CatchModMirrorTest.cs | 2 -- osu.Game.Rulesets.Catch.Tests/Mods/TestSceneCatchModNoScope.cs | 2 -- osu.Game.Rulesets.Catch.Tests/Mods/TestSceneCatchModPerfect.cs | 2 -- osu.Game.Rulesets.Catch.Tests/Mods/TestSceneCatchModRelax.cs | 2 -- 4 files changed, 8 deletions(-) diff --git a/osu.Game.Rulesets.Catch.Tests/Mods/CatchModMirrorTest.cs b/osu.Game.Rulesets.Catch.Tests/Mods/CatchModMirrorTest.cs index 19321a48b9..fbbfee6b60 100644 --- a/osu.Game.Rulesets.Catch.Tests/Mods/CatchModMirrorTest.cs +++ b/osu.Game.Rulesets.Catch.Tests/Mods/CatchModMirrorTest.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Collections.Generic; using NUnit.Framework; using osu.Framework.Utils; diff --git a/osu.Game.Rulesets.Catch.Tests/Mods/TestSceneCatchModNoScope.cs b/osu.Game.Rulesets.Catch.Tests/Mods/TestSceneCatchModNoScope.cs index ffc5734f01..bbe543e73e 100644 --- a/osu.Game.Rulesets.Catch.Tests/Mods/TestSceneCatchModNoScope.cs +++ b/osu.Game.Rulesets.Catch.Tests/Mods/TestSceneCatchModNoScope.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Collections.Generic; using NUnit.Framework; using osu.Framework.Utils; diff --git a/osu.Game.Rulesets.Catch.Tests/Mods/TestSceneCatchModPerfect.cs b/osu.Game.Rulesets.Catch.Tests/Mods/TestSceneCatchModPerfect.cs index 886822f9a5..3e06e78dba 100644 --- a/osu.Game.Rulesets.Catch.Tests/Mods/TestSceneCatchModPerfect.cs +++ b/osu.Game.Rulesets.Catch.Tests/Mods/TestSceneCatchModPerfect.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using NUnit.Framework; using osu.Game.Rulesets.Catch.Mods; using osu.Game.Rulesets.Catch.Objects; diff --git a/osu.Game.Rulesets.Catch.Tests/Mods/TestSceneCatchModRelax.cs b/osu.Game.Rulesets.Catch.Tests/Mods/TestSceneCatchModRelax.cs index 3209be12d5..c01aff0aa0 100644 --- a/osu.Game.Rulesets.Catch.Tests/Mods/TestSceneCatchModRelax.cs +++ b/osu.Game.Rulesets.Catch.Tests/Mods/TestSceneCatchModRelax.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Collections.Generic; using System.Linq; using NUnit.Framework; From 23fd514ca3b691c6e6043288c8d49b2204030477 Mon Sep 17 00:00:00 2001 From: Alden Wu Date: Wed, 20 Jul 2022 18:07:02 -0700 Subject: [PATCH 012/278] Use DrawableSliderTail instead of DrawableSlider --- osu.Game.Rulesets.Osu/Skinning/FollowCircle.cs | 11 ++++++----- osu.Game.Rulesets.Osu/Skinning/TickFollowCircle.cs | 4 +++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Skinning/FollowCircle.cs b/osu.Game.Rulesets.Osu/Skinning/FollowCircle.cs index d7685c1724..06fa381cbb 100644 --- a/osu.Game.Rulesets.Osu/Skinning/FollowCircle.cs +++ b/osu.Game.Rulesets.Osu/Skinning/FollowCircle.cs @@ -58,13 +58,14 @@ namespace osu.Game.Rulesets.Osu.Skinning private void updateStateTransforms(DrawableHitObject drawableObject, ArmedState state) { - // We only want DrawableSlider here. DrawableSliderTail doesn't quite work because its - // HitStateUpdateTime is ~36ms before DrawableSlider's HitStateUpdateTime (aka slider - // end leniency). - if (drawableObject is not DrawableSlider) + if (drawableObject is not DrawableSliderTail) return; - using (BeginAbsoluteSequence(drawableObject.HitStateUpdateTime)) + Debug.Assert(ParentObject != null); + + // Use ParentObject instead of drawableObject because slider tail hit state update time + // is ~36ms before the actual slider end (aka slider tail leniency) + using (BeginAbsoluteSequence(ParentObject.HitStateUpdateTime)) { switch (state) { diff --git a/osu.Game.Rulesets.Osu/Skinning/TickFollowCircle.cs b/osu.Game.Rulesets.Osu/Skinning/TickFollowCircle.cs index 3aeb0c7c0a..de8a8150d0 100644 --- a/osu.Game.Rulesets.Osu/Skinning/TickFollowCircle.cs +++ b/osu.Game.Rulesets.Osu/Skinning/TickFollowCircle.cs @@ -18,6 +18,8 @@ namespace osu.Game.Rulesets.Osu.Skinning private void updateStateTransforms(DrawableHitObject drawableObject, ArmedState state) { + // Fine to use drawableObject.HitStateUpdateTime even for DrawableSliderTail, since on + // stable, the break anim plays right when the tail is missed, not when the slider ends using (BeginAbsoluteSequence(drawableObject.HitStateUpdateTime)) { switch (state) @@ -28,7 +30,7 @@ namespace osu.Game.Rulesets.Osu.Skinning break; case ArmedState.Miss: - if (drawableObject is DrawableSlider or DrawableSliderTick or DrawableSliderRepeat) + if (drawableObject is DrawableSliderTail or DrawableSliderTick or DrawableSliderRepeat) OnSliderBreak(); break; } From 9c2f6103c524edf3e5cbfc118da7bbbcdf35fa4e Mon Sep 17 00:00:00 2001 From: andy840119 Date: Thu, 21 Jul 2022 19:30:04 +0800 Subject: [PATCH 013/278] Following the suggestion to mark the property as nullable. --- osu.Game.Rulesets.Catch/Mods/CatchModFlashlight.cs | 5 +++-- osu.Game.Rulesets.Catch/Mods/CatchModRelax.cs | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModFlashlight.cs b/osu.Game.Rulesets.Catch/Mods/CatchModFlashlight.cs index abe391ba4e..4824106c55 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModFlashlight.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModFlashlight.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using osu.Framework.Bindables; +using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Game.Configuration; using osu.Game.Rulesets.Catch.Objects; @@ -35,9 +36,9 @@ namespace osu.Game.Rulesets.Catch.Mods public override float DefaultFlashlightSize => 350; - protected override Flashlight CreateFlashlight() => new CatchFlashlight(this, playfield); + protected override Flashlight CreateFlashlight() => new CatchFlashlight(this, playfield.AsNonNull()); - private CatchPlayfield playfield = null!; + private CatchPlayfield? playfield; public override void ApplyToDrawableRuleset(DrawableRuleset drawableRuleset) { diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModRelax.cs b/osu.Game.Rulesets.Catch/Mods/CatchModRelax.cs index 60f1614d98..0ab6da0363 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModRelax.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModRelax.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Diagnostics; using osu.Framework.Graphics; using osu.Framework.Input; using osu.Framework.Input.Bindings; @@ -18,7 +19,7 @@ namespace osu.Game.Rulesets.Catch.Mods { public override string Description => @"Use the mouse to control the catcher."; - private DrawableRuleset drawableRuleset = null!; + private DrawableRuleset? drawableRuleset; public void ApplyToDrawableRuleset(DrawableRuleset drawableRuleset) { @@ -27,6 +28,8 @@ namespace osu.Game.Rulesets.Catch.Mods public void ApplyToPlayer(Player player) { + Debug.Assert(drawableRuleset != null); + if (!drawableRuleset.HasReplayLoaded.Value) drawableRuleset.Cursor.Add(new MouseInputHelper((CatchPlayfield)drawableRuleset.Playfield)); } From 726042d9ec2d8eef2a3549fe665d69ba8c51cc15 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 21 Jul 2022 23:16:28 +0900 Subject: [PATCH 014/278] Use switch instead of `or` --- .../Skinning/TickFollowCircle.cs | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Skinning/TickFollowCircle.cs b/osu.Game.Rulesets.Osu/Skinning/TickFollowCircle.cs index de8a8150d0..ca1959a561 100644 --- a/osu.Game.Rulesets.Osu/Skinning/TickFollowCircle.cs +++ b/osu.Game.Rulesets.Osu/Skinning/TickFollowCircle.cs @@ -25,13 +25,26 @@ namespace osu.Game.Rulesets.Osu.Skinning switch (state) { case ArmedState.Hit: - if (drawableObject is DrawableSliderTick or DrawableSliderRepeat) - OnSliderTick(); + switch (drawableObject) + { + case DrawableSliderTick: + case DrawableSliderRepeat: + OnSliderTick(); + break; + } + break; case ArmedState.Miss: - if (drawableObject is DrawableSliderTail or DrawableSliderTick or DrawableSliderRepeat) - OnSliderBreak(); + switch (drawableObject) + { + case DrawableSliderTail: + case DrawableSliderTick: + case DrawableSliderRepeat: + OnSliderBreak(); + break; + } + break; } } From c2c2c505a4f2ab578afaff235e3c042e1e42bf00 Mon Sep 17 00:00:00 2001 From: Alden Wu Date: Thu, 21 Jul 2022 19:46:46 -0700 Subject: [PATCH 015/278] Combine FollowCircle and TickFollowCircle classes --- .../Skinning/Default/DefaultFollowCircle.cs | 13 ++++ .../Skinning/FollowCircle.cs | 52 ++++++++++--- .../Skinning/Legacy/LegacyFollowCircle.cs | 6 +- .../Skinning/TickFollowCircle.cs | 73 ------------------- 4 files changed, 58 insertions(+), 86 deletions(-) delete mode 100644 osu.Game.Rulesets.Osu/Skinning/TickFollowCircle.cs diff --git a/osu.Game.Rulesets.Osu/Skinning/Default/DefaultFollowCircle.cs b/osu.Game.Rulesets.Osu/Skinning/Default/DefaultFollowCircle.cs index 51cfb2568b..3b087245e9 100644 --- a/osu.Game.Rulesets.Osu/Skinning/Default/DefaultFollowCircle.cs +++ b/osu.Game.Rulesets.Osu/Skinning/Default/DefaultFollowCircle.cs @@ -56,5 +56,18 @@ namespace osu.Game.Rulesets.Osu.Skinning.Default this.ScaleTo(1, duration, Easing.OutQuint) .FadeOut(duration / 2, Easing.OutQuint); } + + protected override void OnSliderTick() + { + // TODO: Follow circle should bounce on each slider tick. + + // TEMP DUMMY ANIMS + this.ScaleTo(DrawableSliderBall.FOLLOW_AREA * 1.1f) + .ScaleTo(DrawableSliderBall.FOLLOW_AREA, 175f); + } + + protected override void OnSliderBreak() + { + } } } diff --git a/osu.Game.Rulesets.Osu/Skinning/FollowCircle.cs b/osu.Game.Rulesets.Osu/Skinning/FollowCircle.cs index 06fa381cbb..9eb8e66c83 100644 --- a/osu.Game.Rulesets.Osu/Skinning/FollowCircle.cs +++ b/osu.Game.Rulesets.Osu/Skinning/FollowCircle.cs @@ -58,21 +58,45 @@ namespace osu.Game.Rulesets.Osu.Skinning private void updateStateTransforms(DrawableHitObject drawableObject, ArmedState state) { - if (drawableObject is not DrawableSliderTail) - return; - Debug.Assert(ParentObject != null); - // Use ParentObject instead of drawableObject because slider tail hit state update time - // is ~36ms before the actual slider end (aka slider tail leniency) - using (BeginAbsoluteSequence(ParentObject.HitStateUpdateTime)) + switch (state) { - switch (state) - { - case ArmedState.Hit: - OnSliderEnd(); - break; - } + case ArmedState.Hit: + switch (drawableObject) + { + case DrawableSliderTail: + // Use ParentObject instead of drawableObject because slider tail's + // HitStateUpdateTime is ~36ms before the actual slider end (aka slider + // tail leniency) + using (BeginAbsoluteSequence(ParentObject.HitStateUpdateTime)) + OnSliderEnd(); + break; + + case DrawableSliderTick: + case DrawableSliderRepeat: + using (BeginAbsoluteSequence(drawableObject.HitStateUpdateTime)) + OnSliderTick(); + break; + } + + break; + + case ArmedState.Miss: + switch (drawableObject) + { + case DrawableSliderTail: + case DrawableSliderTick: + case DrawableSliderRepeat: + // Despite above comment, ok to use drawableObject.HitStateUpdateTime + // here, since on stable, the break anim plays right when the tail is + // missed, not when the slider ends + using (BeginAbsoluteSequence(drawableObject.HitStateUpdateTime)) + OnSliderBreak(); + break; + } + + break; } } @@ -92,5 +116,9 @@ namespace osu.Game.Rulesets.Osu.Skinning protected abstract void OnSliderRelease(); protected abstract void OnSliderEnd(); + + protected abstract void OnSliderTick(); + + protected abstract void OnSliderBreak(); } } diff --git a/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacyFollowCircle.cs b/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacyFollowCircle.cs index 9e1c2e7e9d..6d16596ed2 100644 --- a/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacyFollowCircle.cs +++ b/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacyFollowCircle.cs @@ -7,7 +7,7 @@ using osu.Framework.Graphics; namespace osu.Game.Rulesets.Osu.Skinning.Legacy { - public class LegacyFollowCircle : TickFollowCircle + public class LegacyFollowCircle : FollowCircle { public LegacyFollowCircle(Drawable animationContent) { @@ -32,6 +32,10 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy .FadeTo(0).FadeTo(1f, Math.Min(60f, remainingTime)); } + protected override void OnSliderRelease() + { + } + protected override void OnSliderEnd() { this.ScaleTo(1.6f, 200, Easing.Out) diff --git a/osu.Game.Rulesets.Osu/Skinning/TickFollowCircle.cs b/osu.Game.Rulesets.Osu/Skinning/TickFollowCircle.cs deleted file mode 100644 index ca1959a561..0000000000 --- a/osu.Game.Rulesets.Osu/Skinning/TickFollowCircle.cs +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using osu.Game.Rulesets.Objects.Drawables; -using osu.Game.Rulesets.Osu.Objects.Drawables; - -namespace osu.Game.Rulesets.Osu.Skinning -{ - public abstract class TickFollowCircle : FollowCircle - { - protected override void LoadComplete() - { - base.LoadComplete(); - - if (ParentObject != null) - ParentObject.ApplyCustomUpdateState += updateStateTransforms; - } - - private void updateStateTransforms(DrawableHitObject drawableObject, ArmedState state) - { - // Fine to use drawableObject.HitStateUpdateTime even for DrawableSliderTail, since on - // stable, the break anim plays right when the tail is missed, not when the slider ends - using (BeginAbsoluteSequence(drawableObject.HitStateUpdateTime)) - { - switch (state) - { - case ArmedState.Hit: - switch (drawableObject) - { - case DrawableSliderTick: - case DrawableSliderRepeat: - OnSliderTick(); - break; - } - - break; - - case ArmedState.Miss: - switch (drawableObject) - { - case DrawableSliderTail: - case DrawableSliderTick: - case DrawableSliderRepeat: - OnSliderBreak(); - break; - } - - break; - } - } - } - - protected override void Dispose(bool isDisposing) - { - base.Dispose(isDisposing); - - if (ParentObject != null) - ParentObject.ApplyCustomUpdateState -= updateStateTransforms; - } - - /// - /// Sealed empty intentionally. Override instead, since - /// animations should only play on slider ticks. - /// - protected sealed override void OnSliderRelease() - { - } - - protected abstract void OnSliderTick(); - - protected abstract void OnSliderBreak(); - } -} From 16e655766eeb253f4a127bdc34d2dc3247092ba2 Mon Sep 17 00:00:00 2001 From: mk-56 Date: Sat, 23 Jul 2022 23:30:57 +0200 Subject: [PATCH 016/278] Addressed pertinent issues --- osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs index 185751cf3d..52ed843c4c 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs @@ -26,13 +26,16 @@ namespace osu.Game.Rulesets.Osu.Mods public override double ScoreMultiplier => 1; public override Type[] IncompatibleMods => new[] { typeof(OsuModTransform), typeof(OsuModMagnetised), typeof(OsuModRepel) }; - [SettingSource("Strength")] + private const int wiggle_duration = 100; // (ms) Higher = fewer wiggles + + [SettingSource("Strength", "Multiplier applied to the wiggling strength.")] public BindableDouble WiggleStrength { get; } = new BindableDouble(1) { MinValue = 0.1f, MaxValue = 2f, Precision = 0.1f }; + protected override void ApplyIncreasedVisibilityState(DrawableHitObject hitObject, ArmedState state) => drawableOnApplyCustomUpdateState(hitObject, state); protected override void ApplyNormalVisibilityState(DrawableHitObject hitObject, ArmedState state) => drawableOnApplyCustomUpdateState(hitObject, state); @@ -50,18 +53,18 @@ namespace osu.Game.Rulesets.Osu.Mods Random objRand = new Random((int)osuObject.StartTime); // Wiggle all objects during TimePreempt - int amountWiggles = (int)osuObject.TimePreempt / 70; + int amountWiggles = (int)osuObject.TimePreempt / wiggle_duration; void wiggle() { float nextAngle = (float)(objRand.NextDouble() * 2 * Math.PI); float nextDist = (float)(objRand.NextDouble() * WiggleStrength.Value * 7); - drawable.MoveTo(new Vector2((float)(nextDist * Math.Cos(nextAngle) + origin.X), (float)(nextDist * Math.Sin(nextAngle) + origin.Y)), 70); + drawable.MoveTo(new Vector2((float)(nextDist * Math.Cos(nextAngle) + origin.X), (float)(nextDist * Math.Sin(nextAngle) + origin.Y)), wiggle_duration); } for (int i = 0; i < amountWiggles; i++) { - using (drawable.BeginAbsoluteSequence(osuObject.StartTime - osuObject.TimePreempt + i * 70)) + using (drawable.BeginAbsoluteSequence(osuObject.StartTime - osuObject.TimePreempt + i * wiggle_duration)) wiggle(); } @@ -69,11 +72,11 @@ namespace osu.Game.Rulesets.Osu.Mods if (!(osuObject is IHasDuration endTime)) return; - amountWiggles = (int)(endTime.Duration / 70); + amountWiggles = (int)(endTime.Duration / wiggle_duration); for (int i = 0; i < amountWiggles; i++) { - using (drawable.BeginAbsoluteSequence(osuObject.StartTime + i * 70)) + using (drawable.BeginAbsoluteSequence(osuObject.StartTime + i * wiggle_duration)) wiggle(); } } From 7c477e6f2298ffc2fbd8d77efb6badbfd348d068 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sun, 24 Jul 2022 04:19:26 +0300 Subject: [PATCH 017/278] Fix beatmap overlay leaderboard not handling null PP scores properly --- osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs b/osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs index c46c5cde43..08f750827b 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs @@ -6,7 +6,6 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Extensions; @@ -178,10 +177,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores } if (showPerformancePoints) - { - Debug.Assert(score.PP != null); - content.Add(new StatisticText(score.PP.Value, format: @"N0")); - } + content.Add(new StatisticText(score.PP, format: @"N0")); content.Add(new ScoreboardTime(score.Date, text_size) { @@ -222,19 +218,19 @@ namespace osu.Game.Overlays.BeatmapSet.Scores private class StatisticText : OsuSpriteText, IHasTooltip { - private readonly double count; + private readonly double? count; private readonly double? maxCount; private readonly bool showTooltip; public LocalisableString TooltipText => maxCount == null || !showTooltip ? string.Empty : $"{count}/{maxCount}"; - public StatisticText(double count, double? maxCount = null, string format = null, bool showTooltip = true) + public StatisticText(double? count, double? maxCount = null, string format = null, bool showTooltip = true) { this.count = count; this.maxCount = maxCount; this.showTooltip = showTooltip; - Text = count.ToLocalisableString(format); + Text = count?.ToLocalisableString(format) ?? default; Font = OsuFont.GetFont(size: text_size); } From b2f893411766567ad774de4e6327db1688d861cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 22 Jul 2022 20:01:22 +0200 Subject: [PATCH 018/278] Extract base mod select column presentation logic --- osu.Game/Overlays/Mods/ModColumn.cs | 162 ++------------------ osu.Game/Overlays/Mods/ModSelectColumn.cs | 177 ++++++++++++++++++++++ 2 files changed, 187 insertions(+), 152 deletions(-) create mode 100644 osu.Game/Overlays/Mods/ModSelectColumn.cs diff --git a/osu.Game/Overlays/Mods/ModColumn.cs b/osu.Game/Overlays/Mods/ModColumn.cs index beb4856477..1c40c8c6e5 100644 --- a/osu.Game/Overlays/Mods/ModColumn.cs +++ b/osu.Game/Overlays/Mods/ModColumn.cs @@ -12,14 +12,10 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; -using osu.Framework.Graphics.Colour; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; using osu.Framework.Input.Events; using osu.Game.Configuration; using osu.Game.Graphics; -using osu.Game.Graphics.Containers; using osu.Game.Graphics.UserInterface; using osu.Game.Localisation; using osu.Game.Overlays.Mods.Input; @@ -29,10 +25,8 @@ using osuTK.Graphics; namespace osu.Game.Overlays.Mods { - public class ModColumn : CompositeDrawable + public class ModColumn : ModSelectColumn { - public readonly Container TopLevelContent; - public readonly ModType ModType; private IReadOnlyList availableMods = Array.Empty(); @@ -62,149 +56,29 @@ namespace osu.Game.Overlays.Mods } } - /// - /// Determines whether this column should accept user input. - /// - public Bindable Active = new BindableBool(true); - - protected override bool ReceivePositionalInputAtSubTree(Vector2 screenSpacePos) => base.ReceivePositionalInputAtSubTree(screenSpacePos) && Active.Value; - protected virtual ModPanel CreateModPanel(ModState mod) => new ModPanel(mod); private readonly bool allowIncompatibleSelection; - private readonly TextFlowContainer headerText; - private readonly Box headerBackground; - private readonly Container contentContainer; - private readonly Box contentBackground; - private readonly FillFlowContainer panelFlow; private readonly ToggleAllCheckbox? toggleAllCheckbox; - private Colour4 accentColour; - private Bindable hotkeyStyle = null!; private IModHotkeyHandler hotkeyHandler = null!; private Task? latestLoadTask; internal bool ItemsLoaded => latestLoadTask == null; - private const float header_height = 42; - public ModColumn(ModType modType, bool allowIncompatibleSelection) { ModType = modType; this.allowIncompatibleSelection = allowIncompatibleSelection; - Width = 320; - RelativeSizeAxes = Axes.Y; - Shear = new Vector2(ShearedOverlayContainer.SHEAR, 0); - - Container controlContainer; - InternalChildren = new Drawable[] - { - TopLevelContent = new Container - { - RelativeSizeAxes = Axes.Both, - CornerRadius = ModSelectPanel.CORNER_RADIUS, - Masking = true, - Children = new Drawable[] - { - new Container - { - RelativeSizeAxes = Axes.X, - Height = header_height + ModSelectPanel.CORNER_RADIUS, - Children = new Drawable[] - { - headerBackground = new Box - { - RelativeSizeAxes = Axes.X, - Height = header_height + ModSelectPanel.CORNER_RADIUS - }, - headerText = new OsuTextFlowContainer(t => - { - t.Font = OsuFont.TorusAlternate.With(size: 17); - t.Shadow = false; - t.Colour = Colour4.Black; - }) - { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0), - Padding = new MarginPadding - { - Horizontal = 17, - Bottom = ModSelectPanel.CORNER_RADIUS - } - } - } - }, - new Container - { - RelativeSizeAxes = Axes.Both, - Padding = new MarginPadding { Top = header_height }, - Child = contentContainer = new Container - { - RelativeSizeAxes = Axes.Both, - Masking = true, - CornerRadius = ModSelectPanel.CORNER_RADIUS, - BorderThickness = 3, - Children = new Drawable[] - { - contentBackground = new Box - { - RelativeSizeAxes = Axes.Both - }, - new GridContainer - { - RelativeSizeAxes = Axes.Both, - RowDimensions = new[] - { - new Dimension(GridSizeMode.AutoSize), - new Dimension() - }, - Content = new[] - { - new Drawable[] - { - controlContainer = new Container - { - RelativeSizeAxes = Axes.X, - Padding = new MarginPadding { Horizontal = 14 } - } - }, - new Drawable[] - { - new OsuScrollContainer(Direction.Vertical) - { - RelativeSizeAxes = Axes.Both, - ClampExtension = 100, - ScrollbarOverlapsContent = false, - Child = panelFlow = new FillFlowContainer - { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Spacing = new Vector2(0, 7), - Padding = new MarginPadding(7) - } - } - } - } - } - } - } - } - } - } - }; - - createHeaderText(); + HeaderText = ModType.Humanize(LetterCasing.Title); if (allowIncompatibleSelection) { - controlContainer.Height = 35; - controlContainer.Add(toggleAllCheckbox = new ToggleAllCheckbox(this) + ControlContainer.Height = 35; + ControlContainer.Add(toggleAllCheckbox = new ToggleAllCheckbox(this) { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, @@ -212,7 +86,7 @@ namespace osu.Game.Overlays.Mods RelativeSizeAxes = Axes.X, Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0) }); - panelFlow.Padding = new MarginPadding + ItemsFlow.Padding = new MarginPadding { Top = 0, Bottom = 7, @@ -221,33 +95,17 @@ namespace osu.Game.Overlays.Mods } } - private void createHeaderText() - { - IEnumerable headerTextWords = ModType.Humanize(LetterCasing.Title).Split(' '); - - if (headerTextWords.Count() > 1) - { - headerText.AddText($"{headerTextWords.First()} ", t => t.Font = t.Font.With(weight: FontWeight.SemiBold)); - headerTextWords = headerTextWords.Skip(1); - } - - headerText.AddText(string.Join(' ', headerTextWords)); - } - [BackgroundDependencyLoader] - private void load(OverlayColourProvider colourProvider, OsuColour colours, OsuConfigManager configManager) + private void load(OsuColour colours, OsuConfigManager configManager) { - headerBackground.Colour = accentColour = colours.ForModType(ModType); + AccentColour = colours.ForModType(ModType); if (toggleAllCheckbox != null) { - toggleAllCheckbox.AccentColour = accentColour; - toggleAllCheckbox.AccentHoverColour = accentColour.Lighten(0.3f); + toggleAllCheckbox.AccentColour = AccentColour; + toggleAllCheckbox.AccentHoverColour = AccentColour.Lighten(0.3f); } - contentContainer.BorderColour = ColourInfo.GradientVertical(colourProvider.Background4, colourProvider.Background3); - contentBackground.Colour = colourProvider.Background4; - hotkeyStyle = configManager.GetBindable(OsuSetting.ModSelectHotkeyStyle); } @@ -278,7 +136,7 @@ namespace osu.Game.Overlays.Mods latestLoadTask = loadTask = LoadComponentsAsync(panels, loaded => { - panelFlow.ChildrenEnumerable = loaded; + ItemsFlow.ChildrenEnumerable = loaded; updateState(); }, (cancellationTokenSource = new CancellationTokenSource()).Token); loadTask.ContinueWith(_ => diff --git a/osu.Game/Overlays/Mods/ModSelectColumn.cs b/osu.Game/Overlays/Mods/ModSelectColumn.cs new file mode 100644 index 0000000000..d211f9eb5e --- /dev/null +++ b/osu.Game/Overlays/Mods/ModSelectColumn.cs @@ -0,0 +1,177 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Colour; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Localisation; +using osu.Game.Graphics; +using osu.Game.Graphics.Containers; +using osuTK; +using osuTK.Graphics; + +namespace osu.Game.Overlays.Mods +{ + public abstract class ModSelectColumn : CompositeDrawable, IHasAccentColour + { + public readonly Container TopLevelContent; + + public LocalisableString HeaderText + { + set => createHeaderText(value); + } + + public Color4 AccentColour + { + get => headerBackground.Colour; + set => headerBackground.Colour = value; + } + + /// + /// Determines whether this column should accept user input. + /// + public Bindable Active = new BindableBool(true); + + protected override bool ReceivePositionalInputAtSubTree(Vector2 screenSpacePos) => base.ReceivePositionalInputAtSubTree(screenSpacePos) && Active.Value; + + protected readonly Container ControlContainer; + protected readonly FillFlowContainer ItemsFlow; + + private readonly TextFlowContainer headerText; + private readonly Box headerBackground; + private readonly Container contentContainer; + private readonly Box contentBackground; + + private const float header_height = 42; + + protected ModSelectColumn() + { + Width = 320; + RelativeSizeAxes = Axes.Y; + Shear = new Vector2(ShearedOverlayContainer.SHEAR, 0); + + InternalChildren = new Drawable[] + { + TopLevelContent = new Container + { + RelativeSizeAxes = Axes.Both, + CornerRadius = ModSelectPanel.CORNER_RADIUS, + Masking = true, + Children = new Drawable[] + { + new Container + { + RelativeSizeAxes = Axes.X, + Height = header_height + ModSelectPanel.CORNER_RADIUS, + Children = new Drawable[] + { + headerBackground = new Box + { + RelativeSizeAxes = Axes.X, + Height = header_height + ModSelectPanel.CORNER_RADIUS + }, + headerText = new OsuTextFlowContainer(t => + { + t.Font = OsuFont.TorusAlternate.With(size: 17); + t.Shadow = false; + t.Colour = Colour4.Black; + }) + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0), + Padding = new MarginPadding + { + Horizontal = 17, + Bottom = ModSelectPanel.CORNER_RADIUS + } + } + } + }, + new Container + { + RelativeSizeAxes = Axes.Both, + Padding = new MarginPadding { Top = header_height }, + Child = contentContainer = new Container + { + RelativeSizeAxes = Axes.Both, + Masking = true, + CornerRadius = ModSelectPanel.CORNER_RADIUS, + BorderThickness = 3, + Children = new Drawable[] + { + contentBackground = new Box + { + RelativeSizeAxes = Axes.Both + }, + new GridContainer + { + RelativeSizeAxes = Axes.Both, + RowDimensions = new[] + { + new Dimension(GridSizeMode.AutoSize), + new Dimension() + }, + Content = new[] + { + new Drawable[] + { + ControlContainer = new Container + { + RelativeSizeAxes = Axes.X, + Padding = new MarginPadding { Horizontal = 14 } + } + }, + new Drawable[] + { + new OsuScrollContainer(Direction.Vertical) + { + RelativeSizeAxes = Axes.Both, + ClampExtension = 100, + ScrollbarOverlapsContent = false, + Child = ItemsFlow = new FillFlowContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Spacing = new Vector2(0, 7), + Padding = new MarginPadding(7) + } + } + } + } + } + } + } + } + } + } + }; + } + + private void createHeaderText(LocalisableString text) + { + headerText.Clear(); + + int wordIndex = 0; + + headerText.AddText(text, t => + { + if (wordIndex == 0) + t.Font = t.Font.With(weight: FontWeight.SemiBold); + wordIndex += 1; + }); + } + + [BackgroundDependencyLoader] + private void load(OverlayColourProvider colourProvider) + { + contentContainer.BorderColour = ColourInfo.GradientVertical(colourProvider.Background4, colourProvider.Background3); + contentBackground.Colour = colourProvider.Background4; + } + } +} From 6a67d76d7ca085c7f4dec1336fe7be5a66e2ebac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 22 Jul 2022 21:05:02 +0200 Subject: [PATCH 019/278] Add basic mod preset column implementation --- .../UserInterface/TestSceneModPresetColumn.cs | 77 +++++++++++++++++++ .../Localisation/ModPresetColumnStrings.cs | 19 +++++ osu.Game/Overlays/Mods/ModPresetColumn.cs | 77 +++++++++++++++++++ 3 files changed, 173 insertions(+) create mode 100644 osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs create mode 100644 osu.Game/Localisation/ModPresetColumnStrings.cs create mode 100644 osu.Game/Overlays/Mods/ModPresetColumn.cs diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs new file mode 100644 index 0000000000..f6209e1b42 --- /dev/null +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs @@ -0,0 +1,77 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using System.Linq; +using NUnit.Framework; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Overlays; +using osu.Game.Overlays.Mods; +using osu.Game.Rulesets.Mods; +using osu.Game.Rulesets.Osu.Mods; + +namespace osu.Game.Tests.Visual.UserInterface +{ + public class TestSceneModPresetColumn : OsuTestScene + { + [Cached] + private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green); + + [Test] + public void TestBasicAppearance() + { + ModPresetColumn modPresetColumn = null!; + + AddStep("create content", () => Child = new Container + { + RelativeSizeAxes = Axes.Both, + Padding = new MarginPadding(30), + Child = modPresetColumn = new ModPresetColumn + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Presets = createTestPresets().ToArray() + } + }); + AddStep("change presets", () => modPresetColumn.Presets = createTestPresets().Skip(1).ToArray()); + } + + private static IEnumerable createTestPresets() => new[] + { + new ModPreset + { + Name = "First preset", + Description = "Please ignore", + Mods = new Mod[] + { + new OsuModHardRock(), + new OsuModDoubleTime() + } + }, + new ModPreset + { + Name = "AR0", + Description = "For good readers", + Mods = new Mod[] + { + new OsuModDifficultyAdjust + { + ApproachRate = { Value = 0 } + } + } + }, + new ModPreset + { + Name = "This preset is going to have an extraordinarily long name", + Description = "This is done so that the capability to truncate overlong texts may be demonstrated", + Mods = new Mod[] + { + new OsuModFlashlight(), + new OsuModSpinIn() + } + } + }; + } +} diff --git a/osu.Game/Localisation/ModPresetColumnStrings.cs b/osu.Game/Localisation/ModPresetColumnStrings.cs new file mode 100644 index 0000000000..b19a70a248 --- /dev/null +++ b/osu.Game/Localisation/ModPresetColumnStrings.cs @@ -0,0 +1,19 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Localisation; + +namespace osu.Game.Localisation +{ + public static class ModPresetColumnStrings + { + private const string prefix = @"osu.Game.Resources.Localisation.ModPresetColumn"; + + /// + /// "Personal Presets" + /// + public static LocalisableString PersonalPresets => new TranslatableString(getKey(@"personal_presets"), @"Personal Presets"); + + private static string getKey(string key) => $@"{prefix}:{key}"; + } +} \ No newline at end of file diff --git a/osu.Game/Overlays/Mods/ModPresetColumn.cs b/osu.Game/Overlays/Mods/ModPresetColumn.cs new file mode 100644 index 0000000000..b32015e6ea --- /dev/null +++ b/osu.Game/Overlays/Mods/ModPresetColumn.cs @@ -0,0 +1,77 @@ +// Copyright (c) ppy Pty Ltd . 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 System.Threading; +using System.Threading.Tasks; +using osu.Framework.Allocation; +using osu.Game.Graphics; +using osu.Game.Localisation; +using osu.Game.Rulesets.Mods; +using osuTK; + +namespace osu.Game.Overlays.Mods +{ + public class ModPresetColumn : ModSelectColumn + { + private IReadOnlyList presets = Array.Empty(); + + /// + /// Sets the collection of available mod presets. + /// + public IReadOnlyList Presets + { + get => presets; + set + { + presets = value; + + if (IsLoaded) + asyncLoadPanels(); + } + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + AccentColour = colours.Orange1; + HeaderText = ModPresetColumnStrings.PersonalPresets; + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + asyncLoadPanels(); + } + + private CancellationTokenSource? cancellationTokenSource; + + private Task? latestLoadTask; + internal bool ItemsLoaded => latestLoadTask == null; + + private void asyncLoadPanels() + { + cancellationTokenSource?.Cancel(); + + var panels = presets.Select(preset => new ModPresetPanel(preset) + { + Shear = Vector2.Zero + }); + + Task? loadTask; + + latestLoadTask = loadTask = LoadComponentsAsync(panels, loaded => + { + ItemsFlow.ChildrenEnumerable = loaded; + }, (cancellationTokenSource = new CancellationTokenSource()).Token); + loadTask.ContinueWith(_ => + { + if (loadTask == latestLoadTask) + latestLoadTask = null; + }); + } + } +} From 8af9cfbe40c446f8ce1bfd0761f6e68ce9bead0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 24 Jul 2022 23:29:18 +0200 Subject: [PATCH 020/278] Add readonly modifier --- osu.Game/Overlays/Mods/ModSelectColumn.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Overlays/Mods/ModSelectColumn.cs b/osu.Game/Overlays/Mods/ModSelectColumn.cs index d211f9eb5e..0224631577 100644 --- a/osu.Game/Overlays/Mods/ModSelectColumn.cs +++ b/osu.Game/Overlays/Mods/ModSelectColumn.cs @@ -33,7 +33,7 @@ namespace osu.Game.Overlays.Mods /// /// Determines whether this column should accept user input. /// - public Bindable Active = new BindableBool(true); + public readonly Bindable Active = new BindableBool(true); protected override bool ReceivePositionalInputAtSubTree(Vector2 screenSpacePos) => base.ReceivePositionalInputAtSubTree(screenSpacePos) && Active.Value; From 446485f804b4d7df948ea4e82ca23697d6ff2e80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 24 Jul 2022 23:30:52 +0200 Subject: [PATCH 021/278] Move localisation string to common location --- .../Localisation/ModPresetColumnStrings.cs | 19 ------------------- .../Localisation/ModSelectOverlayStrings.cs | 5 +++++ osu.Game/Overlays/Mods/ModPresetColumn.cs | 2 +- 3 files changed, 6 insertions(+), 20 deletions(-) delete mode 100644 osu.Game/Localisation/ModPresetColumnStrings.cs diff --git a/osu.Game/Localisation/ModPresetColumnStrings.cs b/osu.Game/Localisation/ModPresetColumnStrings.cs deleted file mode 100644 index b19a70a248..0000000000 --- a/osu.Game/Localisation/ModPresetColumnStrings.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using osu.Framework.Localisation; - -namespace osu.Game.Localisation -{ - public static class ModPresetColumnStrings - { - private const string prefix = @"osu.Game.Resources.Localisation.ModPresetColumn"; - - /// - /// "Personal Presets" - /// - public static LocalisableString PersonalPresets => new TranslatableString(getKey(@"personal_presets"), @"Personal Presets"); - - private static string getKey(string key) => $@"{prefix}:{key}"; - } -} \ No newline at end of file diff --git a/osu.Game/Localisation/ModSelectOverlayStrings.cs b/osu.Game/Localisation/ModSelectOverlayStrings.cs index e9af7147e3..3696b1f2cd 100644 --- a/osu.Game/Localisation/ModSelectOverlayStrings.cs +++ b/osu.Game/Localisation/ModSelectOverlayStrings.cs @@ -24,6 +24,11 @@ namespace osu.Game.Localisation /// public static LocalisableString ModCustomisation => new TranslatableString(getKey(@"mod_customisation"), @"Mod Customisation"); + /// + /// "Personal Presets" + /// + public static LocalisableString PersonalPresets => new TranslatableString(getKey(@"personal_presets"), @"Personal Presets"); + private static string getKey(string key) => $@"{prefix}:{key}"; } } diff --git a/osu.Game/Overlays/Mods/ModPresetColumn.cs b/osu.Game/Overlays/Mods/ModPresetColumn.cs index b32015e6ea..1eea8383f8 100644 --- a/osu.Game/Overlays/Mods/ModPresetColumn.cs +++ b/osu.Game/Overlays/Mods/ModPresetColumn.cs @@ -37,7 +37,7 @@ namespace osu.Game.Overlays.Mods private void load(OsuColour colours) { AccentColour = colours.Orange1; - HeaderText = ModPresetColumnStrings.PersonalPresets; + HeaderText = ModSelectOverlayStrings.PersonalPresets; } protected override void LoadComplete() From feef16b09b409b9446dd1b3dadea206b246691b7 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 25 Jul 2022 04:18:30 +0300 Subject: [PATCH 022/278] Add potentially failing test case --- .../Visual/Gameplay/TestSceneSpectatorHost.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSpectatorHost.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSpectatorHost.cs index c55e98c1a8..9ad8ac086c 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSpectatorHost.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSpectatorHost.cs @@ -5,6 +5,7 @@ using NUnit.Framework; using osu.Framework.Allocation; +using osu.Framework.Screens; using osu.Game.Online.API; using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Spectator; @@ -43,6 +44,21 @@ namespace osu.Game.Tests.Visual.Gameplay AddAssert("spectator client sent correct ruleset", () => spectatorClient.WatchedUserStates[dummy_user_id].RulesetID == Ruleset.Value.OnlineID); } + [Test] + public void TestRestart() + { + AddAssert("spectator client sees playing state", () => spectatorClient.WatchedUserStates[dummy_user_id].State == SpectatedUserState.Playing); + + AddStep("exit player", () => Player.Exit()); + AddStep("reload player", LoadPlayer); + AddUntilStep("wait for player load", () => Player.IsLoaded && Player.Alpha == 1); + + AddAssert("spectator client sees playing state", () => spectatorClient.WatchedUserStates[dummy_user_id].State == SpectatedUserState.Playing); + + AddWaitStep("wait", 5); + AddUntilStep("spectator client still sees playing state", () => spectatorClient.WatchedUserStates[dummy_user_id].State == SpectatedUserState.Playing); + } + public override void TearDownSteps() { base.TearDownSteps(); From f5a58876694efbb14e5c08be509abed2a6b62abe Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 25 Jul 2022 04:21:52 +0300 Subject: [PATCH 023/278] Fix players potentially not displaying in spectator after restart --- osu.Game/Online/Spectator/SpectatorClient.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/osu.Game/Online/Spectator/SpectatorClient.cs b/osu.Game/Online/Spectator/SpectatorClient.cs index 68c8b57019..d12817d4d4 100644 --- a/osu.Game/Online/Spectator/SpectatorClient.cs +++ b/osu.Game/Online/Spectator/SpectatorClient.cs @@ -206,6 +206,11 @@ namespace osu.Game.Online.Spectator if (!IsPlaying) return; + // Disposal could be processed late, leading to EndPlaying potentially being called after a future BeginPlaying call. + // Account for this by ensuring the current score matches the score in the provided GameplayState. + if (currentScore != state.Score) + return; + if (pendingFrames.Count > 0) purgePendingFrames(); From e0266b0d81fabda2b946321e85fe09ca42c87613 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 25 Jul 2022 04:34:42 +0300 Subject: [PATCH 024/278] Reword comment slightly --- osu.Game/Online/Spectator/SpectatorClient.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Online/Spectator/SpectatorClient.cs b/osu.Game/Online/Spectator/SpectatorClient.cs index d12817d4d4..b5e1c8a45f 100644 --- a/osu.Game/Online/Spectator/SpectatorClient.cs +++ b/osu.Game/Online/Spectator/SpectatorClient.cs @@ -206,8 +206,8 @@ namespace osu.Game.Online.Spectator if (!IsPlaying) return; - // Disposal could be processed late, leading to EndPlaying potentially being called after a future BeginPlaying call. - // Account for this by ensuring the current score matches the score in the provided GameplayState. + // Disposal can take some time, leading to EndPlaying potentially being called after a future play session. + // Account for this by ensuring the score of the current play matches the one in the provided state. if (currentScore != state.Score) return; From fa9daa68996e2ff9688458e36157689639dfdf0a Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 25 Jul 2022 05:21:27 +0300 Subject: [PATCH 025/278] Fix `TestSceneReplayRecorder` not using score provided by gameplay state --- .../Gameplay/TestSceneReplayRecorder.cs | 153 +++++++++--------- osu.Game/Screens/Play/GameplayState.cs | 1 + 2 files changed, 78 insertions(+), 76 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneReplayRecorder.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneReplayRecorder.cs index 54b2e66f2f..b3401c916b 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneReplayRecorder.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneReplayRecorder.cs @@ -3,10 +3,10 @@ #nullable disable +using System; using System.Collections.Generic; using System.Linq; using NUnit.Framework; -using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; @@ -40,8 +40,7 @@ namespace osu.Game.Tests.Visual.Gameplay private TestReplayRecorder recorder; - [Cached] - private GameplayState gameplayState = TestGameplayState.Create(new OsuRuleset()); + private GameplayState gameplayState; [SetUpSteps] public void SetUpSteps() @@ -52,81 +51,15 @@ namespace osu.Game.Tests.Visual.Gameplay { replay = new Replay(); - Add(new GridContainer + gameplayState = TestGameplayState.Create(new OsuRuleset()); + gameplayState.Score.Replay = replay; + + Child = new DependencyProvidingContainer { RelativeSizeAxes = Axes.Both, - Content = new[] - { - new Drawable[] - { - recordingManager = new TestRulesetInputManager(TestCustomisableModRuleset.CreateTestRulesetInfo(), 0, SimultaneousBindingMode.Unique) - { - Recorder = recorder = new TestReplayRecorder(new Score - { - Replay = replay, - ScoreInfo = - { - BeatmapInfo = gameplayState.Beatmap.BeatmapInfo, - Ruleset = new OsuRuleset().RulesetInfo, - } - }) - { - ScreenSpaceToGamefield = pos => recordingManager.ToLocalSpace(pos), - }, - Child = new Container - { - RelativeSizeAxes = Axes.Both, - Children = new Drawable[] - { - new Box - { - Colour = Color4.Brown, - RelativeSizeAxes = Axes.Both, - }, - new OsuSpriteText - { - Text = "Recording", - Scale = new Vector2(3), - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - }, - new TestInputConsumer() - } - }, - } - }, - new Drawable[] - { - playbackManager = new TestRulesetInputManager(TestCustomisableModRuleset.CreateTestRulesetInfo(), 0, SimultaneousBindingMode.Unique) - { - ReplayInputHandler = new TestFramedReplayInputHandler(replay) - { - GamefieldToScreenSpace = pos => playbackManager.ToScreenSpace(pos), - }, - Child = new Container - { - RelativeSizeAxes = Axes.Both, - Children = new Drawable[] - { - new Box - { - Colour = Color4.DarkBlue, - RelativeSizeAxes = Axes.Both, - }, - new OsuSpriteText - { - Text = "Playback", - Scale = new Vector2(3), - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - }, - new TestInputConsumer() - } - }, - } - } - } - }); + CachedDependencies = new (Type, object)[] { (typeof(GameplayState), gameplayState) }, + Child = createContent(), + }; }); } @@ -203,6 +136,74 @@ namespace osu.Game.Tests.Visual.Gameplay recorder = null; } + private Drawable createContent() => new GridContainer + { + RelativeSizeAxes = Axes.Both, + Content = new[] + { + new Drawable[] + { + recordingManager = new TestRulesetInputManager(TestCustomisableModRuleset.CreateTestRulesetInfo(), 0, SimultaneousBindingMode.Unique) + { + Recorder = recorder = new TestReplayRecorder(gameplayState.Score) + { + ScreenSpaceToGamefield = pos => recordingManager.ToLocalSpace(pos), + }, + Child = new Container + { + RelativeSizeAxes = Axes.Both, + Children = new Drawable[] + { + new Box + { + Colour = Color4.Brown, + RelativeSizeAxes = Axes.Both, + }, + new OsuSpriteText + { + Text = "Recording", + Scale = new Vector2(3), + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + }, + new TestInputConsumer() + } + }, + } + }, + new Drawable[] + { + playbackManager = new TestRulesetInputManager(TestCustomisableModRuleset.CreateTestRulesetInfo(), 0, SimultaneousBindingMode.Unique) + { + ReplayInputHandler = new TestFramedReplayInputHandler(replay) + { + GamefieldToScreenSpace = pos => playbackManager.ToScreenSpace(pos), + }, + Child = new Container + { + RelativeSizeAxes = Axes.Both, + Children = new Drawable[] + { + new Box + { + Colour = Color4.DarkBlue, + RelativeSizeAxes = Axes.Both, + }, + new OsuSpriteText + { + Text = "Playback", + Scale = new Vector2(3), + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + }, + new TestInputConsumer() + } + }, + } + } + } + }; + public class TestFramedReplayInputHandler : FramedReplayInputHandler { public TestFramedReplayInputHandler(Replay replay) diff --git a/osu.Game/Screens/Play/GameplayState.cs b/osu.Game/Screens/Play/GameplayState.cs index 9fb62106f3..c2162d4df2 100644 --- a/osu.Game/Screens/Play/GameplayState.cs +++ b/osu.Game/Screens/Play/GameplayState.cs @@ -70,6 +70,7 @@ namespace osu.Game.Screens.Play { ScoreInfo = { + BeatmapInfo = beatmap.BeatmapInfo, Ruleset = ruleset.RulesetInfo } }; From f68c4e889017b5dc9e4fa01fdd253bf13cf4681f Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 25 Jul 2022 06:36:21 +0300 Subject: [PATCH 026/278] Fix code formatting --- osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs index 52ed843c4c..e22ba5c1db 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs @@ -26,7 +26,7 @@ namespace osu.Game.Rulesets.Osu.Mods public override double ScoreMultiplier => 1; public override Type[] IncompatibleMods => new[] { typeof(OsuModTransform), typeof(OsuModMagnetised), typeof(OsuModRepel) }; - private const int wiggle_duration = 100; // (ms) Higher = fewer wiggles + private const int wiggle_duration = 100; // (ms) Higher = fewer wiggles [SettingSource("Strength", "Multiplier applied to the wiggling strength.")] public BindableDouble WiggleStrength { get; } = new BindableDouble(1) From 3d97b748131d2c581ce9e4bb1954e20c3a74cea7 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Mon, 25 Jul 2022 13:03:47 +0900 Subject: [PATCH 027/278] Log beatmap difficulty retrieval failures during score calculation --- osu.Game/Scoring/ScoreManager.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/osu.Game/Scoring/ScoreManager.cs b/osu.Game/Scoring/ScoreManager.cs index 9aed8904e6..7cfc55580b 100644 --- a/osu.Game/Scoring/ScoreManager.cs +++ b/osu.Game/Scoring/ScoreManager.cs @@ -12,6 +12,7 @@ using System.Threading.Tasks; using JetBrains.Annotations; using osu.Framework.Bindables; using osu.Framework.Extensions; +using osu.Framework.Logging; using osu.Framework.Platform; using osu.Framework.Threading; using osu.Game.Beatmaps; @@ -172,6 +173,10 @@ namespace osu.Game.Scoring // We can compute the max combo locally after the async beatmap difficulty computation. var difficulty = await difficultyCache.GetDifficultyAsync(score.BeatmapInfo, score.Ruleset, score.Mods, cancellationToken).ConfigureAwait(false); + + if (difficulty == null) + Logger.Log($"Couldn't get beatmap difficulty for beatmap {score.BeatmapInfo.OnlineID}"); + return difficulty?.MaxCombo; } From 0226b358eec2d3dd0fba037d178bb21011d1b8bf Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Mon, 25 Jul 2022 13:20:33 +0900 Subject: [PATCH 028/278] Disable timeline test for now --- osu.Game.Tests/Visual/Editing/TestSceneTimelineZoom.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneTimelineZoom.cs b/osu.Game.Tests/Visual/Editing/TestSceneTimelineZoom.cs index 6c5cca1874..09d753ba41 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneTimelineZoom.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneTimelineZoom.cs @@ -8,6 +8,7 @@ using osu.Framework.Graphics; namespace osu.Game.Tests.Visual.Editing { + [Ignore("Timeline initialisation is kinda broken.")] // Initial work to rectify this was done in https://github.com/ppy/osu/pull/19297, but needs more massaging to work. public class TestSceneTimelineZoom : TimelineTestScene { public override Drawable CreateTestComponent() => Empty(); From 54eb2b98a96b1d412cc790ba6a00516f01ca5dca Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 25 Jul 2022 07:30:52 +0300 Subject: [PATCH 029/278] Display exclamation triangle on scores with unprocessed PP --- .../Overlays/BeatmapSet/Scores/ScoreTable.cs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs b/osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs index 08f750827b..e9cb02406e 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs @@ -23,6 +23,7 @@ using osuTK.Graphics; using osu.Framework.Localisation; using osu.Framework.Extensions.LocalisationExtensions; using osu.Framework.Graphics.Cursor; +using osu.Framework.Graphics.Sprites; using osu.Game.Resources.Localisation.Web; namespace osu.Game.Overlays.BeatmapSet.Scores @@ -177,7 +178,12 @@ namespace osu.Game.Overlays.BeatmapSet.Scores } if (showPerformancePoints) - content.Add(new StatisticText(score.PP, format: @"N0")); + { + if (score.PP != null) + content.Add(new StatisticText(score.PP, format: @"N0")); + else + content.Add(new ProcessingPPIcon()); + } content.Add(new ScoreboardTime(score.Date, text_size) { @@ -241,5 +247,18 @@ namespace osu.Game.Overlays.BeatmapSet.Scores Colour = colours.GreenLight; } } + + private class ProcessingPPIcon : SpriteIcon, IHasTooltip + { + public LocalisableString TooltipText => ScoresStrings.StatusProcessing; + + public ProcessingPPIcon() + { + Anchor = Anchor.Centre; + Origin = Anchor.Centre; + Size = new Vector2(text_size); + Icon = FontAwesome.Solid.ExclamationTriangle; + } + } } } From 6c95c49da32924ac0321a46c733454a11c3746ee Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 25 Jul 2022 07:31:52 +0300 Subject: [PATCH 030/278] Mark test score with null PP for visual testing --- osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs index 864b2b6878..19acc8d7c0 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs @@ -210,7 +210,7 @@ namespace osu.Game.Tests.Visual.Online new APIMod { Acronym = new OsuModHidden().Acronym }, }, Rank = ScoreRank.B, - PP = 180, + PP = null, MaxCombo = 1234, TotalScore = 12345678, Accuracy = 0.9854, From 91d1c9686c0d970d131dc743a7d6922c55ff0495 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 25 Jul 2022 09:07:51 +0300 Subject: [PATCH 031/278] Separate unprocessed PP placeholder to own class --- .../Overlays/BeatmapSet/Scores/ScoreTable.cs | 17 ++---------- ...UnprocessedPerformancePointsPlaceholder.cs | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 osu.Game/Scoring/Drawables/UnprocessedPerformancePointsPlaceholder.cs diff --git a/osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs b/osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs index e9cb02406e..5463c7a50f 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs @@ -23,8 +23,8 @@ using osuTK.Graphics; using osu.Framework.Localisation; using osu.Framework.Extensions.LocalisationExtensions; using osu.Framework.Graphics.Cursor; -using osu.Framework.Graphics.Sprites; using osu.Game.Resources.Localisation.Web; +using osu.Game.Scoring.Drawables; namespace osu.Game.Overlays.BeatmapSet.Scores { @@ -182,7 +182,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores if (score.PP != null) content.Add(new StatisticText(score.PP, format: @"N0")); else - content.Add(new ProcessingPPIcon()); + content.Add(new UnprocessedPerformancePointsPlaceholder { Size = new Vector2(text_size) }); } content.Add(new ScoreboardTime(score.Date, text_size) @@ -247,18 +247,5 @@ namespace osu.Game.Overlays.BeatmapSet.Scores Colour = colours.GreenLight; } } - - private class ProcessingPPIcon : SpriteIcon, IHasTooltip - { - public LocalisableString TooltipText => ScoresStrings.StatusProcessing; - - public ProcessingPPIcon() - { - Anchor = Anchor.Centre; - Origin = Anchor.Centre; - Size = new Vector2(text_size); - Icon = FontAwesome.Solid.ExclamationTriangle; - } - } } } diff --git a/osu.Game/Scoring/Drawables/UnprocessedPerformancePointsPlaceholder.cs b/osu.Game/Scoring/Drawables/UnprocessedPerformancePointsPlaceholder.cs new file mode 100644 index 0000000000..6087ca9eb9 --- /dev/null +++ b/osu.Game/Scoring/Drawables/UnprocessedPerformancePointsPlaceholder.cs @@ -0,0 +1,27 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +#nullable disable +using osu.Framework.Graphics; +using osu.Framework.Graphics.Cursor; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Localisation; +using osu.Game.Resources.Localisation.Web; + +namespace osu.Game.Scoring.Drawables +{ + /// + /// A placeholder used in PP columns for scores with unprocessed PP value. + /// + public class UnprocessedPerformancePointsPlaceholder : SpriteIcon, IHasTooltip + { + public LocalisableString TooltipText => ScoresStrings.StatusProcessing; + + public UnprocessedPerformancePointsPlaceholder() + { + Anchor = Anchor.Centre; + Origin = Anchor.Centre; + Icon = FontAwesome.Solid.ExclamationTriangle; + } + } +} From f54cee027065eb30ff0c00e1957e075f0be59e45 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 25 Jul 2022 09:10:35 +0300 Subject: [PATCH 032/278] Display placeholder for leaderboard top scores --- .../Scores/TopScoreStatisticsSection.cs | 57 +++++++++++++------ 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/osu.Game/Overlays/BeatmapSet/Scores/TopScoreStatisticsSection.cs b/osu.Game/Overlays/BeatmapSet/Scores/TopScoreStatisticsSection.cs index 3b5ab811ae..653bfd6d2c 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/TopScoreStatisticsSection.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/TopScoreStatisticsSection.cs @@ -12,14 +12,17 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.UserInterface; using osu.Framework.Localisation; using osu.Game.Beatmaps; using osu.Game.Graphics; +using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; using osu.Game.Resources.Localisation.Web; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.UI; using osu.Game.Scoring; +using osu.Game.Scoring.Drawables; using osuTK; namespace osu.Game.Overlays.BeatmapSet.Scores @@ -121,7 +124,11 @@ namespace osu.Game.Overlays.BeatmapSet.Scores maxComboColumn.Text = value.MaxCombo.ToLocalisableString(@"0\x"); ppColumn.Alpha = value.BeatmapInfo.Status.GrantsPerformancePoints() ? 1 : 0; - ppColumn.Text = value.PP?.ToLocalisableString(@"N0") ?? default; + + if (value.PP is double pp) + ppColumn.Text = pp.ToLocalisableString(@"N0"); + else + ppColumn.Drawable = new UnprocessedPerformancePointsPlaceholder { Size = new Vector2(smallFont.Size) }; statisticsColumns.ChildrenEnumerable = value.GetStatisticsForDisplay().Select(createStatisticsColumn); modsColumn.Mods = value.Mods; @@ -197,30 +204,48 @@ namespace osu.Game.Overlays.BeatmapSet.Scores } } - private class TextColumn : InfoColumn + private class TextColumn : InfoColumn, IHasCurrentValue { - private readonly SpriteText text; - - public TextColumn(LocalisableString title, FontUsage font, float? minWidth = null) - : this(title, new OsuSpriteText { Font = font }, minWidth) - { - } - - private TextColumn(LocalisableString title, SpriteText text, float? minWidth = null) - : base(title, text, minWidth) - { - this.text = text; - } + private readonly OsuTextFlowContainer text; public LocalisableString Text { set => text.Text = value; } + public Drawable Drawable + { + set + { + text.Clear(); + text.AddArbitraryDrawable(value); + } + } + + private Bindable current; + public Bindable Current { - get => text.Current; - set => text.Current = value; + get => current; + set + { + text.Clear(); + text.AddText(value.Value, t => t.Current = current = value); + } + } + + public TextColumn(LocalisableString title, FontUsage font, float? minWidth = null) + : this(title, new OsuTextFlowContainer(t => t.Font = font) + { + AutoSizeAxes = Axes.Both + }, minWidth) + { + } + + private TextColumn(LocalisableString title, OsuTextFlowContainer text, float? minWidth = null) + : base(title, text, minWidth) + { + this.text = text; } } From bbbc0a863ff9b5f33b6720423569f58b0a6fc85d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 25 Jul 2022 15:21:24 +0900 Subject: [PATCH 033/278] Add test coverage of `WorkingBeatmap` retrieval from `BeatmapManager` --- .../Beatmaps/WorkingBeatmapManagerTest.cs | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 osu.Game.Tests/Beatmaps/WorkingBeatmapManagerTest.cs diff --git a/osu.Game.Tests/Beatmaps/WorkingBeatmapManagerTest.cs b/osu.Game.Tests/Beatmaps/WorkingBeatmapManagerTest.cs new file mode 100644 index 0000000000..0348e47d4a --- /dev/null +++ b/osu.Game.Tests/Beatmaps/WorkingBeatmapManagerTest.cs @@ -0,0 +1,100 @@ +// 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.Allocation; +using osu.Framework.Audio; +using osu.Framework.Extensions; +using osu.Framework.Platform; +using osu.Framework.Testing; +using osu.Game.Beatmaps; +using osu.Game.Database; +using osu.Game.Rulesets; +using osu.Game.Tests.Resources; +using osu.Game.Tests.Visual; + +namespace osu.Game.Tests.Beatmaps +{ + [HeadlessTest] + public class WorkingBeatmapManagerTest : OsuTestScene + { + private BeatmapManager beatmaps = null!; + + private BeatmapSetInfo importedSet = null!; + + [BackgroundDependencyLoader] + private void load(GameHost host, AudioManager audio, RulesetStore rulesets) + { + Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, rulesets, null, audio, Resources, host, Beatmap.Default)); + } + + [SetUpSteps] + public void SetUpSteps() + { + AddStep("import beatmap", () => + { + beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely(); + importedSet = beatmaps.GetAllUsableBeatmapSets().First(); + }); + } + + [Test] + public void TestGetWorkingBeatmap() => AddStep("run test", () => + { + Assert.That(beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First()), Is.Not.Null); + }); + + [Test] + public void TestCachedRetrievalNoFiles() => AddStep("run test", () => + { + var beatmap = importedSet.Beatmaps.First(); + + Assert.That(beatmap.BeatmapSet?.Files, Is.Empty); + + var first = beatmaps.GetWorkingBeatmap(beatmap); + var second = beatmaps.GetWorkingBeatmap(beatmap); + + Assert.That(first, Is.SameAs(second)); + Assert.That(first.BeatmapInfo.BeatmapSet?.Files, Has.Count.GreaterThan(0)); + }); + + [Test] + public void TestCachedRetrievalWithFiles() => AddStep("run test", () => + { + var beatmap = Realm.Run(r => r.Find(importedSet.Beatmaps.First().ID).Detach()); + + Assert.That(beatmap.BeatmapSet?.Files, Has.Count.GreaterThan(0)); + + var first = beatmaps.GetWorkingBeatmap(beatmap); + var second = beatmaps.GetWorkingBeatmap(beatmap); + + Assert.That(first, Is.SameAs(second)); + Assert.That(first.BeatmapInfo.BeatmapSet?.Files, Has.Count.GreaterThan(0)); + }); + + [Test] + public void TestForcedRefetchRetrievalNoFiles() => AddStep("run test", () => + { + var beatmap = importedSet.Beatmaps.First(); + + Assert.That(beatmap.BeatmapSet?.Files, Is.Empty); + + var first = beatmaps.GetWorkingBeatmap(beatmap); + var second = beatmaps.GetWorkingBeatmap(beatmap, true); + Assert.That(first, Is.Not.SameAs(second)); + }); + + [Test] + public void TestForcedRefetchRetrievalWithFiles() => AddStep("run test", () => + { + var beatmap = Realm.Run(r => r.Find(importedSet.Beatmaps.First().ID).Detach()); + + Assert.That(beatmap.BeatmapSet?.Files, Has.Count.GreaterThan(0)); + + var first = beatmaps.GetWorkingBeatmap(beatmap); + var second = beatmaps.GetWorkingBeatmap(beatmap, true); + Assert.That(first, Is.Not.SameAs(second)); + }); + } +} From 2ec90e37bb9e005dea4f99691758793a549ecd94 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 25 Jul 2022 14:59:11 +0900 Subject: [PATCH 034/278] Fix calls to `GetWorkingBeatmap` invalidating cache too often With recent changes, the pathway between refetching (on request) and refetching (on requirement due to unpopulated files) was combined. Unfortunately this pathway also added a forced invalidation, which should not have been applied to the second case. Closes https://github.com/ppy/osu/issues/19365. --- osu.Game/Beatmaps/BeatmapManager.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 30456afd2f..7717c9cc87 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -439,12 +439,15 @@ namespace osu.Game.Beatmaps { if (beatmapInfo != null) { - // Detached sets don't come with files. - // If we seem to be missing files, now is a good time to re-fetch. - if (refetch || beatmapInfo.IsManaged || beatmapInfo.BeatmapSet?.Files.Count == 0) - { + if (refetch) workingBeatmapCache.Invalidate(beatmapInfo); + // Detached beatmapsets don't come with files as an optimisation (see `RealmObjectExtensions.beatmap_set_mapper`). + // If we seem to be missing files, now is a good time to re-fetch. + bool missingFiles = beatmapInfo.BeatmapSet?.Files.Count == 0; + + if (refetch || beatmapInfo.IsManaged || missingFiles) + { Guid id = beatmapInfo.ID; beatmapInfo = Realm.Run(r => r.Find(id)?.Detach()) ?? beatmapInfo; } From e402e919ab4b2049e56338bdae7bff5a41348d82 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 25 Jul 2022 09:28:54 +0300 Subject: [PATCH 035/278] Display placeholder for user profile scores --- .../Overlays/Profile/Sections/Ranks/DrawableProfileScore.cs | 4 ++++ .../Profile/Sections/Ranks/DrawableProfileWeightedScore.cs | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/osu.Game/Overlays/Profile/Sections/Ranks/DrawableProfileScore.cs b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableProfileScore.cs index 5d8f8c8326..b8446c153d 100644 --- a/osu.Game/Overlays/Profile/Sections/Ranks/DrawableProfileScore.cs +++ b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableProfileScore.cs @@ -19,6 +19,7 @@ using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Leaderboards; using osu.Game.Rulesets; using osu.Game.Rulesets.UI; +using osu.Game.Scoring.Drawables; using osu.Game.Utils; using osuTK; @@ -246,6 +247,9 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks }; } + if (Score.Beatmap?.Status.GrantsPerformancePoints() == true) + return new UnprocessedPerformancePointsPlaceholder { Size = new Vector2(16), Colour = colourProvider.Highlight1 }; + return new OsuSpriteText { Font = OsuFont.GetFont(weight: FontWeight.Bold), diff --git a/osu.Game/Overlays/Profile/Sections/Ranks/DrawableProfileWeightedScore.cs b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableProfileWeightedScore.cs index 94d95dc27e..8c46f10ba2 100644 --- a/osu.Game/Overlays/Profile/Sections/Ranks/DrawableProfileWeightedScore.cs +++ b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableProfileWeightedScore.cs @@ -42,12 +42,11 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks CreateDrawableAccuracy(), new Container { - AutoSizeAxes = Axes.Y, - Width = 50, + Size = new Vector2(50, 14), Child = new OsuSpriteText { Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true), - Text = $"{Score.PP * weight:0}pp", + Text = Score.PP.HasValue ? $"{Score.PP * weight:0}pp" : string.Empty, }, } } From 6bdd1f43a294082ac7a586a05447c095b91b72ed Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 25 Jul 2022 09:28:59 +0300 Subject: [PATCH 036/278] Add visual test coverage --- .../Visual/Online/TestSceneScoresContainer.cs | 15 ++++++++++++++- .../Online/TestSceneUserProfileScores.cs | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs index 19acc8d7c0..cfa9f77634 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs @@ -141,6 +141,19 @@ namespace osu.Game.Tests.Visual.Online AddUntilStep("best score not displayed", () => scoresContainer.ChildrenOfType().Count() == 1); } + [Test] + public void TestUnprocessedPP() + { + AddStep("Load scores with unprocessed PP", () => + { + var allScores = createScores(); + allScores.Scores[0].PP = null; + allScores.UserScore = createUserBest(); + allScores.UserScore.Score.PP = null; + scoresContainer.Scores = allScores; + }); + } + private int onlineID = 1; private APIScoresCollection createScores() @@ -210,7 +223,7 @@ namespace osu.Game.Tests.Visual.Online new APIMod { Acronym = new OsuModHidden().Acronym }, }, Rank = ScoreRank.B, - PP = null, + PP = 180, MaxCombo = 1234, TotalScore = 12345678, Accuracy = 0.9854, diff --git a/osu.Game.Tests/Visual/Online/TestSceneUserProfileScores.cs b/osu.Game.Tests/Visual/Online/TestSceneUserProfileScores.cs index 0eb6ec3c04..4bbb72c862 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneUserProfileScores.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneUserProfileScores.cs @@ -7,6 +7,7 @@ using System; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Game.Beatmaps; using osu.Game.Online.API; using osu.Game.Online.API.Requests.Responses; using osu.Game.Overlays; @@ -99,6 +100,23 @@ namespace osu.Game.Tests.Visual.Online Accuracy = 0.55879 }; + var unprocessedPPScore = new SoloScoreInfo + { + Rank = ScoreRank.B, + Beatmap = new APIBeatmap + { + BeatmapSet = new APIBeatmapSet + { + Title = "C18H27NO3(extend)", + Artist = "Team Grimoire", + }, + DifficultyName = "[4K] Cataclysmic Hypernova", + Status = BeatmapOnlineStatus.Ranked, + }, + EndedAt = DateTimeOffset.Now, + Accuracy = 0.55879 + }; + Add(new FillFlowContainer { Anchor = Anchor.Centre, @@ -112,6 +130,7 @@ namespace osu.Game.Tests.Visual.Online new ColourProvidedContainer(OverlayColourScheme.Green, new DrawableProfileScore(firstScore)), new ColourProvidedContainer(OverlayColourScheme.Green, new DrawableProfileScore(secondScore)), new ColourProvidedContainer(OverlayColourScheme.Pink, new DrawableProfileScore(noPPScore)), + new ColourProvidedContainer(OverlayColourScheme.Pink, new DrawableProfileScore(unprocessedPPScore)), new ColourProvidedContainer(OverlayColourScheme.Pink, new DrawableProfileWeightedScore(firstScore, 0.97)), new ColourProvidedContainer(OverlayColourScheme.Pink, new DrawableProfileWeightedScore(secondScore, 0.85)), new ColourProvidedContainer(OverlayColourScheme.Pink, new DrawableProfileWeightedScore(thirdScore, 0.66)), From 6bf2645b1ae4639bda41bcc825741d1c5a3ae34a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 25 Jul 2022 15:44:54 +0900 Subject: [PATCH 037/278] Fix `StarRatingDisplay` not handling negative numbers as "pending" --- .../Visual/UserInterface/TestSceneStarRatingDisplay.cs | 2 +- osu.Game/Beatmaps/Drawables/StarRatingDisplay.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneStarRatingDisplay.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneStarRatingDisplay.cs index 1f65b6ec7f..72929a4555 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneStarRatingDisplay.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneStarRatingDisplay.cs @@ -29,7 +29,7 @@ namespace osu.Game.Tests.Visual.UserInterface AutoSizeAxes = Axes.Both, Spacing = new Vector2(2f), Direction = FillDirection.Horizontal, - ChildrenEnumerable = Enumerable.Range(0, 15).Select(i => new FillFlowContainer + ChildrenEnumerable = Enumerable.Range(-1, 15).Select(i => new FillFlowContainer { Anchor = Anchor.Centre, Origin = Anchor.Centre, diff --git a/osu.Game/Beatmaps/Drawables/StarRatingDisplay.cs b/osu.Game/Beatmaps/Drawables/StarRatingDisplay.cs index 44bccd69d0..9585f1bdb5 100644 --- a/osu.Game/Beatmaps/Drawables/StarRatingDisplay.cs +++ b/osu.Game/Beatmaps/Drawables/StarRatingDisplay.cs @@ -151,7 +151,7 @@ namespace osu.Game.Beatmaps.Drawables displayedStars.BindValueChanged(s => { - starsText.Text = s.NewValue.ToLocalisableString("0.00"); + starsText.Text = s.NewValue < 0 ? "-" : s.NewValue.ToLocalisableString("0.00"); background.Colour = colours.ForStarDifficulty(s.NewValue); From 4d90e6bbac73e242fb61eeae70b4c6818f4f14c7 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 25 Jul 2022 10:03:06 +0300 Subject: [PATCH 038/278] Flip method to read better --- .../Sections/Ranks/DrawableProfileScore.cs | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/osu.Game/Overlays/Profile/Sections/Ranks/DrawableProfileScore.cs b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableProfileScore.cs index b8446c153d..fda2db7acc 100644 --- a/osu.Game/Overlays/Profile/Sections/Ranks/DrawableProfileScore.cs +++ b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableProfileScore.cs @@ -219,42 +219,42 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks private Drawable createDrawablePerformance() { - if (Score.PP.HasValue) + if (!Score.PP.HasValue) { - return new FillFlowContainer + if (Score.Beatmap?.Status.GrantsPerformancePoints() == true) + return new UnprocessedPerformancePointsPlaceholder { Size = new Vector2(16), Colour = colourProvider.Highlight1 }; + + return new OsuSpriteText { - AutoSizeAxes = Axes.Both, - Direction = FillDirection.Horizontal, - Children = new[] - { - new OsuSpriteText - { - Anchor = Anchor.BottomLeft, - Origin = Anchor.BottomLeft, - Font = OsuFont.GetFont(weight: FontWeight.Bold), - Text = $"{Score.PP:0}", - Colour = colourProvider.Highlight1 - }, - new OsuSpriteText - { - Anchor = Anchor.BottomLeft, - Origin = Anchor.BottomLeft, - Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold), - Text = "pp", - Colour = colourProvider.Light3 - } - } + Font = OsuFont.GetFont(weight: FontWeight.Bold), + Text = "-", + Colour = colourProvider.Highlight1 }; } - if (Score.Beatmap?.Status.GrantsPerformancePoints() == true) - return new UnprocessedPerformancePointsPlaceholder { Size = new Vector2(16), Colour = colourProvider.Highlight1 }; - - return new OsuSpriteText + return new FillFlowContainer { - Font = OsuFont.GetFont(weight: FontWeight.Bold), - Text = "-", - Colour = colourProvider.Highlight1 + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + Children = new[] + { + new OsuSpriteText + { + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + Font = OsuFont.GetFont(weight: FontWeight.Bold), + Text = $"{Score.PP:0}", + Colour = colourProvider.Highlight1 + }, + new OsuSpriteText + { + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold), + Text = "pp", + Colour = colourProvider.Light3 + } + } }; } From 2dd99ef1fdc835fd14297371a159d94af8f7c9d0 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 25 Jul 2022 16:26:47 +0900 Subject: [PATCH 039/278] Refactor `FPSCounter` to not use scheduled tasks While on the surface this looks harmless (ignoring allocations), `Scheduler` doesn't clear cancelled tasks until they reach their execution time. This can cause an increase in time spent processing the scheduler itself. I don't think a per-frame updating component should use scheduled tasks in this way in the first place, so I've just rewritten the logic to avoid that overhead altogether. --- osu.Game/Graphics/UserInterface/FPSCounter.cs | 55 +++++++++---------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/FPSCounter.cs b/osu.Game/Graphics/UserInterface/FPSCounter.cs index 6fa53b32d8..539ac7ed1f 100644 --- a/osu.Game/Graphics/UserInterface/FPSCounter.cs +++ b/osu.Game/Graphics/UserInterface/FPSCounter.cs @@ -11,7 +11,6 @@ using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Shapes; using osu.Framework.Input.Events; using osu.Framework.Platform; -using osu.Framework.Threading; using osu.Framework.Timing; using osu.Framework.Utils; using osu.Game.Configuration; @@ -44,8 +43,6 @@ namespace osu.Game.Graphics.UserInterface private bool isDisplayed; - private ScheduledDelegate? fadeOutDelegate; - private double aimDrawFPS; private double aimUpdateFPS; @@ -54,6 +51,11 @@ namespace osu.Game.Graphics.UserInterface private ThrottledFrameClock updateClock = null!; private ThrottledFrameClock inputClock = null!; + /// + /// The last time value where the display was required (due to a significant change or hovering). + /// + private double lastDisplayRequiredTime; + [Resolved] private OsuColour colours { get; set; } = null!; @@ -131,13 +133,13 @@ namespace osu.Game.Graphics.UserInterface { base.LoadComplete(); - displayTemporarily(); + requestDisplay(); showFpsDisplay.BindValueChanged(showFps => { State.Value = showFps.NewValue ? Visibility.Visible : Visibility.Hidden; if (showFps.NewValue) - displayTemporarily(); + requestDisplay(); }, true); State.BindValueChanged(state => showFpsDisplay.Value = state.NewValue == Visibility.Visible); @@ -150,38 +152,17 @@ namespace osu.Game.Graphics.UserInterface protected override bool OnHover(HoverEvent e) { background.FadeTo(1, 200); - displayTemporarily(); + requestDisplay(); return base.OnHover(e); } protected override void OnHoverLost(HoverLostEvent e) { background.FadeTo(idle_background_alpha, 200); - displayTemporarily(); + requestDisplay(); base.OnHoverLost(e); } - private void displayTemporarily() - { - if (!isDisplayed) - { - mainContent.FadeTo(1, 300, Easing.OutQuint); - isDisplayed = true; - } - - fadeOutDelegate?.Cancel(); - fadeOutDelegate = null; - - if (!IsHovered) - { - fadeOutDelegate = Scheduler.AddDelayed(() => - { - mainContent.FadeTo(0, 300, Easing.OutQuint); - isDisplayed = false; - }, 2000); - } - } - protected override void Update() { base.Update(); @@ -221,7 +202,23 @@ namespace osu.Game.Graphics.UserInterface || 1000 / displayedFrameTime < aimUpdateFPS * 0.8; if (hasSignificantChanges) - displayTemporarily(); + requestDisplay(); + else if (isDisplayed && Time.Current - lastDisplayRequiredTime > 2000) + { + mainContent.FadeTo(0, 300, Easing.OutQuint); + isDisplayed = false; + } + } + + private void requestDisplay() + { + lastDisplayRequiredTime = Time.Current; + + if (!isDisplayed) + { + mainContent.FadeTo(1, 300, Easing.OutQuint); + isDisplayed = true; + } } private void updateFpsDisplay() From fcf767e28bc4d68d97a0137358016261a7255cee Mon Sep 17 00:00:00 2001 From: Andrew Hong Date: Mon, 25 Jul 2022 04:07:33 -0400 Subject: [PATCH 040/278] Add contextmenu to beatmap external link --- .../UserInterface/ExternalLinkButton.cs | 17 +- .../BeatmapSet/BeatmapSetHeaderContent.cs | 184 +++++++++--------- 2 files changed, 110 insertions(+), 91 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs b/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs index ae286f5092..4c54e45a50 100644 --- a/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs +++ b/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs @@ -3,10 +3,12 @@ #nullable disable +using System.Collections.Generic; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Cursor; +using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.Sprites; using osu.Framework.Input.Events; using osu.Framework.Localisation; @@ -16,7 +18,7 @@ using osuTK.Graphics; namespace osu.Game.Graphics.UserInterface { - public class ExternalLinkButton : CompositeDrawable, IHasTooltip + public class ExternalLinkButton : CompositeDrawable, IHasTooltip, IHasContextMenu { public string Link { get; set; } @@ -41,6 +43,19 @@ namespace osu.Game.Graphics.UserInterface new HoverClickSounds() }; } + + public MenuItem[] ContextMenuItems + { + get + { + List items = new List + { + new OsuMenuItem("Copy URL", MenuItemType.Standard, () => host.GetClipboard()?.SetText(Link)) + }; + + return items.ToArray(); + } + } [BackgroundDependencyLoader] private void load(OsuColour colours) diff --git a/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs b/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs index c9e97d5f2f..85b98a92e2 100644 --- a/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs +++ b/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs @@ -9,6 +9,7 @@ using osu.Framework.Bindables; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Colour; +using osu.Game.Graphics.Cursor; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Localisation; @@ -90,113 +91,116 @@ namespace osu.Game.Overlays.BeatmapSet }, }, }, - new Container + new OsuContextMenuContainer { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Padding = new MarginPadding + RelativeSizeAxes = Axes.Both, + Child = new Container { - Vertical = BeatmapSetOverlay.Y_PADDING, - Left = BeatmapSetOverlay.X_PADDING, - Right = BeatmapSetOverlay.X_PADDING + BeatmapSetOverlay.RIGHT_WIDTH, - }, - Children = new Drawable[] - { - fadeContent = new FillFlowContainer + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Padding = new MarginPadding { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Direction = FillDirection.Vertical, - Children = new Drawable[] + Vertical = BeatmapSetOverlay.Y_PADDING, + Left = BeatmapSetOverlay.X_PADDING, + Right = BeatmapSetOverlay.X_PADDING + BeatmapSetOverlay.RIGHT_WIDTH, + }, + Children = new Drawable[] + { + fadeContent = new FillFlowContainer { - new Container + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Direction = FillDirection.Vertical, + Children = new Drawable[] { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Child = Picker = new BeatmapPicker(), - }, - new FillFlowContainer - { - Direction = FillDirection.Horizontal, - AutoSizeAxes = Axes.Both, - Margin = new MarginPadding { Top = 15 }, - Children = new Drawable[] + new Container { - title = new OsuSpriteText + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Child = Picker = new BeatmapPicker(), + }, + new FillFlowContainer + { + Direction = FillDirection.Horizontal, + AutoSizeAxes = Axes.Both, + Margin = new MarginPadding { Top = 15 }, + Children = new Drawable[] { - Font = OsuFont.GetFont(size: 30, weight: FontWeight.SemiBold, italics: true) - }, - externalLink = new ExternalLinkButton - { - Anchor = Anchor.BottomLeft, - Origin = Anchor.BottomLeft, - Margin = new MarginPadding { Left = 5, Bottom = 4 }, // To better lineup with the font - }, - explicitContent = new ExplicitContentBeatmapBadge - { - Alpha = 0f, - Anchor = Anchor.BottomLeft, - Origin = Anchor.BottomLeft, - Margin = new MarginPadding { Left = 10, Bottom = 4 }, - }, - spotlight = new SpotlightBeatmapBadge - { - Alpha = 0f, - Anchor = Anchor.BottomLeft, - Origin = Anchor.BottomLeft, - Margin = new MarginPadding { Left = 10, Bottom = 4 }, + title = new OsuSpriteText + { + Font = OsuFont.GetFont(size: 30, weight: FontWeight.SemiBold, italics: true) + }, + externalLink = new ExternalLinkButton { + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + Margin = new MarginPadding { Left = 5, Bottom = 4 }, // To better lineup with the font + }, + explicitContent = new ExplicitContentBeatmapBadge + { + Alpha = 0f, + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + Margin = new MarginPadding { Left = 10, Bottom = 4 }, + }, + spotlight = new SpotlightBeatmapBadge + { + Alpha = 0f, + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + Margin = new MarginPadding { Left = 10, Bottom = 4 }, + } } - } - }, - new FillFlowContainer - { - Direction = FillDirection.Horizontal, - AutoSizeAxes = Axes.Both, - Margin = new MarginPadding { Bottom = 20 }, - Children = new Drawable[] + }, + new FillFlowContainer { - artist = new OsuSpriteText + Direction = FillDirection.Horizontal, + AutoSizeAxes = Axes.Both, + Margin = new MarginPadding { Bottom = 20 }, + Children = new Drawable[] { - Font = OsuFont.GetFont(size: 20, weight: FontWeight.Medium, italics: true), - }, - featuredArtist = new FeaturedArtistBeatmapBadge - { - Alpha = 0f, - Anchor = Anchor.BottomLeft, - Origin = Anchor.BottomLeft, - Margin = new MarginPadding { Left = 10 } + artist = new OsuSpriteText + { + Font = OsuFont.GetFont(size: 20, weight: FontWeight.Medium, italics: true), + }, + featuredArtist = new FeaturedArtistBeatmapBadge + { + Alpha = 0f, + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + Margin = new MarginPadding { Left = 10 } + } } - } - }, - new Container - { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Child = author = new AuthorInfo(), - }, - beatmapAvailability = new BeatmapAvailability(), - new Container - { - RelativeSizeAxes = Axes.X, - Height = buttons_height, - Margin = new MarginPadding { Top = 10 }, - Children = new Drawable[] + }, + new Container { - favouriteButton = new FavouriteButton + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Child = author = new AuthorInfo(), + }, + beatmapAvailability = new BeatmapAvailability(), + new Container + { + RelativeSizeAxes = Axes.X, + Height = buttons_height, + Margin = new MarginPadding { Top = 10 }, + Children = new Drawable[] { - BeatmapSet = { BindTarget = BeatmapSet } - }, - downloadButtonsContainer = new FillFlowContainer - { - RelativeSizeAxes = Axes.Both, - Padding = new MarginPadding { Left = buttons_height + buttons_spacing }, - Spacing = new Vector2(buttons_spacing), + favouriteButton = new FavouriteButton + { + BeatmapSet = { BindTarget = BeatmapSet } + }, + downloadButtonsContainer = new FillFlowContainer + { + RelativeSizeAxes = Axes.Both, + Padding = new MarginPadding { Left = buttons_height + buttons_spacing }, + Spacing = new Vector2(buttons_spacing), + }, }, }, }, }, - }, - } + } + }, }, loading = new LoadingSpinner { From f1534da683623e65f74019d62983d28bd2391a32 Mon Sep 17 00:00:00 2001 From: Andrew Hong Date: Mon, 25 Jul 2022 04:13:05 -0400 Subject: [PATCH 041/278] Formatting issues --- osu.Game/Graphics/UserInterface/ExternalLinkButton.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs b/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs index 4c54e45a50..e813e2d8e8 100644 --- a/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs +++ b/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs @@ -43,7 +43,7 @@ namespace osu.Game.Graphics.UserInterface new HoverClickSounds() }; } - + public MenuItem[] ContextMenuItems { get From 93175eaf6efda8c782557c8624b4cc23f2075c66 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 25 Jul 2022 11:39:23 +0300 Subject: [PATCH 042/278] Re-enable timeline zoom test and remove flaky attribute --- .../Visual/Editing/TestSceneTimelineZoom.cs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneTimelineZoom.cs b/osu.Game.Tests/Visual/Editing/TestSceneTimelineZoom.cs index 09d753ba41..11ac102814 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneTimelineZoom.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneTimelineZoom.cs @@ -8,22 +8,11 @@ using osu.Framework.Graphics; namespace osu.Game.Tests.Visual.Editing { - [Ignore("Timeline initialisation is kinda broken.")] // Initial work to rectify this was done in https://github.com/ppy/osu/pull/19297, but needs more massaging to work. public class TestSceneTimelineZoom : TimelineTestScene { public override Drawable CreateTestComponent() => Empty(); [Test] - [FlakyTest] - /* - * Fail rate around 0.3% - * - * TearDown : osu.Framework.Testing.Drawables.Steps.AssertButton+TracedException : range halved - * --TearDown - * at osu.Framework.Threading.ScheduledDelegate.RunTaskInternal() - * at osu.Framework.Threading.Scheduler.Update() - * at osu.Framework.Graphics.Drawable.UpdateSubTree() - */ public void TestVisibleRangeUpdatesOnZoomChange() { double initialVisibleRange = 0; From 123930306bc0146f52273f66e26f5c2c5e48f6e2 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 25 Jul 2022 11:54:10 +0300 Subject: [PATCH 043/278] Refactor `ZoomableScrollContainer` to allow setting up zoom range and initial zoom after load --- .../TestSceneZoomableScrollContainer.cs | 17 +--- .../Timeline/ZoomableScrollContainer.cs | 99 ++++++++++--------- 2 files changed, 56 insertions(+), 60 deletions(-) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneZoomableScrollContainer.cs b/osu.Game.Tests/Visual/Editing/TestSceneZoomableScrollContainer.cs index 9dc403814b..ce418f33f0 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneZoomableScrollContainer.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneZoomableScrollContainer.cs @@ -46,7 +46,7 @@ namespace osu.Game.Tests.Visual.Editing RelativeSizeAxes = Axes.Both, Colour = OsuColour.Gray(30) }, - scrollContainer = new ZoomableScrollContainer + scrollContainer = new ZoomableScrollContainer(1, 60, 1) { Anchor = Anchor.Centre, Origin = Anchor.Centre, @@ -80,21 +80,6 @@ namespace osu.Game.Tests.Visual.Editing AddAssert("Inner container width matches scroll container", () => innerBox.DrawWidth == scrollContainer.DrawWidth); } - [Test] - public void TestZoomRangeUpdate() - { - AddStep("set zoom to 2", () => scrollContainer.Zoom = 2); - AddStep("set min zoom to 5", () => scrollContainer.MinZoom = 5); - AddAssert("zoom = 5", () => scrollContainer.Zoom == 5); - - AddStep("set max zoom to 10", () => scrollContainer.MaxZoom = 10); - AddAssert("zoom = 5", () => scrollContainer.Zoom == 5); - - AddStep("set min zoom to 20", () => scrollContainer.MinZoom = 20); - AddStep("set max zoom to 40", () => scrollContainer.MaxZoom = 40); - AddAssert("zoom = 20", () => scrollContainer.Zoom == 20); - } - [Test] public void TestZoom0() { diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/ZoomableScrollContainer.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/ZoomableScrollContainer.cs index 83fd1dea2b..fb2297e88c 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/ZoomableScrollContainer.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/ZoomableScrollContainer.cs @@ -32,19 +32,27 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline private readonly Container zoomedContent; protected override Container Content => zoomedContent; - private float currentZoom = 1; /// - /// The current zoom level of . - /// It may differ from during transitions. + /// The current zoom level of . + /// It may differ from during transitions. /// - public float CurrentZoom => currentZoom; + public float CurrentZoom { get; private set; } = 1; + + private bool isZoomSetUp; [Resolved(canBeNull: true)] private IFrameBasedClock editorClock { get; set; } private readonly LayoutValue zoomedContentWidthCache = new LayoutValue(Invalidation.DrawSize); + private float minZoom; + private float maxZoom; + + /// + /// Creates a with no zoom range. + /// Functionality will be disabled until zoom is set up via . + /// public ZoomableScrollContainer() : base(Direction.Horizontal) { @@ -53,46 +61,36 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline AddLayout(zoomedContentWidthCache); } - private float minZoom = 1; - /// - /// The minimum zoom level allowed. + /// Creates a with a defined zoom range. /// - public float MinZoom + public ZoomableScrollContainer(float minimum, float maximum, float initial) + : this() { - get => minZoom; - set - { - if (value < 1) - throw new ArgumentException($"{nameof(MinZoom)} must be >= 1.", nameof(value)); - - minZoom = value; - - // ensure zoom range is in valid state before updating zoom. - if (MinZoom < MaxZoom) - updateZoom(); - } + SetupZoom(initial, minimum, maximum); } - private float maxZoom = 60; - /// - /// The maximum zoom level allowed. + /// Sets up the minimum and maximum range of this zoomable scroll container, along with the initial zoom value. /// - public float MaxZoom + /// The initial zoom value, applied immediately. + /// The minimum zoom value. + /// The maximum zoom value. + public void SetupZoom(float initial, float minimum, float maximum) { - get => maxZoom; - set - { - if (value < 1) - throw new ArgumentException($"{nameof(MaxZoom)} must be >= 1.", nameof(value)); + if (minimum < 1) + throw new ArgumentException($"{nameof(minimum)} ({minimum}) must be >= 1.", nameof(maximum)); - maxZoom = value; + if (maximum < 1) + throw new ArgumentException($"{nameof(maximum)} ({maximum}) must be >= 1.", nameof(maximum)); - // ensure zoom range is in valid state before updating zoom. - if (MaxZoom > MinZoom) - updateZoom(); - } + if (minimum > maximum) + throw new ArgumentException($"{nameof(minimum)} ({minimum}) must be less than {nameof(maximum)} ({maximum})"); + + minZoom = minimum; + maxZoom = maximum; + CurrentZoom = zoomTarget = initial; + isZoomSetUp = true; } /// @@ -104,14 +102,17 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline set => updateZoom(value); } - private void updateZoom(float? value = null) + private void updateZoom(float value) { - float newZoom = Math.Clamp(value ?? Zoom, MinZoom, MaxZoom); + if (!isZoomSetUp) + return; + + float newZoom = Math.Clamp(value, minZoom, maxZoom); if (IsLoaded) setZoomTarget(newZoom, ToSpaceOfOtherDrawable(new Vector2(DrawWidth / 2, 0), zoomedContent).X); else - currentZoom = zoomTarget = newZoom; + CurrentZoom = zoomTarget = newZoom; } protected override void Update() @@ -141,22 +142,32 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline private void updateZoomedContentWidth() { - zoomedContent.Width = DrawWidth * currentZoom; + zoomedContent.Width = DrawWidth * CurrentZoom; zoomedContentWidthCache.Validate(); } public void AdjustZoomRelatively(float change, float? focusPoint = null) { + if (!isZoomSetUp) + return; + const float zoom_change_sensitivity = 0.02f; - setZoomTarget(zoomTarget + change * (MaxZoom - minZoom) * zoom_change_sensitivity, focusPoint); + setZoomTarget(zoomTarget + change * (maxZoom - minZoom) * zoom_change_sensitivity, focusPoint); + } + + protected void SetZoomImmediately(float value, float min, float max) + { + maxZoom = max; + minZoom = min; + CurrentZoom = zoomTarget = value; } private float zoomTarget = 1; private void setZoomTarget(float newZoom, float? focusPoint = null) { - zoomTarget = Math.Clamp(newZoom, MinZoom, MaxZoom); + zoomTarget = Math.Clamp(newZoom, minZoom, maxZoom); focusPoint ??= zoomedContent.ToLocalSpace(ToScreenSpace(new Vector2(DrawWidth / 2, 0))).X; transformZoomTo(zoomTarget, focusPoint.Value, ZoomDuration, ZoomEasing); @@ -192,7 +203,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline private readonly float scrollOffset; /// - /// Transforms to a new value. + /// Transforms to a new value. /// /// The focus point in absolute coordinates local to the content. /// The size of the content. @@ -204,7 +215,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline this.scrollOffset = scrollOffset; } - public override string TargetMember => nameof(currentZoom); + public override string TargetMember => nameof(CurrentZoom); private float valueAt(double time) { @@ -222,7 +233,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline float expectedWidth = d.DrawWidth * newZoom; float targetOffset = expectedWidth * (focusPoint / contentSize) - focusOffset; - d.currentZoom = newZoom; + d.CurrentZoom = newZoom; d.updateZoomedContentWidth(); // Temporarily here to make sure ScrollTo gets the correct DrawSize for scrollable area. @@ -231,7 +242,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline d.ScrollTo(targetOffset, false); } - protected override void ReadIntoStartValue(ZoomableScrollContainer d) => StartValue = d.currentZoom; + protected override void ReadIntoStartValue(ZoomableScrollContainer d) => StartValue = d.CurrentZoom; } } } From 07c6b4486491848b358f1a2e8c8de56523cc62e3 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 25 Jul 2022 11:54:47 +0300 Subject: [PATCH 044/278] Fix `Timeline` attempting to setup zoom with unloaded track --- .../Compose/Components/Timeline/Timeline.cs | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/Timeline.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/Timeline.cs index bbe011a2e0..54f2d13707 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/Timeline.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/Timeline.cs @@ -146,13 +146,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline waveform.Waveform = b.NewValue.Waveform; track = b.NewValue.Track; - // todo: i don't think this is safe, the track may not be loaded yet. - if (track.Length > 0) - { - MaxZoom = getZoomLevelForVisibleMilliseconds(500); - MinZoom = getZoomLevelForVisibleMilliseconds(10000); - defaultTimelineZoom = getZoomLevelForVisibleMilliseconds(6000); - } + setupTimelineZoom(); }, true); Zoom = (float)(defaultTimelineZoom * editorBeatmap.BeatmapInfo.TimelineZoom); @@ -205,6 +199,20 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline scrollToTrackTime(); } + private void setupTimelineZoom() + { + if (!track.IsLoaded) + { + Scheduler.AddOnce(setupTimelineZoom); + return; + } + + defaultTimelineZoom = getZoomLevelForVisibleMilliseconds(6000); + + float initialZoom = (float)(defaultTimelineZoom * editorBeatmap.BeatmapInfo.TimelineZoom); + SetupZoom(initialZoom, getZoomLevelForVisibleMilliseconds(10000), getZoomLevelForVisibleMilliseconds(500)); + } + protected override bool OnScroll(ScrollEvent e) { // if this is not a precision scroll event, let the editor handle the seek itself (for snapping support) From bc2b629ee7c89ec71dfbac7d11bd36adfdc4bb8a Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 25 Jul 2022 11:43:34 +0300 Subject: [PATCH 045/278] Let tests wait until track load before testing zoom --- osu.Game.Tests/Visual/Editing/TestSceneTimelineZoom.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneTimelineZoom.cs b/osu.Game.Tests/Visual/Editing/TestSceneTimelineZoom.cs index 11ac102814..630d048867 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneTimelineZoom.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneTimelineZoom.cs @@ -17,6 +17,8 @@ namespace osu.Game.Tests.Visual.Editing { double initialVisibleRange = 0; + AddUntilStep("wait for load", () => MusicController.TrackLoaded); + AddStep("reset zoom", () => TimelineArea.Timeline.Zoom = 100); AddStep("get initial range", () => initialVisibleRange = TimelineArea.Timeline.VisibleRange); @@ -34,6 +36,8 @@ namespace osu.Game.Tests.Visual.Editing { double initialVisibleRange = 0; + AddUntilStep("wait for load", () => MusicController.TrackLoaded); + AddStep("reset timeline size", () => TimelineArea.Timeline.Width = 1); AddStep("get initial range", () => initialVisibleRange = TimelineArea.Timeline.VisibleRange); From 48bcf57066f1b5f67e0849a3cac9a9c8e4feb8bc Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 25 Jul 2022 12:06:54 +0300 Subject: [PATCH 046/278] Mark `SetupZoom` and parameterless `ZoomableScrollContainer` ctor as protected --- .../Compose/Components/Timeline/ZoomableScrollContainer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/ZoomableScrollContainer.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/ZoomableScrollContainer.cs index fb2297e88c..725f94e7db 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/ZoomableScrollContainer.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/ZoomableScrollContainer.cs @@ -53,7 +53,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline /// Creates a with no zoom range. /// Functionality will be disabled until zoom is set up via . /// - public ZoomableScrollContainer() + protected ZoomableScrollContainer() : base(Direction.Horizontal) { base.Content.Add(zoomedContent = new Container { RelativeSizeAxes = Axes.Y }); @@ -76,7 +76,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline /// The initial zoom value, applied immediately. /// The minimum zoom value. /// The maximum zoom value. - public void SetupZoom(float initial, float minimum, float maximum) + protected void SetupZoom(float initial, float minimum, float maximum) { if (minimum < 1) throw new ArgumentException($"{nameof(minimum)} ({minimum}) must be >= 1.", nameof(maximum)); From d04df19c7e2ba81107cac71df5435d5cd016f504 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 25 Jul 2022 13:03:06 +0300 Subject: [PATCH 047/278] Remove `APIScore` and replace its final usage --- .../Gameplay/TestSceneReplayDownloadButton.cs | 28 ++- .../Online/API/Requests/Responses/APIScore.cs | 162 ------------------ osu.Game/Online/Solo/SubmittableScore.cs | 2 - 3 files changed, 10 insertions(+), 182 deletions(-) delete mode 100644 osu.Game/Online/API/Requests/Responses/APIScore.cs diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneReplayDownloadButton.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneReplayDownloadButton.cs index c259d5f0a8..1384d4ef6e 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneReplayDownloadButton.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneReplayDownloadButton.cs @@ -7,7 +7,6 @@ using System.Linq; using NUnit.Framework; using osu.Framework.Graphics; using osu.Game.Online; -using osu.Game.Online.API.Requests.Responses; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Extensions; @@ -15,7 +14,6 @@ using osu.Framework.Testing; using osu.Game.Beatmaps; using osu.Game.Database; using osu.Game.Graphics.UserInterface; -using osu.Game.Rulesets; using osu.Game.Rulesets.Osu; using osu.Game.Scoring; using osu.Game.Screens.Ranking; @@ -30,9 +28,6 @@ namespace osu.Game.Tests.Visual.Gameplay { private const long online_score_id = 2553163309; - [Resolved] - private RulesetStore rulesets { get; set; } - private TestReplayDownloadButton downloadButton; [Resolved] @@ -211,21 +206,18 @@ namespace osu.Game.Tests.Visual.Gameplay AddAssert("button is not enabled", () => !downloadButton.ChildrenOfType().First().Enabled.Value); } - private ScoreInfo getScoreInfo(bool replayAvailable, bool hasOnlineId = true) + private ScoreInfo getScoreInfo(bool replayAvailable, bool hasOnlineId = true) => new ScoreInfo { - return new APIScore + OnlineID = hasOnlineId ? online_score_id : 0, + Ruleset = new OsuRuleset().RulesetInfo, + BeatmapInfo = beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps.First(), + Hash = replayAvailable ? "hash" : string.Empty, + User = new APIUser { - OnlineID = hasOnlineId ? online_score_id : 0, - RulesetID = 0, - Beatmap = CreateAPIBeatmapSet(new OsuRuleset().RulesetInfo).Beatmaps.First(), - HasReplay = replayAvailable, - User = new APIUser - { - Id = 39828, - Username = @"WubWoofWolf", - } - }.CreateScoreInfo(rulesets, beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps.First()); - } + Id = 39828, + Username = @"WubWoofWolf", + } + }; private class TestReplayDownloadButton : ReplayDownloadButton { diff --git a/osu.Game/Online/API/Requests/Responses/APIScore.cs b/osu.Game/Online/API/Requests/Responses/APIScore.cs deleted file mode 100644 index f236607761..0000000000 --- a/osu.Game/Online/API/Requests/Responses/APIScore.cs +++ /dev/null @@ -1,162 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -#nullable disable - -using System; -using System.Collections.Generic; -using System.Linq; -using JetBrains.Annotations; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using osu.Game.Beatmaps; -using osu.Game.Database; -using osu.Game.Rulesets; -using osu.Game.Rulesets.Mods; -using osu.Game.Scoring; -using osu.Game.Scoring.Legacy; -using osu.Game.Users; - -namespace osu.Game.Online.API.Requests.Responses -{ - public class APIScore : IScoreInfo - { - [JsonProperty(@"score")] - public long TotalScore { get; set; } - - [JsonProperty(@"max_combo")] - public int MaxCombo { get; set; } - - [JsonProperty(@"user")] - public APIUser User { get; set; } - - [JsonProperty(@"id")] - public long OnlineID { get; set; } - - [JsonProperty(@"replay")] - public bool HasReplay { get; set; } - - [JsonProperty(@"created_at")] - public DateTimeOffset Date { get; set; } - - [JsonProperty(@"beatmap")] - [CanBeNull] - public APIBeatmap Beatmap { get; set; } - - [JsonProperty("accuracy")] - public double Accuracy { get; set; } - - [JsonProperty(@"pp")] - public double? PP { get; set; } - - [JsonProperty(@"beatmapset")] - [CanBeNull] - public APIBeatmapSet BeatmapSet - { - set - { - // in the deserialisation case we need to ferry this data across. - // the order of properties returned by the API guarantees that the beatmap is populated by this point. - if (!(Beatmap is APIBeatmap apiBeatmap)) - throw new InvalidOperationException("Beatmap set metadata arrived before beatmap metadata in response"); - - apiBeatmap.BeatmapSet = value; - } - } - - [JsonProperty("statistics")] - public Dictionary Statistics { get; set; } - - [JsonProperty(@"mode_int")] - public int RulesetID { get; set; } - - [JsonProperty(@"mods")] - private string[] mods { set => Mods = value.Select(acronym => new APIMod { Acronym = acronym }); } - - [NotNull] - public IEnumerable Mods { get; set; } = Array.Empty(); - - [JsonProperty("rank")] - [JsonConverter(typeof(StringEnumConverter))] - public ScoreRank Rank { get; set; } - - /// - /// Create a from an API score instance. - /// - /// A ruleset store, used to populate a ruleset instance in the returned score. - /// An optional beatmap, copied into the returned score (for cases where the API does not populate the beatmap). - /// - public ScoreInfo CreateScoreInfo(RulesetStore rulesets, BeatmapInfo beatmap = null) - { - var ruleset = rulesets.GetRuleset(RulesetID) ?? throw new InvalidOperationException($"Ruleset with ID of {RulesetID} not found locally"); - - var rulesetInstance = ruleset.CreateInstance(); - - var modInstances = Mods.Select(apiMod => rulesetInstance.CreateModFromAcronym(apiMod.Acronym)).Where(m => m != null).ToArray(); - - // all API scores provided by this class are considered to be legacy. - modInstances = modInstances.Append(rulesetInstance.CreateMod()).ToArray(); - - var scoreInfo = new ScoreInfo - { - TotalScore = TotalScore, - MaxCombo = MaxCombo, - BeatmapInfo = beatmap ?? new BeatmapInfo(), - User = User, - Accuracy = Accuracy, - OnlineID = OnlineID, - Date = Date, - PP = PP, - Hash = HasReplay ? "online" : string.Empty, // todo: temporary? - Rank = Rank, - Ruleset = ruleset, - Mods = modInstances, - }; - - if (Statistics != null) - { - foreach (var kvp in Statistics) - { - switch (kvp.Key) - { - case @"count_geki": - scoreInfo.SetCountGeki(kvp.Value); - break; - - case @"count_300": - scoreInfo.SetCount300(kvp.Value); - break; - - case @"count_katu": - scoreInfo.SetCountKatu(kvp.Value); - break; - - case @"count_100": - scoreInfo.SetCount100(kvp.Value); - break; - - case @"count_50": - scoreInfo.SetCount50(kvp.Value); - break; - - case @"count_miss": - scoreInfo.SetCountMiss(kvp.Value); - break; - } - } - } - - return scoreInfo; - } - - public IRulesetInfo Ruleset => new RulesetInfo { OnlineID = RulesetID }; - IEnumerable IHasNamedFiles.Files => throw new NotImplementedException(); - - #region Implementation of IScoreInfo - - IBeatmapInfo IScoreInfo.Beatmap => Beatmap; - IUser IScoreInfo.User => User; - - #endregion - } -} diff --git a/osu.Game/Online/Solo/SubmittableScore.cs b/osu.Game/Online/Solo/SubmittableScore.cs index 31f0cb1dfb..73782060b3 100644 --- a/osu.Game/Online/Solo/SubmittableScore.cs +++ b/osu.Game/Online/Solo/SubmittableScore.cs @@ -9,7 +9,6 @@ using JetBrains.Annotations; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using osu.Game.Online.API; -using osu.Game.Online.API.Requests.Responses; using osu.Game.Rulesets.Scoring; using osu.Game.Scoring; @@ -17,7 +16,6 @@ namespace osu.Game.Online.Solo { /// /// A class specifically for sending scores to the API during score submission. - /// This is used instead of due to marginally different serialisation naming requirements. /// [Serializable] public class SubmittableScore From 1b6ebcfd87772a104773ead922fa0817891609f6 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 25 Jul 2022 13:43:19 +0300 Subject: [PATCH 048/278] Remove `SubmittableScore` and replace with `SoloScoreInfo` extension method --- .../Online/TestAPIModJsonSerialization.cs | 13 ++-- ... => TestSoloScoreInfoJsonSerialization.cs} | 8 +-- .../API/Requests/Responses/SoloScoreInfo.cs | 17 +++++ osu.Game/Online/Rooms/SubmitScoreRequest.cs | 6 +- osu.Game/Online/Solo/SubmittableScore.cs | 70 ------------------- 5 files changed, 30 insertions(+), 84 deletions(-) rename osu.Game.Tests/Online/{TestSubmittableScoreJsonSerialization.cs => TestSoloScoreInfoJsonSerialization.cs} (79%) delete mode 100644 osu.Game/Online/Solo/SubmittableScore.cs diff --git a/osu.Game.Tests/Online/TestAPIModJsonSerialization.cs b/osu.Game.Tests/Online/TestAPIModJsonSerialization.cs index 185f85513b..67dbcf0ccf 100644 --- a/osu.Game.Tests/Online/TestAPIModJsonSerialization.cs +++ b/osu.Game.Tests/Online/TestAPIModJsonSerialization.cs @@ -12,7 +12,6 @@ using osu.Game.Beatmaps; using osu.Game.Configuration; using osu.Game.Online.API; using osu.Game.Online.API.Requests.Responses; -using osu.Game.Online.Solo; using osu.Game.Rulesets; using osu.Game.Rulesets.Difficulty; using osu.Game.Rulesets.Mods; @@ -110,30 +109,30 @@ namespace osu.Game.Tests.Online } [Test] - public void TestDeserialiseSubmittableScoreWithEmptyMods() + public void TestDeserialiseSoloScoreWithEmptyMods() { - var score = new SubmittableScore(new ScoreInfo + var score = SoloScoreInfo.ForSubmission(new ScoreInfo { User = new APIUser(), Ruleset = new OsuRuleset().RulesetInfo, }); - var deserialised = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(score)); + var deserialised = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(score)); Assert.That(deserialised?.Mods.Length, Is.Zero); } [Test] - public void TestDeserialiseSubmittableScoreWithCustomModSetting() + public void TestDeserialiseSoloScoreWithCustomModSetting() { - var score = new SubmittableScore(new ScoreInfo + var score = SoloScoreInfo.ForSubmission(new ScoreInfo { Mods = new Mod[] { new OsuModDoubleTime { SpeedChange = { Value = 2 } } }, User = new APIUser(), Ruleset = new OsuRuleset().RulesetInfo, }); - var deserialised = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(score)); + var deserialised = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(score)); Assert.That((deserialised?.Mods[0])?.Settings["speed_change"], Is.EqualTo(2)); } diff --git a/osu.Game.Tests/Online/TestSubmittableScoreJsonSerialization.cs b/osu.Game.Tests/Online/TestSoloScoreInfoJsonSerialization.cs similarity index 79% rename from osu.Game.Tests/Online/TestSubmittableScoreJsonSerialization.cs rename to osu.Game.Tests/Online/TestSoloScoreInfoJsonSerialization.cs index f0f6727393..8ff0b67b5b 100644 --- a/osu.Game.Tests/Online/TestSubmittableScoreJsonSerialization.cs +++ b/osu.Game.Tests/Online/TestSoloScoreInfoJsonSerialization.cs @@ -6,7 +6,7 @@ using Newtonsoft.Json; using NUnit.Framework; using osu.Game.IO.Serialization; -using osu.Game.Online.Solo; +using osu.Game.Online.API.Requests.Responses; using osu.Game.Tests.Resources; namespace osu.Game.Tests.Online @@ -15,12 +15,12 @@ namespace osu.Game.Tests.Online /// Basic testing to ensure our attribute-based naming is correctly working. /// [TestFixture] - public class TestSubmittableScoreJsonSerialization + public class TestSoloScoreInfoJsonSerialization { [Test] public void TestScoreSerialisationViaExtensionMethod() { - var score = new SubmittableScore(TestResources.CreateTestScoreInfo()); + var score = SoloScoreInfo.ForSubmission(TestResources.CreateTestScoreInfo()); string serialised = score.Serialize(); @@ -31,7 +31,7 @@ namespace osu.Game.Tests.Online [Test] public void TestScoreSerialisationWithoutSettings() { - var score = new SubmittableScore(TestResources.CreateTestScoreInfo()); + var score = SoloScoreInfo.ForSubmission(TestResources.CreateTestScoreInfo()); string serialised = JsonConvert.SerializeObject(score); diff --git a/osu.Game/Online/API/Requests/Responses/SoloScoreInfo.cs b/osu.Game/Online/API/Requests/Responses/SoloScoreInfo.cs index bfc8b4102a..6558578023 100644 --- a/osu.Game/Online/API/Requests/Responses/SoloScoreInfo.cs +++ b/osu.Game/Online/API/Requests/Responses/SoloScoreInfo.cs @@ -151,6 +151,23 @@ namespace osu.Game.Online.API.Requests.Responses PP = PP, }; + /// + /// Creates a from a local score for score submission. + /// + /// The local score. + public static SoloScoreInfo ForSubmission(ScoreInfo score) => new SoloScoreInfo + { + Rank = score.Rank, + TotalScore = (int)score.TotalScore, + Accuracy = score.Accuracy, + PP = score.PP, + MaxCombo = score.MaxCombo, + RulesetID = score.RulesetID, + Passed = score.Passed, + Mods = score.APIMods, + Statistics = score.Statistics, + }; + public long OnlineID => ID ?? -1; } } diff --git a/osu.Game/Online/Rooms/SubmitScoreRequest.cs b/osu.Game/Online/Rooms/SubmitScoreRequest.cs index d681938da5..48a7780a03 100644 --- a/osu.Game/Online/Rooms/SubmitScoreRequest.cs +++ b/osu.Game/Online/Rooms/SubmitScoreRequest.cs @@ -7,20 +7,20 @@ using System.Net.Http; using Newtonsoft.Json; using osu.Framework.IO.Network; using osu.Game.Online.API; -using osu.Game.Online.Solo; +using osu.Game.Online.API.Requests.Responses; using osu.Game.Scoring; namespace osu.Game.Online.Rooms { public abstract class SubmitScoreRequest : APIRequest { - public readonly SubmittableScore Score; + public readonly SoloScoreInfo Score; protected readonly long ScoreId; protected SubmitScoreRequest(ScoreInfo scoreInfo, long scoreId) { - Score = new SubmittableScore(scoreInfo); + Score = SoloScoreInfo.ForSubmission(scoreInfo); ScoreId = scoreId; } diff --git a/osu.Game/Online/Solo/SubmittableScore.cs b/osu.Game/Online/Solo/SubmittableScore.cs deleted file mode 100644 index 73782060b3..0000000000 --- a/osu.Game/Online/Solo/SubmittableScore.cs +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -#nullable disable - -using System; -using System.Collections.Generic; -using JetBrains.Annotations; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using osu.Game.Online.API; -using osu.Game.Rulesets.Scoring; -using osu.Game.Scoring; - -namespace osu.Game.Online.Solo -{ - /// - /// A class specifically for sending scores to the API during score submission. - /// - [Serializable] - public class SubmittableScore - { - [JsonProperty("rank")] - [JsonConverter(typeof(StringEnumConverter))] - public ScoreRank Rank { get; set; } - - [JsonProperty("total_score")] - public long TotalScore { get; set; } - - [JsonProperty("accuracy")] - public double Accuracy { get; set; } - - [JsonProperty(@"pp")] - public double? PP { get; set; } - - [JsonProperty("max_combo")] - public int MaxCombo { get; set; } - - [JsonProperty("ruleset_id")] - public int RulesetID { get; set; } - - [JsonProperty("passed")] - public bool Passed { get; set; } - - // Used for API serialisation/deserialisation. - [JsonProperty("mods")] - public APIMod[] Mods { get; set; } - - [JsonProperty("statistics")] - public Dictionary Statistics { get; set; } - - [UsedImplicitly] - public SubmittableScore() - { - } - - public SubmittableScore(ScoreInfo score) - { - Rank = score.Rank; - TotalScore = score.TotalScore; - Accuracy = score.Accuracy; - PP = score.PP; - MaxCombo = score.MaxCombo; - RulesetID = score.RulesetID; - Passed = score.Passed; - Mods = score.APIMods; - Statistics = score.Statistics; - } - } -} From ec477a3ebfd74b2cdfa0444c23644d710c422df8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 25 Jul 2022 17:18:28 +0900 Subject: [PATCH 049/278] Add basic coverage of current behaviour of beatmap reimport --- .../Database/BeatmapImporterTests.cs | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/osu.Game.Tests/Database/BeatmapImporterTests.cs b/osu.Game.Tests/Database/BeatmapImporterTests.cs index 9ee88c0670..076be8339a 100644 --- a/osu.Game.Tests/Database/BeatmapImporterTests.cs +++ b/osu.Game.Tests/Database/BeatmapImporterTests.cs @@ -670,6 +670,61 @@ namespace osu.Game.Tests.Database }); } + [Test] + public void TestImportThenReimportWithNewDifficulty() + { + RunTestWithRealmAsync(async (realm, storage) => + { + var importer = new BeatmapImporter(storage, realm); + using var store = new RealmRulesetStore(realm, storage); + + string? pathOriginal = TestResources.GetTestBeatmapForImport(); + + string pathMissingOneBeatmap = pathOriginal.Replace(".osz", "_missing_difficulty.osz"); + + string extractedFolder = $"{pathOriginal}_extracted"; + Directory.CreateDirectory(extractedFolder); + + try + { + using (var zip = ZipArchive.Open(pathOriginal)) + zip.WriteToDirectory(extractedFolder); + + // remove one difficulty before first import + new FileInfo(Directory.GetFiles(extractedFolder, "*.osu").First()).Delete(); + + using (var zip = ZipArchive.Create()) + { + zip.AddAllFromDirectory(extractedFolder); + zip.SaveTo(pathMissingOneBeatmap, new ZipWriterOptions(CompressionType.Deflate)); + } + + var firstImport = await importer.Import(new ImportTask(pathMissingOneBeatmap)); + Assert.That(firstImport, Is.Not.Null); + + Assert.That(realm.Realm.All().Where(s => !s.DeletePending), Has.Count.EqualTo(1)); + Assert.That(realm.Realm.All().First(s => !s.DeletePending).Beatmaps, Has.Count.EqualTo(11)); + + // Second import matches first but contains one extra .osu file. + var secondImport = await importer.Import(new ImportTask(pathOriginal)); + Assert.That(secondImport, Is.Not.Null); + + Assert.That(realm.Realm.All(), Has.Count.EqualTo(23)); + Assert.That(realm.Realm.All(), Has.Count.EqualTo(2)); + + Assert.That(realm.Realm.All().Where(s => !s.DeletePending), Has.Count.EqualTo(1)); + Assert.That(realm.Realm.All().First(s => !s.DeletePending).Beatmaps, Has.Count.EqualTo(12)); + + // check the newly "imported" beatmap is not the original. + Assert.That(firstImport?.ID, Is.Not.EqualTo(secondImport?.ID)); + } + finally + { + Directory.Delete(extractedFolder, true); + } + }); + } + [Test] public void TestImportThenReimportAfterMissingFiles() { From 6a3e8e31de7587b2d6859c7bbb9964531424cfaf Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 25 Jul 2022 18:51:19 +0900 Subject: [PATCH 050/278] Centralise calls to reset online info of a `BeatmapInfo` --- osu.Game.Tests/Database/BeatmapImporterTests.cs | 2 +- .../Visual/Gameplay/TestScenePlayerScoreSubmission.cs | 2 +- osu.Game/Beatmaps/BeatmapImporter.cs | 4 ++-- osu.Game/Beatmaps/BeatmapInfo.cs | 11 +++++++++++ osu.Game/Beatmaps/BeatmapManager.cs | 3 +-- osu.Game/Beatmaps/BeatmapOnlineLookupQueue.cs | 4 ++-- 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/osu.Game.Tests/Database/BeatmapImporterTests.cs b/osu.Game.Tests/Database/BeatmapImporterTests.cs index 076be8339a..66384e8cd1 100644 --- a/osu.Game.Tests/Database/BeatmapImporterTests.cs +++ b/osu.Game.Tests/Database/BeatmapImporterTests.cs @@ -797,7 +797,7 @@ namespace osu.Game.Tests.Database await realm.Realm.WriteAsync(() => { foreach (var b in imported.Beatmaps) - b.OnlineID = -1; + b.ResetOnlineInfo(); }); deleteBeatmapSet(imported, realm.Realm); diff --git a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerScoreSubmission.cs b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerScoreSubmission.cs index 96efca6b65..d1bdfb1dfa 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerScoreSubmission.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerScoreSubmission.cs @@ -239,7 +239,7 @@ namespace osu.Game.Tests.Visual.Gameplay createPlayerTest(false, r => { var beatmap = createTestBeatmap(r); - beatmap.BeatmapInfo.OnlineID = -1; + beatmap.BeatmapInfo.ResetOnlineInfo(); return beatmap; }); diff --git a/osu.Game/Beatmaps/BeatmapImporter.cs b/osu.Game/Beatmaps/BeatmapImporter.cs index 3e4d01a9a3..2fdaeb9eed 100644 --- a/osu.Game/Beatmaps/BeatmapImporter.cs +++ b/osu.Game/Beatmaps/BeatmapImporter.cs @@ -87,7 +87,7 @@ namespace osu.Game.Beatmaps existingSetWithSameOnlineID.OnlineID = -1; foreach (var b in existingSetWithSameOnlineID.Beatmaps) - b.OnlineID = -1; + b.ResetOnlineInfo(); LogForModel(beatmapSet, $"Found existing beatmap set with same OnlineID ({beatmapSet.OnlineID}). It will be disassociated and marked for deletion."); } @@ -133,7 +133,7 @@ namespace osu.Game.Beatmaps } } - void resetIds() => beatmapSet.Beatmaps.ForEach(b => b.OnlineID = -1); + void resetIds() => beatmapSet.Beatmaps.ForEach(b => b.ResetOnlineInfo()); } protected override bool CanSkipImport(BeatmapSetInfo existing, BeatmapSetInfo import) diff --git a/osu.Game/Beatmaps/BeatmapInfo.cs b/osu.Game/Beatmaps/BeatmapInfo.cs index 466448d771..66c1995c8b 100644 --- a/osu.Game/Beatmaps/BeatmapInfo.cs +++ b/osu.Game/Beatmaps/BeatmapInfo.cs @@ -109,6 +109,17 @@ namespace osu.Game.Beatmaps [JsonIgnore] public bool Hidden { get; set; } + /// + /// Reset any fetched online linking information (and history). + /// + public void ResetOnlineInfo() + { + OnlineID = -1; + LastOnlineUpdate = null; + OnlineMD5Hash = string.Empty; + Status = BeatmapOnlineStatus.None; + } + #region Properties we may not want persisted (but also maybe no harm?) public double AudioLeadIn { get; set; } diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 7717c9cc87..62edd6e8da 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -164,8 +164,7 @@ namespace osu.Game.Beatmaps // clear the hash, as that's what is used to match .osu files with their corresponding realm beatmaps. newBeatmapInfo.Hash = string.Empty; // clear online properties. - newBeatmapInfo.OnlineID = -1; - newBeatmapInfo.Status = BeatmapOnlineStatus.None; + newBeatmapInfo.ResetOnlineInfo(); return addDifficultyToSet(targetBeatmapSet, newBeatmap, referenceWorkingBeatmap.Skin); } diff --git a/osu.Game/Beatmaps/BeatmapOnlineLookupQueue.cs b/osu.Game/Beatmaps/BeatmapOnlineLookupQueue.cs index d3be240d4c..6a3383cc92 100644 --- a/osu.Game/Beatmaps/BeatmapOnlineLookupQueue.cs +++ b/osu.Game/Beatmaps/BeatmapOnlineLookupQueue.cs @@ -88,7 +88,7 @@ namespace osu.Game.Beatmaps if (req.CompletionState == APIRequestCompletionState.Failed) { logForModel(set, $"Online retrieval failed for {beatmapInfo}"); - beatmapInfo.OnlineID = -1; + beatmapInfo.ResetOnlineInfo(); return; } @@ -118,7 +118,7 @@ namespace osu.Game.Beatmaps catch (Exception e) { logForModel(set, $"Online retrieval failed for {beatmapInfo} ({e.Message})"); - beatmapInfo.OnlineID = -1; + beatmapInfo.ResetOnlineInfo(); } } From b7f6413bcee7c4381fbbe30f9725bf144248eda8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 25 Jul 2022 18:52:53 +0900 Subject: [PATCH 051/278] Fix old version of beatmap potentially not being deleted during update flow This can happen if the online IDs are not present in the `.osu` files. Previously this was only working due to the early logic in the import process (that relies on matching all online IDs perfectly). --- osu.Game/Beatmaps/BeatmapModelDownloader.cs | 20 +++++++++++++++++++ osu.Game/Database/ModelDownloader.cs | 8 ++++++-- .../Select/Carousel/UpdateBeatmapSetButton.cs | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapModelDownloader.cs b/osu.Game/Beatmaps/BeatmapModelDownloader.cs index 4295def5c3..8c037b6382 100644 --- a/osu.Game/Beatmaps/BeatmapModelDownloader.cs +++ b/osu.Game/Beatmaps/BeatmapModelDownloader.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using osu.Framework.Logging; using osu.Game.Database; using osu.Game.Online.API; using osu.Game.Online.API.Requests; @@ -19,5 +20,24 @@ namespace osu.Game.Beatmaps : base(beatmapImporter, api) { } + + public bool Update(BeatmapSetInfo model) + { + return Download(model, false, onSuccess); + + void onSuccess(Live imported) + { + imported.PerformWrite(updated => + { + Logger.Log($"Beatmap \"{updated}\"update completed successfully", LoggingTarget.Database); + + var original = updated.Realm.Find(model.ID); + + // Generally the import process will do this for us if the OnlineIDs match, + // but that isn't a guarantee (ie. if the .osu file doesn't have OnlineIDs populated). + original.DeletePending = true; + }); + } + } } } diff --git a/osu.Game/Database/ModelDownloader.cs b/osu.Game/Database/ModelDownloader.cs index 02bcb342e4..8fa1c12d88 100644 --- a/osu.Game/Database/ModelDownloader.cs +++ b/osu.Game/Database/ModelDownloader.cs @@ -42,7 +42,9 @@ namespace osu.Game.Database /// The request object. protected abstract ArchiveDownloadRequest CreateDownloadRequest(T model, bool minimiseDownloadSize); - public bool Download(T model, bool minimiseDownloadSize = false) + public bool Download(T model, bool minimiseDownloadSize = false) => Download(model, minimiseDownloadSize, null); + + protected bool Download(T model, bool minimiseDownloadSize, Action>? onSuccess) { if (!canDownload(model)) return false; @@ -67,7 +69,9 @@ namespace osu.Game.Database var imported = await importer.Import(notification, new ImportTask(filename)).ConfigureAwait(false); // for now a failed import will be marked as a failed download for simplicity. - if (!imported.Any()) + if (imported.Any()) + onSuccess?.Invoke(imported.Single()); + else DownloadFailed?.Invoke(request); CurrentDownloads.Remove(request); diff --git a/osu.Game/Screens/Select/Carousel/UpdateBeatmapSetButton.cs b/osu.Game/Screens/Select/Carousel/UpdateBeatmapSetButton.cs index b80eb40018..3746c1975c 100644 --- a/osu.Game/Screens/Select/Carousel/UpdateBeatmapSetButton.cs +++ b/osu.Game/Screens/Select/Carousel/UpdateBeatmapSetButton.cs @@ -90,7 +90,7 @@ namespace osu.Game.Screens.Select.Carousel Action = () => { - beatmapDownloader.Download(beatmapSetInfo); + beatmapDownloader.Update(beatmapSetInfo); attachExistingDownload(); }; } From 912218e1231a18ebf7fc17e749f60963c90a4bf8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 25 Jul 2022 18:54:33 +0900 Subject: [PATCH 052/278] Ensure scores are transferred after beatmap update if difficulty hash didn't change --- osu.Game/Beatmaps/BeatmapModelDownloader.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/osu.Game/Beatmaps/BeatmapModelDownloader.cs b/osu.Game/Beatmaps/BeatmapModelDownloader.cs index 8c037b6382..0110ce0c50 100644 --- a/osu.Game/Beatmaps/BeatmapModelDownloader.cs +++ b/osu.Game/Beatmaps/BeatmapModelDownloader.cs @@ -1,6 +1,7 @@ // 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 osu.Framework.Logging; using osu.Game.Database; using osu.Game.Online.API; @@ -36,6 +37,23 @@ namespace osu.Game.Beatmaps // Generally the import process will do this for us if the OnlineIDs match, // but that isn't a guarantee (ie. if the .osu file doesn't have OnlineIDs populated). original.DeletePending = true; + + foreach (var beatmap in original.Beatmaps.ToArray()) + { + var updatedBeatmap = updated.Beatmaps.FirstOrDefault(b => b.Hash == beatmap.Hash); + + if (updatedBeatmap != null) + { + // If the updated beatmap matches an existing one, transfer any user data across.. + if (beatmap.Scores.Any()) + { + Logger.Log($"Transferring {beatmap.Scores.Count()} scores for unchanged difficulty \"{beatmap}\"", LoggingTarget.Database); + + foreach (var score in beatmap.Scores) + score.BeatmapInfo = updatedBeatmap; + } + } + } }); } } From e5ad07454ca37dbe6bb57b03d3dfcb48da1504cc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 25 Jul 2022 18:54:55 +0900 Subject: [PATCH 053/278] Ensure previous version prior to update loses online info after marked pending delete --- osu.Game/Beatmaps/BeatmapModelDownloader.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/osu.Game/Beatmaps/BeatmapModelDownloader.cs b/osu.Game/Beatmaps/BeatmapModelDownloader.cs index 0110ce0c50..7c48abbe66 100644 --- a/osu.Game/Beatmaps/BeatmapModelDownloader.cs +++ b/osu.Game/Beatmaps/BeatmapModelDownloader.cs @@ -52,6 +52,19 @@ namespace osu.Game.Beatmaps foreach (var score in beatmap.Scores) score.BeatmapInfo = updatedBeatmap; } + + // ..then nuke the old beatmap completely. + // this is done instead of a soft deletion to avoid a user potentially creating weird + // interactions, like restoring the outdated beatmap then updating a second time + // (causing user data to be wiped). + original.Beatmaps.Remove(beatmap); + } + else + { + // If the beatmap differs in the original, leave it in a soft-deleted state but reset online info. + // This caters to the case where a user has made modifications they potentially want to restore, + // but after restoring we want to ensure it can't be used to trigger an update of the beatmap. + beatmap.ResetOnlineInfo(); } } }); From 2363a3fb7b1d5b6a8cafbce199fde6e96636e942 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 25 Jul 2022 18:55:08 +0900 Subject: [PATCH 054/278] Persist `DateAdded` over beatmap updates --- osu.Game/Beatmaps/BeatmapModelDownloader.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game/Beatmaps/BeatmapModelDownloader.cs b/osu.Game/Beatmaps/BeatmapModelDownloader.cs index 7c48abbe66..a566aee49e 100644 --- a/osu.Game/Beatmaps/BeatmapModelDownloader.cs +++ b/osu.Game/Beatmaps/BeatmapModelDownloader.cs @@ -38,6 +38,9 @@ namespace osu.Game.Beatmaps // but that isn't a guarantee (ie. if the .osu file doesn't have OnlineIDs populated). original.DeletePending = true; + // Transfer local values which should be persisted across a beatmap update. + updated.DateAdded = original.DateAdded; + foreach (var beatmap in original.Beatmaps.ToArray()) { var updatedBeatmap = updated.Beatmaps.FirstOrDefault(b => b.Hash == beatmap.Hash); From 2e14d8730c397f86cf5ad75cc6b7bd24ef73ffd7 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 25 Jul 2022 19:31:46 +0900 Subject: [PATCH 055/278] Move implementation of updating a beatmap to `BeatmapImporter` --- ...eneOnlinePlayBeatmapAvailabilityTracker.cs | 2 +- osu.Game/Beatmaps/BeatmapImporter.cs | 56 ++++++++++++++++ osu.Game/Beatmaps/BeatmapManager.cs | 3 + osu.Game/Beatmaps/BeatmapModelDownloader.cs | 64 ++++--------------- .../Drawables/BundledBeatmapDownloader.cs | 3 +- osu.Game/Database/ModelDownloader.cs | 20 ++++-- 6 files changed, 89 insertions(+), 59 deletions(-) diff --git a/osu.Game.Tests/Online/TestSceneOnlinePlayBeatmapAvailabilityTracker.cs b/osu.Game.Tests/Online/TestSceneOnlinePlayBeatmapAvailabilityTracker.cs index 536322805b..0a980efbae 100644 --- a/osu.Game.Tests/Online/TestSceneOnlinePlayBeatmapAvailabilityTracker.cs +++ b/osu.Game.Tests/Online/TestSceneOnlinePlayBeatmapAvailabilityTracker.cs @@ -237,7 +237,7 @@ namespace osu.Game.Tests.Online internal class TestBeatmapModelDownloader : BeatmapModelDownloader { - public TestBeatmapModelDownloader(IModelImporter importer, IAPIProvider apiProvider) + public TestBeatmapModelDownloader(BeatmapManager importer, IAPIProvider apiProvider) : base(importer, apiProvider) { } diff --git a/osu.Game/Beatmaps/BeatmapImporter.cs b/osu.Game/Beatmaps/BeatmapImporter.cs index 2fdaeb9eed..3cfeb0df67 100644 --- a/osu.Game/Beatmaps/BeatmapImporter.cs +++ b/osu.Game/Beatmaps/BeatmapImporter.cs @@ -3,9 +3,11 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Threading; +using System.Threading.Tasks; using osu.Framework.Extensions; using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Logging; @@ -16,6 +18,7 @@ using osu.Game.Database; using osu.Game.Extensions; using osu.Game.IO; using osu.Game.IO.Archives; +using osu.Game.Overlays.Notifications; using osu.Game.Rulesets; using Realms; @@ -38,6 +41,59 @@ namespace osu.Game.Beatmaps { } + public async Task>> ImportAsUpdate(ProgressNotification notification, ImportTask importTask, BeatmapSetInfo original) + { + var imported = await Import(notification, importTask); + + Debug.Assert(imported.Count() == 1); + + imported.First().PerformWrite(updated => + { + Logger.Log($"Beatmap \"{updated}\"update completed successfully", LoggingTarget.Database); + + original = updated.Realm.Find(original.ID); + + // Generally the import process will do this for us if the OnlineIDs match, + // but that isn't a guarantee (ie. if the .osu file doesn't have OnlineIDs populated). + original.DeletePending = true; + + // Transfer local values which should be persisted across a beatmap update. + updated.DateAdded = original.DateAdded; + + foreach (var beatmap in original.Beatmaps.ToArray()) + { + var updatedBeatmap = updated.Beatmaps.FirstOrDefault(b => b.Hash == beatmap.Hash); + + if (updatedBeatmap != null) + { + // If the updated beatmap matches an existing one, transfer any user data across.. + if (beatmap.Scores.Any()) + { + Logger.Log($"Transferring {beatmap.Scores.Count()} scores for unchanged difficulty \"{beatmap}\"", LoggingTarget.Database); + + foreach (var score in beatmap.Scores) + score.BeatmapInfo = updatedBeatmap; + } + + // ..then nuke the old beatmap completely. + // this is done instead of a soft deletion to avoid a user potentially creating weird + // interactions, like restoring the outdated beatmap then updating a second time + // (causing user data to be wiped). + original.Beatmaps.Remove(beatmap); + } + else + { + // If the beatmap differs in the original, leave it in a soft-deleted state but reset online info. + // This caters to the case where a user has made modifications they potentially want to restore, + // but after restoring we want to ensure it can't be used to trigger an update of the beatmap. + beatmap.ResetOnlineInfo(); + } + } + }); + + return imported; + } + protected override bool ShouldDeleteArchive(string path) => Path.GetExtension(path).ToLowerInvariant() == ".osz"; protected override void Populate(BeatmapSetInfo beatmapSet, ArchiveReader? archive, Realm realm, CancellationToken cancellationToken = default) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 62edd6e8da..1b31d29c2b 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -408,6 +408,9 @@ namespace osu.Game.Beatmaps Realm.Run(r => Undelete(r.All().Where(s => s.DeletePending).ToList())); } + public Task>> ImportAsUpdate(ProgressNotification notification, ImportTask importTask, BeatmapSetInfo original) => + beatmapImporter.ImportAsUpdate(notification, importTask, original); + #region Implementation of ICanAcceptFiles public Task Import(params string[] paths) => beatmapImporter.Import(paths); diff --git a/osu.Game/Beatmaps/BeatmapModelDownloader.cs b/osu.Game/Beatmaps/BeatmapModelDownloader.cs index a566aee49e..e70168f1b3 100644 --- a/osu.Game/Beatmaps/BeatmapModelDownloader.cs +++ b/osu.Game/Beatmaps/BeatmapModelDownloader.cs @@ -1,77 +1,39 @@ // 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 osu.Framework.Logging; +using System.Collections.Generic; +using System.Threading.Tasks; using osu.Game.Database; using osu.Game.Online.API; using osu.Game.Online.API.Requests; +using osu.Game.Overlays.Notifications; namespace osu.Game.Beatmaps { public class BeatmapModelDownloader : ModelDownloader { + private readonly BeatmapManager beatmapManager; + protected override ArchiveDownloadRequest CreateDownloadRequest(IBeatmapSetInfo set, bool minimiseDownloadSize) => new DownloadBeatmapSetRequest(set, minimiseDownloadSize); public override ArchiveDownloadRequest? GetExistingDownload(IBeatmapSetInfo model) => CurrentDownloads.Find(r => r.Model.OnlineID == model.OnlineID); - public BeatmapModelDownloader(IModelImporter beatmapImporter, IAPIProvider api) + public BeatmapModelDownloader(BeatmapManager beatmapImporter, IAPIProvider api) : base(beatmapImporter, api) { + beatmapManager = beatmapImporter; } - public bool Update(BeatmapSetInfo model) + protected override Task>> Import(ProgressNotification notification, string filename, BeatmapSetInfo? originalModel) { - return Download(model, false, onSuccess); + if (originalModel != null) + return beatmapManager.ImportAsUpdate(notification, new ImportTask(filename), originalModel); - void onSuccess(Live imported) - { - imported.PerformWrite(updated => - { - Logger.Log($"Beatmap \"{updated}\"update completed successfully", LoggingTarget.Database); - - var original = updated.Realm.Find(model.ID); - - // Generally the import process will do this for us if the OnlineIDs match, - // but that isn't a guarantee (ie. if the .osu file doesn't have OnlineIDs populated). - original.DeletePending = true; - - // Transfer local values which should be persisted across a beatmap update. - updated.DateAdded = original.DateAdded; - - foreach (var beatmap in original.Beatmaps.ToArray()) - { - var updatedBeatmap = updated.Beatmaps.FirstOrDefault(b => b.Hash == beatmap.Hash); - - if (updatedBeatmap != null) - { - // If the updated beatmap matches an existing one, transfer any user data across.. - if (beatmap.Scores.Any()) - { - Logger.Log($"Transferring {beatmap.Scores.Count()} scores for unchanged difficulty \"{beatmap}\"", LoggingTarget.Database); - - foreach (var score in beatmap.Scores) - score.BeatmapInfo = updatedBeatmap; - } - - // ..then nuke the old beatmap completely. - // this is done instead of a soft deletion to avoid a user potentially creating weird - // interactions, like restoring the outdated beatmap then updating a second time - // (causing user data to be wiped). - original.Beatmaps.Remove(beatmap); - } - else - { - // If the beatmap differs in the original, leave it in a soft-deleted state but reset online info. - // This caters to the case where a user has made modifications they potentially want to restore, - // but after restoring we want to ensure it can't be used to trigger an update of the beatmap. - beatmap.ResetOnlineInfo(); - } - } - }); - } + return base.Import(notification, filename, null); } + + public bool Update(BeatmapSetInfo model) => Download(model, false, model); } } diff --git a/osu.Game/Beatmaps/Drawables/BundledBeatmapDownloader.cs b/osu.Game/Beatmaps/Drawables/BundledBeatmapDownloader.cs index 80af4108c7..bcbe7084d5 100644 --- a/osu.Game/Beatmaps/Drawables/BundledBeatmapDownloader.cs +++ b/osu.Game/Beatmaps/Drawables/BundledBeatmapDownloader.cs @@ -11,7 +11,6 @@ using System.Text.RegularExpressions; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Game.Database; using osu.Game.Online; using osu.Game.Online.API; using osu.Game.Online.API.Requests; @@ -109,7 +108,7 @@ namespace osu.Game.Beatmaps.Drawables private class BundledBeatmapModelDownloader : BeatmapModelDownloader { - public BundledBeatmapModelDownloader(IModelImporter beatmapImporter, IAPIProvider api) + public BundledBeatmapModelDownloader(BeatmapManager beatmapImporter, IAPIProvider api) : base(beatmapImporter, api) { } diff --git a/osu.Game/Database/ModelDownloader.cs b/osu.Game/Database/ModelDownloader.cs index 8fa1c12d88..5fd124cafc 100644 --- a/osu.Game/Database/ModelDownloader.cs +++ b/osu.Game/Database/ModelDownloader.cs @@ -44,7 +44,7 @@ namespace osu.Game.Database public bool Download(T model, bool minimiseDownloadSize = false) => Download(model, minimiseDownloadSize, null); - protected bool Download(T model, bool minimiseDownloadSize, Action>? onSuccess) + protected bool Download(T model, bool minimiseDownloadSize, TModel? originalModel) { if (!canDownload(model)) return false; @@ -66,12 +66,10 @@ namespace osu.Game.Database Task.Factory.StartNew(async () => { // This gets scheduled back to the update thread, but we want the import to run in the background. - var imported = await importer.Import(notification, new ImportTask(filename)).ConfigureAwait(false); + var imported = await Import(notification, filename, originalModel).ConfigureAwait(false); // for now a failed import will be marked as a failed download for simplicity. - if (imported.Any()) - onSuccess?.Invoke(imported.Single()); - else + if (!imported.Any()) DownloadFailed?.Invoke(request); CurrentDownloads.Remove(request); @@ -107,6 +105,18 @@ namespace osu.Game.Database } } + /// + /// Run the post-download import for the model. + /// + /// The notification to update. + /// The path of the temporary downloaded file. + /// An optional model for update scenarios, to be used as a reference. + /// The imported model. + protected virtual Task>> Import(ProgressNotification notification, string filename, TModel? originalModel) + { + return importer.Import(notification, new ImportTask(filename)); + } + public abstract ArchiveDownloadRequest? GetExistingDownload(T model); private bool canDownload(T model) => GetExistingDownload(model) == null && api != null; From 92dd1bcddb6dc3cfd669e721fc0f459a6b6d1e21 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 25 Jul 2022 19:50:58 +0900 Subject: [PATCH 056/278] Add test coverage of actual update flow --- .../Database/BeatmapImporterTests.cs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/osu.Game.Tests/Database/BeatmapImporterTests.cs b/osu.Game.Tests/Database/BeatmapImporterTests.cs index 66384e8cd1..784613ce3e 100644 --- a/osu.Game.Tests/Database/BeatmapImporterTests.cs +++ b/osu.Game.Tests/Database/BeatmapImporterTests.cs @@ -725,6 +725,60 @@ namespace osu.Game.Tests.Database }); } + [Test] + public void TestImportThenReimportWithNewDifficultyAsUpdate() + { + RunTestWithRealmAsync(async (realm, storage) => + { + var importer = new BeatmapImporter(storage, realm); + using var store = new RealmRulesetStore(realm, storage); + + string? pathOriginal = TestResources.GetTestBeatmapForImport(); + + string pathMissingOneBeatmap = pathOriginal.Replace(".osz", "_missing_difficulty.osz"); + + string extractedFolder = $"{pathOriginal}_extracted"; + Directory.CreateDirectory(extractedFolder); + + try + { + using (var zip = ZipArchive.Open(pathOriginal)) + zip.WriteToDirectory(extractedFolder); + + // remove one difficulty before first import + new FileInfo(Directory.GetFiles(extractedFolder, "*.osu").First()).Delete(); + + using (var zip = ZipArchive.Create()) + { + zip.AddAllFromDirectory(extractedFolder); + zip.SaveTo(pathMissingOneBeatmap, new ZipWriterOptions(CompressionType.Deflate)); + } + + var firstImport = await importer.Import(new ImportTask(pathMissingOneBeatmap)); + Assert.That(firstImport, Is.Not.Null); + Debug.Assert(firstImport != null); + + Assert.That(realm.Realm.All().Where(s => !s.DeletePending), Has.Count.EqualTo(1)); + Assert.That(realm.Realm.All().First(s => !s.DeletePending).Beatmaps, Has.Count.EqualTo(11)); + + // Second import matches first but contains one extra .osu file. + var secondImport = (await importer.ImportAsUpdate(new ProgressNotification(), new ImportTask(pathOriginal), firstImport.Value)).FirstOrDefault(); + Assert.That(secondImport, Is.Not.Null); + + Assert.That(realm.Realm.All(), Has.Count.EqualTo(12)); + Assert.That(realm.Realm.All(), Has.Count.EqualTo(12)); + Assert.That(realm.Realm.All(), Has.Count.EqualTo(1)); + + // check the newly "imported" beatmap is not the original. + Assert.That(firstImport?.ID, Is.Not.EqualTo(secondImport?.ID)); + } + finally + { + Directory.Delete(extractedFolder, true); + } + }); + } + [Test] public void TestImportThenReimportAfterMissingFiles() { From 8a0c8f5fd874cbca96918c1f396ff31b2fb27b6e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 25 Jul 2022 19:51:10 +0900 Subject: [PATCH 057/278] Fix some realm pieces not being cleaned up --- osu.Game/Beatmaps/BeatmapImporter.cs | 13 +++++++++++-- osu.Game/Database/RealmAccess.cs | 1 - 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapImporter.cs b/osu.Game/Beatmaps/BeatmapImporter.cs index 3cfeb0df67..104a36c788 100644 --- a/osu.Game/Beatmaps/BeatmapImporter.cs +++ b/osu.Game/Beatmaps/BeatmapImporter.cs @@ -49,9 +49,11 @@ namespace osu.Game.Beatmaps imported.First().PerformWrite(updated => { - Logger.Log($"Beatmap \"{updated}\"update completed successfully", LoggingTarget.Database); + var realm = updated.Realm; - original = updated.Realm.Find(original.ID); + Logger.Log($"Beatmap \"{updated}\" update completed successfully", LoggingTarget.Database); + + original = realm.Find(original.ID); // Generally the import process will do this for us if the OnlineIDs match, // but that isn't a guarantee (ie. if the .osu file doesn't have OnlineIDs populated). @@ -80,6 +82,9 @@ namespace osu.Game.Beatmaps // interactions, like restoring the outdated beatmap then updating a second time // (causing user data to be wiped). original.Beatmaps.Remove(beatmap); + + realm.Remove(beatmap.Metadata); + realm.Remove(beatmap); } else { @@ -89,6 +94,10 @@ namespace osu.Game.Beatmaps beatmap.ResetOnlineInfo(); } } + + // If the original has no beatmaps left, delete the set as well. + if (!original.Beatmaps.Any()) + realm.Remove(original); }); return imported; diff --git a/osu.Game/Database/RealmAccess.cs b/osu.Game/Database/RealmAccess.cs index 826341a5b9..a93fdea35b 100644 --- a/osu.Game/Database/RealmAccess.cs +++ b/osu.Game/Database/RealmAccess.cs @@ -278,7 +278,6 @@ namespace osu.Game.Database realm.Remove(score); realm.Remove(beatmap.Metadata); - realm.Remove(beatmap); } From 9c411c2250175f7cf4ecb34983bb356fd9deae93 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 25 Jul 2022 20:06:36 +0900 Subject: [PATCH 058/278] Fix test nullability assertions --- osu.Game.Tests/Database/BeatmapImporterTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Database/BeatmapImporterTests.cs b/osu.Game.Tests/Database/BeatmapImporterTests.cs index 784613ce3e..3b1f82375c 100644 --- a/osu.Game.Tests/Database/BeatmapImporterTests.cs +++ b/osu.Game.Tests/Database/BeatmapImporterTests.cs @@ -764,13 +764,14 @@ namespace osu.Game.Tests.Database // Second import matches first but contains one extra .osu file. var secondImport = (await importer.ImportAsUpdate(new ProgressNotification(), new ImportTask(pathOriginal), firstImport.Value)).FirstOrDefault(); Assert.That(secondImport, Is.Not.Null); + Debug.Assert(secondImport != null); Assert.That(realm.Realm.All(), Has.Count.EqualTo(12)); Assert.That(realm.Realm.All(), Has.Count.EqualTo(12)); Assert.That(realm.Realm.All(), Has.Count.EqualTo(1)); // check the newly "imported" beatmap is not the original. - Assert.That(firstImport?.ID, Is.Not.EqualTo(secondImport?.ID)); + Assert.That(firstImport.ID, Is.Not.EqualTo(secondImport.ID)); } finally { From e5355f314d4b5a851c0646f2da7d2916c2972106 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 25 Jul 2022 15:19:32 +0300 Subject: [PATCH 059/278] Use longer hash string --- osu.Game.Tests/Visual/Gameplay/TestSceneReplayDownloadButton.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneReplayDownloadButton.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneReplayDownloadButton.cs index 1384d4ef6e..9d70d1ef33 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneReplayDownloadButton.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneReplayDownloadButton.cs @@ -211,7 +211,7 @@ namespace osu.Game.Tests.Visual.Gameplay OnlineID = hasOnlineId ? online_score_id : 0, Ruleset = new OsuRuleset().RulesetInfo, BeatmapInfo = beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps.First(), - Hash = replayAvailable ? "hash" : string.Empty, + Hash = replayAvailable ? "online" : string.Empty, User = new APIUser { Id = 39828, From d41ac36a69c60c41b24ce20ece66a1a67ee2304e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 25 Jul 2022 23:59:25 +0900 Subject: [PATCH 060/278] Fix scenario where import is expected to be empty --- osu.Game/Beatmaps/BeatmapImporter.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game/Beatmaps/BeatmapImporter.cs b/osu.Game/Beatmaps/BeatmapImporter.cs index 104a36c788..2a6121b541 100644 --- a/osu.Game/Beatmaps/BeatmapImporter.cs +++ b/osu.Game/Beatmaps/BeatmapImporter.cs @@ -45,6 +45,9 @@ namespace osu.Game.Beatmaps { var imported = await Import(notification, importTask); + if (!imported.Any()) + return imported; + Debug.Assert(imported.Count() == 1); imported.First().PerformWrite(updated => From 46c4e784777b031a71e3c60374904d5fb15d1931 Mon Sep 17 00:00:00 2001 From: Andrew Hong Date: Mon, 25 Jul 2022 15:40:20 -0400 Subject: [PATCH 061/278] Add notification and another menuitem --- .../UserInterface/ExternalLinkButton.cs | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs b/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs index e813e2d8e8..c5e1e51e07 100644 --- a/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs +++ b/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs @@ -13,6 +13,8 @@ using osu.Framework.Graphics.Sprites; using osu.Framework.Input.Events; using osu.Framework.Localisation; using osu.Framework.Platform; +using osu.Game.Overlays; +using osu.Game.Overlays.Notifications; using osuTK; using osuTK.Graphics; @@ -22,6 +24,9 @@ namespace osu.Game.Graphics.UserInterface { public string Link { get; set; } + [Resolved] + private INotificationOverlay notificationOverlay { get; set; } + private Color4 hoverColour; [Resolved] @@ -44,14 +49,26 @@ namespace osu.Game.Graphics.UserInterface }; } + private void copyUrl() + { + host.GetClipboard()?.SetText(Link); + notificationOverlay.Post(new SimpleNotification + { + Text = "Copied URL!" + }); + } + public MenuItem[] ContextMenuItems { get { - List items = new List + List items = new List(); + + if (Link != null) { - new OsuMenuItem("Copy URL", MenuItemType.Standard, () => host.GetClipboard()?.SetText(Link)) - }; + items.Add(new OsuMenuItem("Open", MenuItemType.Standard, () => host.OpenUrlExternally(Link))); + items.Add(new OsuMenuItem("Copy URL", MenuItemType.Standard, () => copyUrl())); + } return items.ToArray(); } From a8e315abf033fb82a148c507b8be1d12613d91bf Mon Sep 17 00:00:00 2001 From: Andrew Hong Date: Mon, 25 Jul 2022 17:16:33 -0400 Subject: [PATCH 062/278] Refactor --- osu.Game/Graphics/UserInterface/ExternalLinkButton.cs | 2 +- osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs b/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs index c5e1e51e07..166546bb8a 100644 --- a/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs +++ b/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs @@ -8,8 +8,8 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Cursor; -using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.UserInterface; using osu.Framework.Input.Events; using osu.Framework.Localisation; using osu.Framework.Platform; diff --git a/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs b/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs index 85b98a92e2..c02c42786b 100644 --- a/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs +++ b/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs @@ -130,7 +130,8 @@ namespace osu.Game.Overlays.BeatmapSet { Font = OsuFont.GetFont(size: 30, weight: FontWeight.SemiBold, italics: true) }, - externalLink = new ExternalLinkButton { + externalLink = new ExternalLinkButton + { Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, Margin = new MarginPadding { Left = 5, Bottom = 4 }, // To better lineup with the font From ee0c67e114826da6d497bec8b78f6ddd5efd5630 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 26 Jul 2022 14:07:33 +0900 Subject: [PATCH 063/278] Add ability to make cursor show even during touch input I completely disagree with this from a UX perspective, but it's come up so often that I figure we should just let users bone themselves. --- osu.Game/Configuration/OsuConfigManager.cs | 2 ++ osu.Game/Graphics/Cursor/MenuCursorContainer.cs | 15 +++++++++++++-- osu.Game/Localisation/SkinSettingsStrings.cs | 5 +++++ .../Settings/Sections/Gameplay/InputSettings.cs | 5 +++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index e816fd50f3..fb585e9cbd 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -91,6 +91,7 @@ namespace osu.Game.Configuration // Input SetDefault(OsuSetting.MenuCursorSize, 1.0f, 0.5f, 2f, 0.01f); SetDefault(OsuSetting.GameplayCursorSize, 1.0f, 0.1f, 2f, 0.01f); + SetDefault(OsuSetting.GameplayCursorDuringTouch, false); SetDefault(OsuSetting.AutoCursorSize, false); SetDefault(OsuSetting.MouseDisableButtons, false); @@ -292,6 +293,7 @@ namespace osu.Game.Configuration MenuCursorSize, GameplayCursorSize, AutoCursorSize, + GameplayCursorDuringTouch, DimLevel, BlurLevel, LightenDuringBreaks, diff --git a/osu.Game/Graphics/Cursor/MenuCursorContainer.cs b/osu.Game/Graphics/Cursor/MenuCursorContainer.cs index 746f1b5d5e..e03dc4df6f 100644 --- a/osu.Game/Graphics/Cursor/MenuCursorContainer.cs +++ b/osu.Game/Graphics/Cursor/MenuCursorContainer.cs @@ -3,16 +3,20 @@ #nullable disable +using osu.Framework.Allocation; +using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Cursor; using osu.Framework.Input; using osu.Framework.Input.StateChanges; +using osu.Game.Configuration; namespace osu.Game.Graphics.Cursor { /// - /// A container which provides a which can be overridden by hovered s. + /// A container which provides a . + /// It also handles cases where a more localised cursor is provided by another component (via ). /// public class MenuCursorContainer : Container, IProvideCursor { @@ -36,12 +40,19 @@ namespace osu.Game.Graphics.Cursor }); } + private Bindable showDuringTouch; + private InputManager inputManager; + [Resolved] + private OsuConfigManager config { get; set; } + protected override void LoadComplete() { base.LoadComplete(); inputManager = GetContainingInputManager(); + + showDuringTouch = config.GetBindable(OsuSetting.GameplayCursorDuringTouch); } private IProvideCursor currentTarget; @@ -51,7 +62,7 @@ namespace osu.Game.Graphics.Cursor base.Update(); var lastMouseSource = inputManager.CurrentState.Mouse.LastSource; - bool hasValidInput = lastMouseSource != null && !(lastMouseSource is ISourcedFromTouch); + bool hasValidInput = lastMouseSource != null && (showDuringTouch.Value || lastMouseSource is not ISourcedFromTouch); if (!hasValidInput || !CanShowCursor) { diff --git a/osu.Game/Localisation/SkinSettingsStrings.cs b/osu.Game/Localisation/SkinSettingsStrings.cs index 81035c5a5e..4b6b0ce1d6 100644 --- a/osu.Game/Localisation/SkinSettingsStrings.cs +++ b/osu.Game/Localisation/SkinSettingsStrings.cs @@ -34,6 +34,11 @@ namespace osu.Game.Localisation /// public static LocalisableString AutoCursorSize => new TranslatableString(getKey(@"auto_cursor_size"), @"Adjust gameplay cursor size based on current beatmap"); + /// + /// "Show gameplay cursor during touch input" + /// + public static LocalisableString GameplayCursorDuringTouch => new TranslatableString(getKey(@"gameplay_cursor_during_touch"), @"Show gameplay cursor during touch input"); + /// /// "Beatmap skins" /// diff --git a/osu.Game/Overlays/Settings/Sections/Gameplay/InputSettings.cs b/osu.Game/Overlays/Settings/Sections/Gameplay/InputSettings.cs index b5315d5268..ac59a6c0ed 100644 --- a/osu.Game/Overlays/Settings/Sections/Gameplay/InputSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Gameplay/InputSettings.cs @@ -32,6 +32,11 @@ namespace osu.Game.Overlays.Settings.Sections.Gameplay LabelText = SkinSettingsStrings.AutoCursorSize, Current = config.GetBindable(OsuSetting.AutoCursorSize) }, + new SettingsCheckbox + { + LabelText = SkinSettingsStrings.GameplayCursorDuringTouch, + Current = config.GetBindable(OsuSetting.GameplayCursorDuringTouch) + }, }; if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows) From ef10145d6f9f77117e6e148cf82f76f6b89ffdb4 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 26 Jul 2022 14:11:52 +0900 Subject: [PATCH 064/278] Rename `MenuCursorContainer` and clean up code --- .../Visual/Gameplay/TestScenePause.cs | 2 +- .../Visual/UserInterface/TestSceneCursors.cs | 62 +++++++++--------- osu.Game.Tournament/TournamentGameBase.cs | 4 +- ...sorContainer.cs => GlobalCursorDisplay.cs} | 64 +++++++++---------- osu.Game/Graphics/Cursor/IProvideCursor.cs | 4 +- osu.Game/OsuGame.cs | 4 +- osu.Game/OsuGameBase.cs | 6 +- osu.Game/Rulesets/UI/DrawableRuleset.cs | 2 +- osu.Game/Screens/Utility/LatencyArea.cs | 8 +-- .../Visual/OsuManualInputManagerTestScene.cs | 6 +- 10 files changed, 80 insertions(+), 82 deletions(-) rename osu.Game/Graphics/Cursor/{MenuCursorContainer.cs => GlobalCursorDisplay.cs} (52%) diff --git a/osu.Game.Tests/Visual/Gameplay/TestScenePause.cs b/osu.Game.Tests/Visual/Gameplay/TestScenePause.cs index 5bd0a29308..71cc1f7b23 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestScenePause.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestScenePause.cs @@ -31,7 +31,7 @@ namespace osu.Game.Tests.Visual.Gameplay public TestScenePause() { - base.Content.Add(content = new MenuCursorContainer { RelativeSizeAxes = Axes.Both }); + base.Content.Add(content = new GlobalCursorDisplay { RelativeSizeAxes = Axes.Both }); } [SetUpSteps] diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneCursors.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneCursors.cs index 0fa7c5303c..bcbe146456 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneCursors.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneCursors.cs @@ -21,12 +21,12 @@ namespace osu.Game.Tests.Visual.UserInterface [TestFixture] public class TestSceneCursors : OsuManualInputManagerTestScene { - private readonly MenuCursorContainer menuCursorContainer; + private readonly GlobalCursorDisplay globalCursorDisplay; private readonly CustomCursorBox[] cursorBoxes = new CustomCursorBox[6]; public TestSceneCursors() { - Child = menuCursorContainer = new MenuCursorContainer + Child = globalCursorDisplay = new GlobalCursorDisplay { RelativeSizeAxes = Axes.Both, Children = new[] @@ -96,11 +96,11 @@ namespace osu.Game.Tests.Visual.UserInterface private void testUserCursor() { AddStep("Move to green area", () => InputManager.MoveMouseTo(cursorBoxes[0])); - AddAssert("Check green cursor visible", () => checkVisible(cursorBoxes[0].Cursor)); - AddAssert("Check green cursor at mouse", () => checkAtMouse(cursorBoxes[0].Cursor)); + AddAssert("Check green cursor visible", () => checkVisible(cursorBoxes[0].MenuCursor)); + AddAssert("Check green cursor at mouse", () => checkAtMouse(cursorBoxes[0].MenuCursor)); AddStep("Move out", moveOut); - AddAssert("Check green cursor invisible", () => !checkVisible(cursorBoxes[0].Cursor)); - AddAssert("Check global cursor visible", () => checkVisible(menuCursorContainer.Cursor)); + AddAssert("Check green cursor invisible", () => !checkVisible(cursorBoxes[0].MenuCursor)); + AddAssert("Check global cursor visible", () => checkVisible(globalCursorDisplay.MenuCursor)); } /// @@ -111,13 +111,13 @@ namespace osu.Game.Tests.Visual.UserInterface private void testLocalCursor() { AddStep("Move to purple area", () => InputManager.MoveMouseTo(cursorBoxes[3])); - AddAssert("Check purple cursor visible", () => checkVisible(cursorBoxes[3].Cursor)); - AddAssert("Check purple cursor at mouse", () => checkAtMouse(cursorBoxes[3].Cursor)); - AddAssert("Check global cursor visible", () => checkVisible(menuCursorContainer.Cursor)); - AddAssert("Check global cursor at mouse", () => checkAtMouse(menuCursorContainer.Cursor)); + AddAssert("Check purple cursor visible", () => checkVisible(cursorBoxes[3].MenuCursor)); + AddAssert("Check purple cursor at mouse", () => checkAtMouse(cursorBoxes[3].MenuCursor)); + AddAssert("Check global cursor visible", () => checkVisible(globalCursorDisplay.MenuCursor)); + AddAssert("Check global cursor at mouse", () => checkAtMouse(globalCursorDisplay.MenuCursor)); AddStep("Move out", moveOut); - AddAssert("Check purple cursor visible", () => checkVisible(cursorBoxes[3].Cursor)); - AddAssert("Check global cursor visible", () => checkVisible(menuCursorContainer.Cursor)); + AddAssert("Check purple cursor visible", () => checkVisible(cursorBoxes[3].MenuCursor)); + AddAssert("Check global cursor visible", () => checkVisible(globalCursorDisplay.MenuCursor)); } /// @@ -128,12 +128,12 @@ namespace osu.Game.Tests.Visual.UserInterface private void testUserCursorOverride() { AddStep("Move to blue-green boundary", () => InputManager.MoveMouseTo(cursorBoxes[1].ScreenSpaceDrawQuad.BottomRight - new Vector2(10))); - AddAssert("Check blue cursor visible", () => checkVisible(cursorBoxes[1].Cursor)); - AddAssert("Check green cursor invisible", () => !checkVisible(cursorBoxes[0].Cursor)); - AddAssert("Check blue cursor at mouse", () => checkAtMouse(cursorBoxes[1].Cursor)); + AddAssert("Check blue cursor visible", () => checkVisible(cursorBoxes[1].MenuCursor)); + AddAssert("Check green cursor invisible", () => !checkVisible(cursorBoxes[0].MenuCursor)); + AddAssert("Check blue cursor at mouse", () => checkAtMouse(cursorBoxes[1].MenuCursor)); AddStep("Move out", moveOut); - AddAssert("Check blue cursor not visible", () => !checkVisible(cursorBoxes[1].Cursor)); - AddAssert("Check green cursor not visible", () => !checkVisible(cursorBoxes[0].Cursor)); + AddAssert("Check blue cursor not visible", () => !checkVisible(cursorBoxes[1].MenuCursor)); + AddAssert("Check green cursor not visible", () => !checkVisible(cursorBoxes[0].MenuCursor)); } /// @@ -143,13 +143,13 @@ namespace osu.Game.Tests.Visual.UserInterface private void testMultipleLocalCursors() { AddStep("Move to yellow-purple boundary", () => InputManager.MoveMouseTo(cursorBoxes[5].ScreenSpaceDrawQuad.BottomRight - new Vector2(10))); - AddAssert("Check purple cursor visible", () => checkVisible(cursorBoxes[3].Cursor)); - AddAssert("Check purple cursor at mouse", () => checkAtMouse(cursorBoxes[3].Cursor)); - AddAssert("Check yellow cursor visible", () => checkVisible(cursorBoxes[5].Cursor)); - AddAssert("Check yellow cursor at mouse", () => checkAtMouse(cursorBoxes[5].Cursor)); + AddAssert("Check purple cursor visible", () => checkVisible(cursorBoxes[3].MenuCursor)); + AddAssert("Check purple cursor at mouse", () => checkAtMouse(cursorBoxes[3].MenuCursor)); + AddAssert("Check yellow cursor visible", () => checkVisible(cursorBoxes[5].MenuCursor)); + AddAssert("Check yellow cursor at mouse", () => checkAtMouse(cursorBoxes[5].MenuCursor)); AddStep("Move out", moveOut); - AddAssert("Check purple cursor visible", () => checkVisible(cursorBoxes[3].Cursor)); - AddAssert("Check yellow cursor visible", () => checkVisible(cursorBoxes[5].Cursor)); + AddAssert("Check purple cursor visible", () => checkVisible(cursorBoxes[3].MenuCursor)); + AddAssert("Check yellow cursor visible", () => checkVisible(cursorBoxes[5].MenuCursor)); } /// @@ -159,13 +159,13 @@ namespace osu.Game.Tests.Visual.UserInterface private void testUserOverrideWithLocal() { AddStep("Move to yellow-blue boundary", () => InputManager.MoveMouseTo(cursorBoxes[5].ScreenSpaceDrawQuad.TopRight - new Vector2(10))); - AddAssert("Check blue cursor visible", () => checkVisible(cursorBoxes[1].Cursor)); - AddAssert("Check blue cursor at mouse", () => checkAtMouse(cursorBoxes[1].Cursor)); - AddAssert("Check yellow cursor visible", () => checkVisible(cursorBoxes[5].Cursor)); - AddAssert("Check yellow cursor at mouse", () => checkAtMouse(cursorBoxes[5].Cursor)); + AddAssert("Check blue cursor visible", () => checkVisible(cursorBoxes[1].MenuCursor)); + AddAssert("Check blue cursor at mouse", () => checkAtMouse(cursorBoxes[1].MenuCursor)); + AddAssert("Check yellow cursor visible", () => checkVisible(cursorBoxes[5].MenuCursor)); + AddAssert("Check yellow cursor at mouse", () => checkAtMouse(cursorBoxes[5].MenuCursor)); AddStep("Move out", moveOut); - AddAssert("Check blue cursor invisible", () => !checkVisible(cursorBoxes[1].Cursor)); - AddAssert("Check yellow cursor visible", () => checkVisible(cursorBoxes[5].Cursor)); + AddAssert("Check blue cursor invisible", () => !checkVisible(cursorBoxes[1].MenuCursor)); + AddAssert("Check yellow cursor visible", () => checkVisible(cursorBoxes[5].MenuCursor)); } /// @@ -191,7 +191,7 @@ namespace osu.Game.Tests.Visual.UserInterface { public bool SmoothTransition; - public CursorContainer Cursor { get; } + public CursorContainer MenuCursor { get; } public bool ProvidingUserCursor { get; } public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => base.ReceivePositionalInputAt(screenSpacePos) || (SmoothTransition && !ProvidingUserCursor); @@ -218,7 +218,7 @@ namespace osu.Game.Tests.Visual.UserInterface Origin = Anchor.Centre, Text = providesUserCursor ? "User cursor" : "Local cursor" }, - Cursor = new TestCursorContainer + MenuCursor = new TestCursorContainer { State = { Value = providesUserCursor ? Visibility.Hidden : Visibility.Visible }, } diff --git a/osu.Game.Tournament/TournamentGameBase.cs b/osu.Game.Tournament/TournamentGameBase.cs index 063b62bf08..1861e39c60 100644 --- a/osu.Game.Tournament/TournamentGameBase.cs +++ b/osu.Game.Tournament/TournamentGameBase.cs @@ -70,10 +70,10 @@ namespace osu.Game.Tournament protected override void LoadComplete() { - MenuCursorContainer.Cursor.AlwaysPresent = true; // required for tooltip display + GlobalCursorDisplay.MenuCursor.AlwaysPresent = true; // required for tooltip display // we don't want to show the menu cursor as it would appear on stream output. - MenuCursorContainer.Cursor.Alpha = 0; + GlobalCursorDisplay.MenuCursor.Alpha = 0; base.LoadComplete(); diff --git a/osu.Game/Graphics/Cursor/MenuCursorContainer.cs b/osu.Game/Graphics/Cursor/GlobalCursorDisplay.cs similarity index 52% rename from osu.Game/Graphics/Cursor/MenuCursorContainer.cs rename to osu.Game/Graphics/Cursor/GlobalCursorDisplay.cs index e03dc4df6f..6613e18cbe 100644 --- a/osu.Game/Graphics/Cursor/MenuCursorContainer.cs +++ b/osu.Game/Graphics/Cursor/GlobalCursorDisplay.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -15,48 +13,48 @@ using osu.Game.Configuration; namespace osu.Game.Graphics.Cursor { /// - /// A container which provides a . - /// It also handles cases where a more localised cursor is provided by another component (via ). + /// A container which provides the main . + /// Also handles cases where a more localised cursor is provided by another component (via ). /// - public class MenuCursorContainer : Container, IProvideCursor + public class GlobalCursorDisplay : Container, IProvideCursor { - protected override Container Content => content; - private readonly Container content; - /// - /// Whether any cursors can be displayed. + /// Control whether any cursor should be displayed. /// - internal bool CanShowCursor = true; + internal bool ShowCursor = true; + + public CursorContainer MenuCursor { get; } - public CursorContainer Cursor { get; } public bool ProvidingUserCursor => true; - public MenuCursorContainer() + protected override Container Content { get; } = new Container { RelativeSizeAxes = Axes.Both }; + + private Bindable showDuringTouch = null!; + + private InputManager inputManager = null!; + + private IProvideCursor? currentOverrideProvider; + + [Resolved] + private OsuConfigManager config { get; set; } = null!; + + public GlobalCursorDisplay() { AddRangeInternal(new Drawable[] { - Cursor = new MenuCursor { State = { Value = Visibility.Hidden } }, - content = new Container { RelativeSizeAxes = Axes.Both } + MenuCursor = new MenuCursor { State = { Value = Visibility.Hidden } }, + Content = new Container { RelativeSizeAxes = Axes.Both } }); } - private Bindable showDuringTouch; - - private InputManager inputManager; - - [Resolved] - private OsuConfigManager config { get; set; } - protected override void LoadComplete() { base.LoadComplete(); - inputManager = GetContainingInputManager(); + inputManager = GetContainingInputManager(); showDuringTouch = config.GetBindable(OsuSetting.GameplayCursorDuringTouch); } - private IProvideCursor currentTarget; - protected override void Update() { base.Update(); @@ -64,31 +62,31 @@ namespace osu.Game.Graphics.Cursor var lastMouseSource = inputManager.CurrentState.Mouse.LastSource; bool hasValidInput = lastMouseSource != null && (showDuringTouch.Value || lastMouseSource is not ISourcedFromTouch); - if (!hasValidInput || !CanShowCursor) + if (!hasValidInput || !ShowCursor) { - currentTarget?.Cursor?.Hide(); - currentTarget = null; + currentOverrideProvider?.MenuCursor?.Hide(); + currentOverrideProvider = null; return; } - IProvideCursor newTarget = this; + IProvideCursor newOverrideProvider = this; foreach (var d in inputManager.HoveredDrawables) { if (d is IProvideCursor p && p.ProvidingUserCursor) { - newTarget = p; + newOverrideProvider = p; break; } } - if (currentTarget == newTarget) + if (currentOverrideProvider == newOverrideProvider) return; - currentTarget?.Cursor?.Hide(); - newTarget.Cursor?.Show(); + currentOverrideProvider?.MenuCursor?.Hide(); + newOverrideProvider.MenuCursor?.Show(); - currentTarget = newTarget; + currentOverrideProvider = newOverrideProvider; } } } diff --git a/osu.Game/Graphics/Cursor/IProvideCursor.cs b/osu.Game/Graphics/Cursor/IProvideCursor.cs index 9f01e5da6d..f7f7b75bc8 100644 --- a/osu.Game/Graphics/Cursor/IProvideCursor.cs +++ b/osu.Game/Graphics/Cursor/IProvideCursor.cs @@ -17,10 +17,10 @@ namespace osu.Game.Graphics.Cursor /// The cursor provided by this . /// May be null if no cursor should be visible. /// - CursorContainer Cursor { get; } + CursorContainer MenuCursor { get; } /// - /// Whether should be displayed as the singular user cursor. This will temporarily hide any other user cursor. + /// Whether should be displayed as the singular user cursor. This will temporarily hide any other user cursor. /// This value is checked every frame and may be used to control whether multiple cursors are displayed (e.g. watching replays). /// bool ProvidingUserCursor { get; } diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 4f08511783..1ee53e2848 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -716,7 +716,7 @@ namespace osu.Game // The next time this is updated is in UpdateAfterChildren, which occurs too late and results // in the cursor being shown for a few frames during the intro. // This prevents the cursor from showing until we have a screen with CursorVisible = true - MenuCursorContainer.CanShowCursor = menuScreen?.CursorVisible ?? false; + GlobalCursorDisplay.ShowCursor = menuScreen?.CursorVisible ?? false; // todo: all archive managers should be able to be looped here. SkinManager.PostNotification = n => Notifications.Post(n); @@ -1231,7 +1231,7 @@ namespace osu.Game ScreenOffsetContainer.X = horizontalOffset; overlayContent.X = horizontalOffset * 1.2f; - MenuCursorContainer.CanShowCursor = (ScreenStack.CurrentScreen as IOsuScreen)?.CursorVisible ?? false; + GlobalCursorDisplay.ShowCursor = (ScreenStack.CurrentScreen as IOsuScreen)?.CursorVisible ?? false; } private void screenChanged(IScreen current, IScreen newScreen) diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 3b81b5c8cd..7b6cda17a2 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -138,7 +138,7 @@ namespace osu.Game protected RealmKeyBindingStore KeyBindingStore { get; private set; } - protected MenuCursorContainer MenuCursorContainer { get; private set; } + protected GlobalCursorDisplay GlobalCursorDisplay { get; private set; } protected MusicController MusicController { get; private set; } @@ -340,10 +340,10 @@ namespace osu.Game RelativeSizeAxes = Axes.Both, Child = CreateScalingContainer().WithChildren(new Drawable[] { - (MenuCursorContainer = new MenuCursorContainer + (GlobalCursorDisplay = new GlobalCursorDisplay { RelativeSizeAxes = Axes.Both - }).WithChild(content = new OsuTooltipContainer(MenuCursorContainer.Cursor) + }).WithChild(content = new OsuTooltipContainer(GlobalCursorDisplay.MenuCursor) { RelativeSizeAxes = Axes.Both }), diff --git a/osu.Game/Rulesets/UI/DrawableRuleset.cs b/osu.Game/Rulesets/UI/DrawableRuleset.cs index 95cb02c477..f7f62d2af0 100644 --- a/osu.Game/Rulesets/UI/DrawableRuleset.cs +++ b/osu.Game/Rulesets/UI/DrawableRuleset.cs @@ -380,7 +380,7 @@ namespace osu.Game.Rulesets.UI // only show the cursor when within the playfield, by default. public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Playfield.ReceivePositionalInputAt(screenSpacePos); - CursorContainer IProvideCursor.Cursor => Playfield.Cursor; + CursorContainer IProvideCursor.MenuCursor => Playfield.Cursor; public override GameplayCursorContainer Cursor => Playfield.Cursor; diff --git a/osu.Game/Screens/Utility/LatencyArea.cs b/osu.Game/Screens/Utility/LatencyArea.cs index b7d45ba642..c8e0bf93a2 100644 --- a/osu.Game/Screens/Utility/LatencyArea.cs +++ b/osu.Game/Screens/Utility/LatencyArea.cs @@ -36,7 +36,7 @@ namespace osu.Game.Screens.Utility public readonly Bindable VisualMode = new Bindable(); - public CursorContainer? Cursor { get; private set; } + public CursorContainer? MenuCursor { get; private set; } public bool ProvidingUserCursor => IsActiveArea.Value; @@ -91,7 +91,7 @@ namespace osu.Game.Screens.Utility { RelativeSizeAxes = Axes.Both, }, - Cursor = new LatencyCursorContainer + MenuCursor = new LatencyCursorContainer { RelativeSizeAxes = Axes.Both, }, @@ -105,7 +105,7 @@ namespace osu.Game.Screens.Utility { RelativeSizeAxes = Axes.Both, }, - Cursor = new LatencyCursorContainer + MenuCursor = new LatencyCursorContainer { RelativeSizeAxes = Axes.Both, }, @@ -119,7 +119,7 @@ namespace osu.Game.Screens.Utility { RelativeSizeAxes = Axes.Both, }, - Cursor = new LatencyCursorContainer + MenuCursor = new LatencyCursorContainer { RelativeSizeAxes = Axes.Both, }, diff --git a/osu.Game/Tests/Visual/OsuManualInputManagerTestScene.cs b/osu.Game/Tests/Visual/OsuManualInputManagerTestScene.cs index eccd2efa96..9082ca9c58 100644 --- a/osu.Game/Tests/Visual/OsuManualInputManagerTestScene.cs +++ b/osu.Game/Tests/Visual/OsuManualInputManagerTestScene.cs @@ -38,11 +38,11 @@ namespace osu.Game.Tests.Visual protected OsuManualInputManagerTestScene() { - MenuCursorContainer cursorContainer; + GlobalCursorDisplay cursorDisplay; - CompositeDrawable mainContent = cursorContainer = new MenuCursorContainer { RelativeSizeAxes = Axes.Both }; + CompositeDrawable mainContent = cursorDisplay = new GlobalCursorDisplay { RelativeSizeAxes = Axes.Both }; - cursorContainer.Child = content = new OsuTooltipContainer(cursorContainer.Cursor) + cursorDisplay.Child = content = new OsuTooltipContainer(cursorDisplay.MenuCursor) { RelativeSizeAxes = Axes.Both }; From 1b2158ff048da3e37c13f908eac533e4cefe2aca Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 26 Jul 2022 14:15:59 +0900 Subject: [PATCH 065/278] Remove unused method --- .../Compose/Components/Timeline/ZoomableScrollContainer.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/ZoomableScrollContainer.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/ZoomableScrollContainer.cs index 725f94e7db..7d51284f46 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/ZoomableScrollContainer.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/ZoomableScrollContainer.cs @@ -156,13 +156,6 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline setZoomTarget(zoomTarget + change * (maxZoom - minZoom) * zoom_change_sensitivity, focusPoint); } - protected void SetZoomImmediately(float value, float min, float max) - { - maxZoom = max; - minZoom = min; - CurrentZoom = zoomTarget = value; - } - private float zoomTarget = 1; private void setZoomTarget(float newZoom, float? focusPoint = null) From 7d8a78ef015b10dcb77edf9b4c14c890b22fee88 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 26 Jul 2022 14:53:20 +0900 Subject: [PATCH 066/278] Move tests to own class --- .../Database/BeatmapImporterTests.cs | 55 ------------- .../Database/BeatmapImporterUpdateTests.cs | 81 +++++++++++++++++++ 2 files changed, 81 insertions(+), 55 deletions(-) create mode 100644 osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs diff --git a/osu.Game.Tests/Database/BeatmapImporterTests.cs b/osu.Game.Tests/Database/BeatmapImporterTests.cs index 3b1f82375c..66384e8cd1 100644 --- a/osu.Game.Tests/Database/BeatmapImporterTests.cs +++ b/osu.Game.Tests/Database/BeatmapImporterTests.cs @@ -725,61 +725,6 @@ namespace osu.Game.Tests.Database }); } - [Test] - public void TestImportThenReimportWithNewDifficultyAsUpdate() - { - RunTestWithRealmAsync(async (realm, storage) => - { - var importer = new BeatmapImporter(storage, realm); - using var store = new RealmRulesetStore(realm, storage); - - string? pathOriginal = TestResources.GetTestBeatmapForImport(); - - string pathMissingOneBeatmap = pathOriginal.Replace(".osz", "_missing_difficulty.osz"); - - string extractedFolder = $"{pathOriginal}_extracted"; - Directory.CreateDirectory(extractedFolder); - - try - { - using (var zip = ZipArchive.Open(pathOriginal)) - zip.WriteToDirectory(extractedFolder); - - // remove one difficulty before first import - new FileInfo(Directory.GetFiles(extractedFolder, "*.osu").First()).Delete(); - - using (var zip = ZipArchive.Create()) - { - zip.AddAllFromDirectory(extractedFolder); - zip.SaveTo(pathMissingOneBeatmap, new ZipWriterOptions(CompressionType.Deflate)); - } - - var firstImport = await importer.Import(new ImportTask(pathMissingOneBeatmap)); - Assert.That(firstImport, Is.Not.Null); - Debug.Assert(firstImport != null); - - Assert.That(realm.Realm.All().Where(s => !s.DeletePending), Has.Count.EqualTo(1)); - Assert.That(realm.Realm.All().First(s => !s.DeletePending).Beatmaps, Has.Count.EqualTo(11)); - - // Second import matches first but contains one extra .osu file. - var secondImport = (await importer.ImportAsUpdate(new ProgressNotification(), new ImportTask(pathOriginal), firstImport.Value)).FirstOrDefault(); - Assert.That(secondImport, Is.Not.Null); - Debug.Assert(secondImport != null); - - Assert.That(realm.Realm.All(), Has.Count.EqualTo(12)); - Assert.That(realm.Realm.All(), Has.Count.EqualTo(12)); - Assert.That(realm.Realm.All(), Has.Count.EqualTo(1)); - - // check the newly "imported" beatmap is not the original. - Assert.That(firstImport.ID, Is.Not.EqualTo(secondImport.ID)); - } - finally - { - Directory.Delete(extractedFolder, true); - } - }); - } - [Test] public void TestImportThenReimportAfterMissingFiles() { diff --git a/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs b/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs new file mode 100644 index 0000000000..713a73d64e --- /dev/null +++ b/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs @@ -0,0 +1,81 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Diagnostics; +using System.IO; +using System.Linq; +using NUnit.Framework; +using osu.Game.Beatmaps; +using osu.Game.Database; +using osu.Game.Overlays.Notifications; +using osu.Game.Rulesets; +using osu.Game.Tests.Resources; +using SharpCompress.Archives; +using SharpCompress.Archives.Zip; +using SharpCompress.Common; +using SharpCompress.Writers.Zip; + +namespace osu.Game.Tests.Database +{ + /// + /// Tests the flow where a beatmap is already loaded and an update is applied. + /// + [TestFixture] + public class BeatmapImporterUpdateTests : RealmTest + { + [Test] + public void TestImportThenUpdateWithNewDifficulty() + { + RunTestWithRealmAsync(async (realm, storage) => + { + var importer = new BeatmapImporter(storage, realm); + using var store = new RealmRulesetStore(realm, storage); + + string? pathOriginal = TestResources.GetTestBeatmapForImport(); + + string pathMissingOneBeatmap = pathOriginal.Replace(".osz", "_missing_difficulty.osz"); + + string extractedFolder = $"{pathOriginal}_extracted"; + Directory.CreateDirectory(extractedFolder); + + try + { + using (var zip = ZipArchive.Open(pathOriginal)) + zip.WriteToDirectory(extractedFolder); + + // remove one difficulty before first import + new FileInfo(Directory.GetFiles(extractedFolder, "*.osu").First()).Delete(); + + using (var zip = ZipArchive.Create()) + { + zip.AddAllFromDirectory(extractedFolder); + zip.SaveTo(pathMissingOneBeatmap, new ZipWriterOptions(CompressionType.Deflate)); + } + + var firstImport = await importer.Import(new ImportTask(pathMissingOneBeatmap)); + Assert.That(firstImport, Is.Not.Null); + Debug.Assert(firstImport != null); + + Assert.That(realm.Realm.All().Where(s => !s.DeletePending), Has.Count.EqualTo(1)); + Assert.That(realm.Realm.All().First(s => !s.DeletePending).Beatmaps, Has.Count.EqualTo(11)); + + // Second import matches first but contains one extra .osu file. + var secondImport = (await importer.ImportAsUpdate(new ProgressNotification(), new ImportTask(pathOriginal), firstImport.Value)).FirstOrDefault(); + Assert.That(secondImport, Is.Not.Null); + Debug.Assert(secondImport != null); + + Assert.That(realm.Realm.All(), Has.Count.EqualTo(12)); + Assert.That(realm.Realm.All(), Has.Count.EqualTo(12)); + Assert.That(realm.Realm.All(), Has.Count.EqualTo(1)); + + // check the newly "imported" beatmap is not the original. + Assert.That(firstImport.ID, Is.Not.EqualTo(secondImport.ID)); + } + finally + { + Directory.Delete(extractedFolder, true); + } + }); + } + } +} From 59d3cc52c445694f2874ff91d4f8bcb9538b6430 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 26 Jul 2022 14:56:41 +0900 Subject: [PATCH 067/278] Avoid leaving left-over files after test run completes --- .../Database/BeatmapImporterTests.cs | 1 - osu.Game.Tests/Database/RealmLiveTests.cs | 30 ++++++++----------- osu.Game.Tests/Database/RealmTest.cs | 23 +++++--------- .../NonVisual/DataLoadTest.cs | 4 +-- 4 files changed, 23 insertions(+), 35 deletions(-) diff --git a/osu.Game.Tests/Database/BeatmapImporterTests.cs b/osu.Game.Tests/Database/BeatmapImporterTests.cs index 9ee88c0670..2e49aa7bdc 100644 --- a/osu.Game.Tests/Database/BeatmapImporterTests.cs +++ b/osu.Game.Tests/Database/BeatmapImporterTests.cs @@ -142,7 +142,6 @@ namespace osu.Game.Tests.Database { Task.Run(async () => { - // ReSharper disable once AccessToDisposedClosure var beatmapSet = await importer.Import(new ImportTask(TestResources.GetTestBeatmapStream(), "renatus.osz")); Assert.NotNull(beatmapSet); diff --git a/osu.Game.Tests/Database/RealmLiveTests.cs b/osu.Game.Tests/Database/RealmLiveTests.cs index 3615cebe6a..d853e75db0 100644 --- a/osu.Game.Tests/Database/RealmLiveTests.cs +++ b/osu.Game.Tests/Database/RealmLiveTests.cs @@ -32,31 +32,29 @@ namespace osu.Game.Tests.Database [Test] public void TestAccessAfterStorageMigrate() { - RunTestWithRealm((realm, storage) => + using (var migratedStorage = new TemporaryNativeStorage("realm-test-migration-target")) { - var beatmap = new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata()); - - Live? liveBeatmap = null; - - realm.Run(r => + RunTestWithRealm((realm, storage) => { - r.Write(_ => r.Add(beatmap)); + var beatmap = new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata()); - liveBeatmap = beatmap.ToLive(realm); - }); + Live? liveBeatmap = null; + + realm.Run(r => + { + r.Write(_ => r.Add(beatmap)); + + liveBeatmap = beatmap.ToLive(realm); + }); - using (var migratedStorage = new TemporaryNativeStorage("realm-test-migration-target")) - { migratedStorage.DeleteDirectory(string.Empty); using (realm.BlockAllOperations("testing")) - { storage.Migrate(migratedStorage); - } Assert.IsFalse(liveBeatmap?.PerformRead(l => l.Hidden)); - } - }); + }); + } } [Test] @@ -341,14 +339,12 @@ namespace osu.Game.Tests.Database liveBeatmap.PerformRead(resolved => { // retrieval causes an implicit refresh. even changes that aren't related to the retrieval are fired at this point. - // ReSharper disable once AccessToDisposedClosure Assert.AreEqual(2, outerRealm.All().Count()); Assert.AreEqual(1, changesTriggered); // can access properties without a crash. Assert.IsFalse(resolved.Hidden); - // ReSharper disable once AccessToDisposedClosure outerRealm.Write(r => { // can use with the main context. diff --git a/osu.Game.Tests/Database/RealmTest.cs b/osu.Game.Tests/Database/RealmTest.cs index d6b3c1ff44..1b1878942b 100644 --- a/osu.Game.Tests/Database/RealmTest.cs +++ b/osu.Game.Tests/Database/RealmTest.cs @@ -4,11 +4,11 @@ using System; using System.Runtime.CompilerServices; using System.Threading.Tasks; +using JetBrains.Annotations; using NUnit.Framework; using osu.Framework.Extensions; using osu.Framework.Logging; using osu.Framework.Platform; -using osu.Framework.Testing; using osu.Game.Beatmaps; using osu.Game.Database; using osu.Game.IO; @@ -20,22 +20,15 @@ namespace osu.Game.Tests.Database [TestFixture] public abstract class RealmTest { - private static readonly TemporaryNativeStorage storage; - - static RealmTest() - { - storage = new TemporaryNativeStorage("realm-test"); - storage.DeleteDirectory(string.Empty); - } - - protected void RunTestWithRealm(Action testAction, [CallerMemberName] string caller = "") + protected void RunTestWithRealm([InstantHandle] Action testAction, [CallerMemberName] string caller = "") { using (HeadlessGameHost host = new CleanRunHeadlessGameHost(callingMethodName: caller)) { host.Run(new RealmTestGame(() => { - // ReSharper disable once AccessToDisposedClosure - var testStorage = new OsuStorage(host, storage.GetStorageForDirectory(caller)); + var defaultStorage = host.Storage; + + var testStorage = new OsuStorage(host, defaultStorage); using (var realm = new RealmAccess(testStorage, OsuGameBase.CLIENT_DATABASE_FILENAME)) { @@ -58,7 +51,7 @@ namespace osu.Game.Tests.Database { host.Run(new RealmTestGame(async () => { - var testStorage = storage.GetStorageForDirectory(caller); + var testStorage = host.Storage; using (var realm = new RealmAccess(testStorage, OsuGameBase.CLIENT_DATABASE_FILENAME)) { @@ -116,7 +109,7 @@ namespace osu.Game.Tests.Database private class RealmTestGame : Framework.Game { - public RealmTestGame(Func work) + public RealmTestGame([InstantHandle] Func work) { // ReSharper disable once AsyncVoidLambda Scheduler.Add(async () => @@ -126,7 +119,7 @@ namespace osu.Game.Tests.Database }); } - public RealmTestGame(Action work) + public RealmTestGame([InstantHandle] Action work) { Scheduler.Add(() => { diff --git a/osu.Game.Tournament.Tests/NonVisual/DataLoadTest.cs b/osu.Game.Tournament.Tests/NonVisual/DataLoadTest.cs index ad776622be..df77b31191 100644 --- a/osu.Game.Tournament.Tests/NonVisual/DataLoadTest.cs +++ b/osu.Game.Tournament.Tests/NonVisual/DataLoadTest.cs @@ -6,6 +6,7 @@ using System; using System.IO; using System.Threading.Tasks; +using JetBrains.Annotations; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Bindables; @@ -27,7 +28,6 @@ namespace osu.Game.Tournament.Tests.NonVisual { var osu = new TestTournament(runOnLoadComplete: () => { - // ReSharper disable once AccessToDisposedClosure var storage = host.Storage.GetStorageForDirectory(Path.Combine("tournaments", "default")); using (var stream = storage.CreateFileSafely("bracket.json")) @@ -85,7 +85,7 @@ namespace osu.Game.Tournament.Tests.NonVisual public new Task BracketLoadTask => base.BracketLoadTask; - public TestTournament(bool resetRuleset = false, Action runOnLoadComplete = null) + public TestTournament(bool resetRuleset = false, [InstantHandle] Action runOnLoadComplete = null) { this.resetRuleset = resetRuleset; this.runOnLoadComplete = runOnLoadComplete; From ac553d22ea076a161743a0fefdc67099b37b0d4b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 26 Jul 2022 15:05:01 +0900 Subject: [PATCH 068/278] Fix left over resource file which isn't actually imported --- osu.Game.Tests/Database/BeatmapImporterTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game.Tests/Database/BeatmapImporterTests.cs b/osu.Game.Tests/Database/BeatmapImporterTests.cs index 2e49aa7bdc..af285f82b1 100644 --- a/osu.Game.Tests/Database/BeatmapImporterTests.cs +++ b/osu.Game.Tests/Database/BeatmapImporterTests.cs @@ -310,6 +310,7 @@ namespace osu.Game.Tests.Database } finally { + File.Delete(temp); Directory.Delete(extractedFolder, true); } }); From 99bdf417175c8fa856fca0e9dba78babbf7005c9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 26 Jul 2022 15:12:22 +0900 Subject: [PATCH 069/278] Avoid potential realm fetch after disposal in `StatisticsPanel` As seen at https://github.com/ppy/osu/runs/7513799859?check_suite_focus=true. --- .../Screens/Ranking/Statistics/StatisticsPanel.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/osu.Game/Screens/Ranking/Statistics/StatisticsPanel.cs b/osu.Game/Screens/Ranking/Statistics/StatisticsPanel.cs index 435162e057..79d7b99e51 100644 --- a/osu.Game/Screens/Ranking/Statistics/StatisticsPanel.cs +++ b/osu.Game/Screens/Ranking/Statistics/StatisticsPanel.cs @@ -11,6 +11,7 @@ using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Audio.Sample; using osu.Framework.Bindables; +using osu.Framework.Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Input.Events; @@ -90,18 +91,16 @@ namespace osu.Game.Screens.Ranking.Statistics spinner.Show(); var localCancellationSource = loadCancellation = new CancellationTokenSource(); - IBeatmap playableBeatmap = null; + + var workingBeatmap = beatmapManager.GetWorkingBeatmap(newScore.BeatmapInfo); // Todo: The placement of this is temporary. Eventually we'll both generate the playable beatmap _and_ run through it in a background task to generate the hit events. - Task.Run(() => - { - playableBeatmap = beatmapManager.GetWorkingBeatmap(newScore.BeatmapInfo).GetPlayableBeatmap(newScore.Ruleset, newScore.Mods); - }, loadCancellation.Token).ContinueWith(_ => Schedule(() => + Task.Run(() => workingBeatmap.GetPlayableBeatmap(newScore.Ruleset, newScore.Mods), loadCancellation.Token).ContinueWith(task => Schedule(() => { bool hitEventsAvailable = newScore.HitEvents.Count != 0; Container container; - var statisticRows = newScore.Ruleset.CreateInstance().CreateStatisticsForScore(newScore, playableBeatmap); + var statisticRows = newScore.Ruleset.CreateInstance().CreateStatisticsForScore(newScore, task.GetResultSafely()); if (!hitEventsAvailable && statisticRows.SelectMany(r => r.Columns).All(c => c.RequiresHitEvents)) { From d7ef4170be894807edb5880d282d7f01844a5dfb Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Tue, 26 Jul 2022 09:36:25 +0300 Subject: [PATCH 070/278] Maintain sort stability by using carousel item ID as fallback --- osu.Game/Screens/Select/Carousel/CarouselGroup.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Select/Carousel/CarouselGroup.cs b/osu.Game/Screens/Select/Carousel/CarouselGroup.cs index e430ff3d3a..07c3c24018 100644 --- a/osu.Game/Screens/Select/Carousel/CarouselGroup.cs +++ b/osu.Game/Screens/Select/Carousel/CarouselGroup.cs @@ -24,6 +24,7 @@ namespace osu.Game.Screens.Select.Carousel private ulong currentChildID; private Comparer? criteriaComparer; + private Comparer? itemIDComparer; private FilterCriteria? lastCriteria; @@ -90,7 +91,8 @@ namespace osu.Game.Screens.Select.Carousel // IEnumerable.OrderBy() is used instead of List.Sort() to ensure sorting stability criteriaComparer = Comparer.Create((x, y) => x.CompareTo(criteria, y)); - items = items.OrderBy(c => c, criteriaComparer).ToList(); + itemIDComparer = Comparer.Create((x, y) => x.ChildID.CompareTo(y.ChildID)); + items = items.OrderBy(c => c, criteriaComparer).ThenBy(c => c, itemIDComparer).ToList(); lastCriteria = criteria; } From 693ac8750c214d43a28eb44fd76f12829d1c6177 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Tue, 26 Jul 2022 09:39:30 +0300 Subject: [PATCH 071/278] Remove remaining uses of "child" terminology in non-drawable components --- osu.Game/Screens/Select/Carousel/CarouselGroup.cs | 12 ++++++------ .../Select/Carousel/CarouselGroupEagerSelect.cs | 14 +++++++------- osu.Game/Screens/Select/Carousel/CarouselItem.cs | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/osu.Game/Screens/Select/Carousel/CarouselGroup.cs b/osu.Game/Screens/Select/Carousel/CarouselGroup.cs index 07c3c24018..7fcf53e68c 100644 --- a/osu.Game/Screens/Select/Carousel/CarouselGroup.cs +++ b/osu.Game/Screens/Select/Carousel/CarouselGroup.cs @@ -7,7 +7,7 @@ using System.Linq; namespace osu.Game.Screens.Select.Carousel { /// - /// A group which ensures only one child is selected. + /// A group which ensures only one item is selected. /// public class CarouselGroup : CarouselItem { @@ -18,10 +18,10 @@ namespace osu.Game.Screens.Select.Carousel private List items = new List(); /// - /// Used to assign a monotonically increasing ID to children as they are added. This member is - /// incremented whenever a child is added. + /// Used to assign a monotonically increasing ID to items as they are added. This member is + /// incremented whenever an item is added. /// - private ulong currentChildID; + private ulong currentItemID; private Comparer? criteriaComparer; private Comparer? itemIDComparer; @@ -42,7 +42,7 @@ namespace osu.Game.Screens.Select.Carousel public virtual void AddItem(CarouselItem i) { i.State.ValueChanged += state => ChildItemStateChanged(i, state.NewValue); - i.ChildID = ++currentChildID; + i.ItemID = ++currentItemID; if (lastCriteria != null) { @@ -91,7 +91,7 @@ namespace osu.Game.Screens.Select.Carousel // IEnumerable.OrderBy() is used instead of List.Sort() to ensure sorting stability criteriaComparer = Comparer.Create((x, y) => x.CompareTo(criteria, y)); - itemIDComparer = Comparer.Create((x, y) => x.ChildID.CompareTo(y.ChildID)); + itemIDComparer = Comparer.Create((x, y) => x.ItemID.CompareTo(y.ItemID)); items = items.OrderBy(c => c, criteriaComparer).ThenBy(c => c, itemIDComparer).ToList(); lastCriteria = criteria; diff --git a/osu.Game/Screens/Select/Carousel/CarouselGroupEagerSelect.cs b/osu.Game/Screens/Select/Carousel/CarouselGroupEagerSelect.cs index 613b3db5d5..61109829f3 100644 --- a/osu.Game/Screens/Select/Carousel/CarouselGroupEagerSelect.cs +++ b/osu.Game/Screens/Select/Carousel/CarouselGroupEagerSelect.cs @@ -10,7 +10,7 @@ using System.Linq; namespace osu.Game.Screens.Select.Carousel { /// - /// A group which ensures at least one child is selected (if the group itself is selected). + /// A group which ensures at least one item is selected (if the group itself is selected). /// public class CarouselGroupEagerSelect : CarouselGroup { @@ -35,16 +35,16 @@ namespace osu.Game.Screens.Select.Carousel /// /// To avoid overhead during filter operations, we don't attempt any selections until after all - /// children have been filtered. This bool will be true during the base + /// items have been filtered. This bool will be true during the base /// operation. /// - private bool filteringChildren; + private bool filteringItems; public override void Filter(FilterCriteria criteria) { - filteringChildren = true; + filteringItems = true; base.Filter(criteria); - filteringChildren = false; + filteringItems = false; attemptSelection(); } @@ -97,12 +97,12 @@ namespace osu.Game.Screens.Select.Carousel private void attemptSelection() { - if (filteringChildren) return; + if (filteringItems) return; // we only perform eager selection if we are a currently selected group. if (State.Value != CarouselItemState.Selected) return; - // we only perform eager selection if none of our children are in a selected state already. + // we only perform eager selection if none of our items are in a selected state already. if (Items.Any(i => i.State.Value == CarouselItemState.Selected)) return; PerformSelection(); diff --git a/osu.Game/Screens/Select/Carousel/CarouselItem.cs b/osu.Game/Screens/Select/Carousel/CarouselItem.cs index a901f72dad..cbf079eb4b 100644 --- a/osu.Game/Screens/Select/Carousel/CarouselItem.cs +++ b/osu.Game/Screens/Select/Carousel/CarouselItem.cs @@ -38,7 +38,7 @@ namespace osu.Game.Screens.Select.Carousel /// /// Used as a default sort method for s of differing types. /// - internal ulong ChildID; + internal ulong ItemID; /// /// Create a fresh drawable version of this item. @@ -49,7 +49,7 @@ namespace osu.Game.Screens.Select.Carousel { } - public virtual int CompareTo(FilterCriteria criteria, CarouselItem other) => ChildID.CompareTo(other.ChildID); + public virtual int CompareTo(FilterCriteria criteria, CarouselItem other) => ItemID.CompareTo(other.ItemID); public int CompareTo(CarouselItem other) => CarouselYPosition.CompareTo(other.CarouselYPosition); } From 8370ca976557116af528330389f7fe18583d0896 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 26 Jul 2022 15:46:29 +0900 Subject: [PATCH 072/278] Add `ImportAsUpdate` method to `IModelImporter` to avoid otehr changes --- .../Database/BeatmapImporterUpdateTests.cs | 2 +- ...ceneOnlinePlayBeatmapAvailabilityTracker.cs | 2 +- osu.Game/Beatmaps/BeatmapImporter.cs | 10 ++++++---- osu.Game/Beatmaps/BeatmapManager.cs | 2 +- osu.Game/Beatmaps/BeatmapModelDownloader.cs | 18 +----------------- osu.Game/Database/IModelImporter.cs | 10 ++++++++++ osu.Game/Database/ModelDownloader.cs | 16 +++------------- osu.Game/Database/RealmArchiveModelImporter.cs | 2 ++ osu.Game/Scoring/ScoreManager.cs | 2 ++ .../Select/Carousel/UpdateBeatmapSetButton.cs | 2 +- osu.Game/Skinning/SkinManager.cs | 2 ++ 11 files changed, 30 insertions(+), 38 deletions(-) diff --git a/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs b/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs index 713a73d64e..cf4245ae83 100644 --- a/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs +++ b/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs @@ -60,7 +60,7 @@ namespace osu.Game.Tests.Database Assert.That(realm.Realm.All().First(s => !s.DeletePending).Beatmaps, Has.Count.EqualTo(11)); // Second import matches first but contains one extra .osu file. - var secondImport = (await importer.ImportAsUpdate(new ProgressNotification(), new ImportTask(pathOriginal), firstImport.Value)).FirstOrDefault(); + var secondImport = await importer.ImportAsUpdate(new ProgressNotification(), new ImportTask(pathOriginal), firstImport.Value); Assert.That(secondImport, Is.Not.Null); Debug.Assert(secondImport != null); diff --git a/osu.Game.Tests/Online/TestSceneOnlinePlayBeatmapAvailabilityTracker.cs b/osu.Game.Tests/Online/TestSceneOnlinePlayBeatmapAvailabilityTracker.cs index 0a980efbae..536322805b 100644 --- a/osu.Game.Tests/Online/TestSceneOnlinePlayBeatmapAvailabilityTracker.cs +++ b/osu.Game.Tests/Online/TestSceneOnlinePlayBeatmapAvailabilityTracker.cs @@ -237,7 +237,7 @@ namespace osu.Game.Tests.Online internal class TestBeatmapModelDownloader : BeatmapModelDownloader { - public TestBeatmapModelDownloader(BeatmapManager importer, IAPIProvider apiProvider) + public TestBeatmapModelDownloader(IModelImporter importer, IAPIProvider apiProvider) : base(importer, apiProvider) { } diff --git a/osu.Game/Beatmaps/BeatmapImporter.cs b/osu.Game/Beatmaps/BeatmapImporter.cs index 2a6121b541..1e90e14e68 100644 --- a/osu.Game/Beatmaps/BeatmapImporter.cs +++ b/osu.Game/Beatmaps/BeatmapImporter.cs @@ -41,16 +41,18 @@ namespace osu.Game.Beatmaps { } - public async Task>> ImportAsUpdate(ProgressNotification notification, ImportTask importTask, BeatmapSetInfo original) + public override async Task?> ImportAsUpdate(ProgressNotification notification, ImportTask importTask, BeatmapSetInfo original) { var imported = await Import(notification, importTask); if (!imported.Any()) - return imported; + return null; Debug.Assert(imported.Count() == 1); - imported.First().PerformWrite(updated => + var first = imported.First(); + + first.PerformWrite(updated => { var realm = updated.Realm; @@ -103,7 +105,7 @@ namespace osu.Game.Beatmaps realm.Remove(original); }); - return imported; + return first; } protected override bool ShouldDeleteArchive(string path) => Path.GetExtension(path).ToLowerInvariant() == ".osz"; diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 1b31d29c2b..debe4c6829 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -408,7 +408,7 @@ namespace osu.Game.Beatmaps Realm.Run(r => Undelete(r.All().Where(s => s.DeletePending).ToList())); } - public Task>> ImportAsUpdate(ProgressNotification notification, ImportTask importTask, BeatmapSetInfo original) => + public Task?> ImportAsUpdate(ProgressNotification notification, ImportTask importTask, BeatmapSetInfo original) => beatmapImporter.ImportAsUpdate(notification, importTask, original); #region Implementation of ICanAcceptFiles diff --git a/osu.Game/Beatmaps/BeatmapModelDownloader.cs b/osu.Game/Beatmaps/BeatmapModelDownloader.cs index e70168f1b3..4295def5c3 100644 --- a/osu.Game/Beatmaps/BeatmapModelDownloader.cs +++ b/osu.Game/Beatmaps/BeatmapModelDownloader.cs @@ -1,39 +1,23 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Collections.Generic; -using System.Threading.Tasks; using osu.Game.Database; using osu.Game.Online.API; using osu.Game.Online.API.Requests; -using osu.Game.Overlays.Notifications; namespace osu.Game.Beatmaps { public class BeatmapModelDownloader : ModelDownloader { - private readonly BeatmapManager beatmapManager; - protected override ArchiveDownloadRequest CreateDownloadRequest(IBeatmapSetInfo set, bool minimiseDownloadSize) => new DownloadBeatmapSetRequest(set, minimiseDownloadSize); public override ArchiveDownloadRequest? GetExistingDownload(IBeatmapSetInfo model) => CurrentDownloads.Find(r => r.Model.OnlineID == model.OnlineID); - public BeatmapModelDownloader(BeatmapManager beatmapImporter, IAPIProvider api) + public BeatmapModelDownloader(IModelImporter beatmapImporter, IAPIProvider api) : base(beatmapImporter, api) { - beatmapManager = beatmapImporter; } - - protected override Task>> Import(ProgressNotification notification, string filename, BeatmapSetInfo? originalModel) - { - if (originalModel != null) - return beatmapManager.ImportAsUpdate(notification, new ImportTask(filename), originalModel); - - return base.Import(notification, filename, null); - } - - public bool Update(BeatmapSetInfo model) => Download(model, false, model); } } diff --git a/osu.Game/Database/IModelImporter.cs b/osu.Game/Database/IModelImporter.cs index ebb8be39ef..4085f122d0 100644 --- a/osu.Game/Database/IModelImporter.cs +++ b/osu.Game/Database/IModelImporter.cs @@ -23,6 +23,16 @@ namespace osu.Game.Database /// The imported models. Task>> Import(ProgressNotification notification, params ImportTask[] tasks); + /// + /// Process a single import as an update for an existing model. + /// This will still run a full import, but perform any post-processing required to make it feel like an update to the user. + /// + /// The notification to update. + /// The import task. + /// The original model which is being updated. + /// The imported model. + Task?> ImportAsUpdate(ProgressNotification notification, ImportTask task, TModel original); + /// /// A user displayable name for the model type associated with this manager. /// diff --git a/osu.Game/Database/ModelDownloader.cs b/osu.Game/Database/ModelDownloader.cs index 5fd124cafc..7ce0fa46b7 100644 --- a/osu.Game/Database/ModelDownloader.cs +++ b/osu.Game/Database/ModelDownloader.cs @@ -44,6 +44,8 @@ namespace osu.Game.Database public bool Download(T model, bool minimiseDownloadSize = false) => Download(model, minimiseDownloadSize, null); + public void DownloadAsUpdate(TModel originalModel) => Download(originalModel, false, originalModel); + protected bool Download(T model, bool minimiseDownloadSize, TModel? originalModel) { if (!canDownload(model)) return false; @@ -66,7 +68,7 @@ namespace osu.Game.Database Task.Factory.StartNew(async () => { // This gets scheduled back to the update thread, but we want the import to run in the background. - var imported = await Import(notification, filename, originalModel).ConfigureAwait(false); + var imported = await importer.Import(notification, new ImportTask(filename)).ConfigureAwait(false); // for now a failed import will be marked as a failed download for simplicity. if (!imported.Any()) @@ -105,18 +107,6 @@ namespace osu.Game.Database } } - /// - /// Run the post-download import for the model. - /// - /// The notification to update. - /// The path of the temporary downloaded file. - /// An optional model for update scenarios, to be used as a reference. - /// The imported model. - protected virtual Task>> Import(ProgressNotification notification, string filename, TModel? originalModel) - { - return importer.Import(notification, new ImportTask(filename)); - } - public abstract ArchiveDownloadRequest? GetExistingDownload(T model); private bool canDownload(T model) => GetExistingDownload(model) == null && api != null; diff --git a/osu.Game/Database/RealmArchiveModelImporter.cs b/osu.Game/Database/RealmArchiveModelImporter.cs index aa7fac07a8..a0cf98b978 100644 --- a/osu.Game/Database/RealmArchiveModelImporter.cs +++ b/osu.Game/Database/RealmArchiveModelImporter.cs @@ -174,6 +174,8 @@ namespace osu.Game.Database return imported; } + public virtual Task?> ImportAsUpdate(ProgressNotification notification, ImportTask task, TModel original) => throw new NotImplementedException(); + /// /// Import one from the filesystem and delete the file on success. /// Note that this bypasses the UI flow and should only be used for special cases or testing. diff --git a/osu.Game/Scoring/ScoreManager.cs b/osu.Game/Scoring/ScoreManager.cs index 7cfc55580b..7367a1ef77 100644 --- a/osu.Game/Scoring/ScoreManager.cs +++ b/osu.Game/Scoring/ScoreManager.cs @@ -268,6 +268,8 @@ namespace osu.Game.Scoring public Task>> Import(ProgressNotification notification, params ImportTask[] tasks) => scoreImporter.Import(notification, tasks); + public Task> ImportAsUpdate(ProgressNotification notification, ImportTask task, ScoreInfo original) => scoreImporter.ImportAsUpdate(notification, task, original); + public Live Import(ScoreInfo item, ArchiveReader archive = null, bool batchImport = false, CancellationToken cancellationToken = default) => scoreImporter.ImportModel(item, archive, batchImport, cancellationToken); diff --git a/osu.Game/Screens/Select/Carousel/UpdateBeatmapSetButton.cs b/osu.Game/Screens/Select/Carousel/UpdateBeatmapSetButton.cs index 3746c1975c..73e7d23df0 100644 --- a/osu.Game/Screens/Select/Carousel/UpdateBeatmapSetButton.cs +++ b/osu.Game/Screens/Select/Carousel/UpdateBeatmapSetButton.cs @@ -90,7 +90,7 @@ namespace osu.Game.Screens.Select.Carousel Action = () => { - beatmapDownloader.Update(beatmapSetInfo); + beatmapDownloader.DownloadAsUpdate(beatmapSetInfo); attachExistingDownload(); }; } diff --git a/osu.Game/Skinning/SkinManager.cs b/osu.Game/Skinning/SkinManager.cs index dc0197e613..dd35f83434 100644 --- a/osu.Game/Skinning/SkinManager.cs +++ b/osu.Game/Skinning/SkinManager.cs @@ -272,6 +272,8 @@ namespace osu.Game.Skinning public Task>> Import(ProgressNotification notification, params ImportTask[] tasks) => skinImporter.Import(notification, tasks); + public Task> ImportAsUpdate(ProgressNotification notification, ImportTask task, SkinInfo original) => skinImporter.ImportAsUpdate(notification, task, original); + public Task> Import(ImportTask task, bool batchImport = false, CancellationToken cancellationToken = default) => skinImporter.Import(task, batchImport, cancellationToken); #endregion From 9939866f7d3e65796fa61c39880c36a38b3258aa Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 26 Jul 2022 15:54:10 +0900 Subject: [PATCH 073/278] Revert one more missed change --- osu.Game/Beatmaps/Drawables/BundledBeatmapDownloader.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Beatmaps/Drawables/BundledBeatmapDownloader.cs b/osu.Game/Beatmaps/Drawables/BundledBeatmapDownloader.cs index bcbe7084d5..80af4108c7 100644 --- a/osu.Game/Beatmaps/Drawables/BundledBeatmapDownloader.cs +++ b/osu.Game/Beatmaps/Drawables/BundledBeatmapDownloader.cs @@ -11,6 +11,7 @@ using System.Text.RegularExpressions; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Game.Database; using osu.Game.Online; using osu.Game.Online.API; using osu.Game.Online.API.Requests; @@ -108,7 +109,7 @@ namespace osu.Game.Beatmaps.Drawables private class BundledBeatmapModelDownloader : BeatmapModelDownloader { - public BundledBeatmapModelDownloader(BeatmapManager beatmapImporter, IAPIProvider api) + public BundledBeatmapModelDownloader(IModelImporter beatmapImporter, IAPIProvider api) : base(beatmapImporter, api) { } From a4f6f2b9eb8ad8a5e0f0ca35d6c641a3fc411360 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Tue, 26 Jul 2022 09:55:37 +0300 Subject: [PATCH 074/278] Make item ID comparer static --- osu.Game/Screens/Select/Carousel/CarouselGroup.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/Select/Carousel/CarouselGroup.cs b/osu.Game/Screens/Select/Carousel/CarouselGroup.cs index 7fcf53e68c..8d141b6f72 100644 --- a/osu.Game/Screens/Select/Carousel/CarouselGroup.cs +++ b/osu.Game/Screens/Select/Carousel/CarouselGroup.cs @@ -24,7 +24,8 @@ namespace osu.Game.Screens.Select.Carousel private ulong currentItemID; private Comparer? criteriaComparer; - private Comparer? itemIDComparer; + + private static readonly Comparer item_id_comparer = Comparer.Create((x, y) => x.ItemID.CompareTo(y.ItemID)); private FilterCriteria? lastCriteria; @@ -91,8 +92,7 @@ namespace osu.Game.Screens.Select.Carousel // IEnumerable.OrderBy() is used instead of List.Sort() to ensure sorting stability criteriaComparer = Comparer.Create((x, y) => x.CompareTo(criteria, y)); - itemIDComparer = Comparer.Create((x, y) => x.ItemID.CompareTo(y.ItemID)); - items = items.OrderBy(c => c, criteriaComparer).ThenBy(c => c, itemIDComparer).ToList(); + items = items.OrderBy(c => c, criteriaComparer).ThenBy(c => c, item_id_comparer).ToList(); lastCriteria = criteria; } From 91ffa7007f85f56cbe96f1c23111624a16e13172 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Tue, 26 Jul 2022 10:24:16 +0300 Subject: [PATCH 075/278] Improve existing test coverage to cover order changes from other sort modes --- .../Visual/SongSelect/TestSceneBeatmapCarousel.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapCarousel.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapCarousel.cs index e574ee30fb..59932f8781 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapCarousel.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapCarousel.cs @@ -522,15 +522,15 @@ namespace osu.Game.Tests.Visual.SongSelect { var sets = new List(); - for (int i = 0; i < 20; i++) + for (int i = 0; i < 10; i++) { var set = TestResources.CreateTestBeatmapSetInfo(); // only need to set the first as they are a shared reference. var beatmap = set.Beatmaps.First(); - beatmap.Metadata.Artist = "same artist"; - beatmap.Metadata.Title = "same title"; + beatmap.Metadata.Artist = $"artist {i / 2}"; + beatmap.Metadata.Title = $"title {9 - i}"; sets.Add(set); } @@ -540,10 +540,13 @@ namespace osu.Game.Tests.Visual.SongSelect loadBeatmaps(sets); AddStep("Sort by artist", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Artist }, false)); - AddAssert("Items remain in original order", () => carousel.BeatmapSets.Select((set, index) => set.OnlineID == index + idOffset).All(b => b)); + AddAssert("Items remain in original order", () => carousel.BeatmapSets.Select((set, index) => set.OnlineID == idOffset + index).All(b => b)); AddStep("Sort by title", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Title }, false)); - AddAssert("Items remain in original order", () => carousel.BeatmapSets.Select((set, index) => set.OnlineID == index + idOffset).All(b => b)); + AddAssert("Items are in reverse order", () => carousel.BeatmapSets.Select((set, index) => set.OnlineID == idOffset + sets.Count - index - 1).All(b => b)); + + AddStep("Sort by artist", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Artist }, false)); + AddAssert("Items reset to original order", () => carousel.BeatmapSets.Select((set, index) => set.OnlineID == idOffset + index).All(b => b)); } [Test] From 846291d20387ecf0e23669edb100ec288a3675b7 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 26 Jul 2022 16:30:44 +0900 Subject: [PATCH 076/278] Refactor new tests to not suck as much as the old importer tests --- .../Database/BeatmapImporterUpdateTests.cs | 107 +++++++++++------- 1 file changed, 69 insertions(+), 38 deletions(-) diff --git a/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs b/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs index cf4245ae83..38c5172227 100644 --- a/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs +++ b/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs @@ -1,15 +1,19 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Diagnostics; using System.IO; using System.Linq; +using System.Linq.Expressions; using NUnit.Framework; +using osu.Framework.Allocation; using osu.Game.Beatmaps; using osu.Game.Database; using osu.Game.Overlays.Notifications; using osu.Game.Rulesets; using osu.Game.Tests.Resources; +using Realms; using SharpCompress.Archives; using SharpCompress.Archives.Zip; using SharpCompress.Common; @@ -24,58 +28,85 @@ namespace osu.Game.Tests.Database public class BeatmapImporterUpdateTests : RealmTest { [Test] - public void TestImportThenUpdateWithNewDifficulty() + public void TestNewDifficultyAdded() { RunTestWithRealmAsync(async (realm, storage) => { var importer = new BeatmapImporter(storage, realm); - using var store = new RealmRulesetStore(realm, storage); + using var rulesets = new RealmRulesetStore(realm, storage); - string? pathOriginal = TestResources.GetTestBeatmapForImport(); - - string pathMissingOneBeatmap = pathOriginal.Replace(".osz", "_missing_difficulty.osz"); - - string extractedFolder = $"{pathOriginal}_extracted"; - Directory.CreateDirectory(extractedFolder); - - try + using var __ = getBeatmapArchive(out string pathOriginal); + using var _ = getBeatmapArchiveWithModifications(out string pathMissingOneBeatmap, directory => { - using (var zip = ZipArchive.Open(pathOriginal)) - zip.WriteToDirectory(extractedFolder); - // remove one difficulty before first import - new FileInfo(Directory.GetFiles(extractedFolder, "*.osu").First()).Delete(); + directory.GetFiles("*.osu").First().Delete(); + }); - using (var zip = ZipArchive.Create()) - { - zip.AddAllFromDirectory(extractedFolder); - zip.SaveTo(pathMissingOneBeatmap, new ZipWriterOptions(CompressionType.Deflate)); - } + var importBeforeUpdate = await importer.Import(new ImportTask(pathMissingOneBeatmap)); - var firstImport = await importer.Import(new ImportTask(pathMissingOneBeatmap)); - Assert.That(firstImport, Is.Not.Null); - Debug.Assert(firstImport != null); + Assert.That(importBeforeUpdate, Is.Not.Null); + Debug.Assert(importBeforeUpdate != null); - Assert.That(realm.Realm.All().Where(s => !s.DeletePending), Has.Count.EqualTo(1)); - Assert.That(realm.Realm.All().First(s => !s.DeletePending).Beatmaps, Has.Count.EqualTo(11)); + checkCount(realm, 1, s => !s.DeletePending); + Assert.That(importBeforeUpdate.Value.Beatmaps, Has.Count.EqualTo(11)); - // Second import matches first but contains one extra .osu file. - var secondImport = await importer.ImportAsUpdate(new ProgressNotification(), new ImportTask(pathOriginal), firstImport.Value); - Assert.That(secondImport, Is.Not.Null); - Debug.Assert(secondImport != null); + // Second import matches first but contains one extra .osu file. + var importAfterUpdate = await importer.ImportAsUpdate(new ProgressNotification(), new ImportTask(pathOriginal), importBeforeUpdate.Value); - Assert.That(realm.Realm.All(), Has.Count.EqualTo(12)); - Assert.That(realm.Realm.All(), Has.Count.EqualTo(12)); - Assert.That(realm.Realm.All(), Has.Count.EqualTo(1)); + Assert.That(importAfterUpdate, Is.Not.Null); + Debug.Assert(importAfterUpdate != null); - // check the newly "imported" beatmap is not the original. - Assert.That(firstImport.ID, Is.Not.EqualTo(secondImport.ID)); - } - finally - { - Directory.Delete(extractedFolder, true); - } + checkCount(realm, 12); + checkCount(realm, 12); + checkCount(realm, 1); + + // check the newly "imported" beatmap is not the original. + Assert.That(importBeforeUpdate.ID, Is.Not.EqualTo(importAfterUpdate.ID)); }); } + + private static void checkCount(RealmAccess realm, int expected, Expression>? condition = null) where T : RealmObject + { + var query = realm.Realm.All(); + + if (condition != null) + query = query.Where(condition); + + Assert.That(query, Has.Count.EqualTo(expected)); + } + + private static IDisposable getBeatmapArchiveWithModifications(out string path, Action applyModifications) + { + var cleanup = getBeatmapArchive(out path); + + string extractedFolder = $"{path}_extracted"; + Directory.CreateDirectory(extractedFolder); + + using (var zip = ZipArchive.Open(path)) + zip.WriteToDirectory(extractedFolder); + + applyModifications(new DirectoryInfo(extractedFolder)); + + File.Delete(path); + + using (var zip = ZipArchive.Create()) + { + zip.AddAllFromDirectory(extractedFolder); + zip.SaveTo(path, new ZipWriterOptions(CompressionType.Deflate)); + } + + Directory.Delete(extractedFolder, true); + + return cleanup; + } + + private static IDisposable getBeatmapArchive(out string path, bool quick = true) + { + string beatmapPath = TestResources.GetTestBeatmapForImport(quick); + + path = beatmapPath; + + return new InvokeOnDisposal(() => File.Delete(beatmapPath)); + } } } From 4c22b55ce345a7e0b05aef98f165e1969fd42332 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 26 Jul 2022 17:00:28 +0900 Subject: [PATCH 077/278] Fix incorrect handling if an update is processed with no changes --- osu.Game/Beatmaps/BeatmapImporter.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/osu.Game/Beatmaps/BeatmapImporter.cs b/osu.Game/Beatmaps/BeatmapImporter.cs index 1e90e14e68..ef0e76234a 100644 --- a/osu.Game/Beatmaps/BeatmapImporter.cs +++ b/osu.Game/Beatmaps/BeatmapImporter.cs @@ -52,6 +52,10 @@ namespace osu.Game.Beatmaps var first = imported.First(); + // If there were no changes, ensure we don't accidentally nuke ourselves. + if (first.ID == original.ID) + return first; + first.PerformWrite(updated => { var realm = updated.Realm; From aaf6ec05bbef6d30b9be0e5e8f9775e882c5c3c5 Mon Sep 17 00:00:00 2001 From: Andrew Hong Date: Tue, 26 Jul 2022 04:19:54 -0400 Subject: [PATCH 078/278] Remove notification upon copy --- .../Graphics/UserInterface/ExternalLinkButton.cs | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs b/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs index 166546bb8a..acabeca66e 100644 --- a/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs +++ b/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs @@ -13,8 +13,6 @@ using osu.Framework.Graphics.UserInterface; using osu.Framework.Input.Events; using osu.Framework.Localisation; using osu.Framework.Platform; -using osu.Game.Overlays; -using osu.Game.Overlays.Notifications; using osuTK; using osuTK.Graphics; @@ -24,9 +22,6 @@ namespace osu.Game.Graphics.UserInterface { public string Link { get; set; } - [Resolved] - private INotificationOverlay notificationOverlay { get; set; } - private Color4 hoverColour; [Resolved] @@ -49,15 +44,6 @@ namespace osu.Game.Graphics.UserInterface }; } - private void copyUrl() - { - host.GetClipboard()?.SetText(Link); - notificationOverlay.Post(new SimpleNotification - { - Text = "Copied URL!" - }); - } - public MenuItem[] ContextMenuItems { get @@ -67,7 +53,7 @@ namespace osu.Game.Graphics.UserInterface if (Link != null) { items.Add(new OsuMenuItem("Open", MenuItemType.Standard, () => host.OpenUrlExternally(Link))); - items.Add(new OsuMenuItem("Copy URL", MenuItemType.Standard, () => copyUrl())); + items.Add(new OsuMenuItem("Copy URL", MenuItemType.Standard, () => host.GetClipboard()?.SetText(Link))); } return items.ToArray(); From 1221cb1a42a68265c0f80151514b6952442e9fdf Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 26 Jul 2022 17:22:52 +0900 Subject: [PATCH 079/278] Add comprehensive test coverage of update scenarios --- .../Database/BeatmapImporterUpdateTests.cs | 289 +++++++++++++++++- 1 file changed, 286 insertions(+), 3 deletions(-) diff --git a/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs b/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs index 38c5172227..515bed5c35 100644 --- a/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs +++ b/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs @@ -10,8 +10,10 @@ using NUnit.Framework; using osu.Framework.Allocation; using osu.Game.Beatmaps; using osu.Game.Database; +using osu.Game.Models; using osu.Game.Overlays.Notifications; using osu.Game.Rulesets; +using osu.Game.Scoring; using osu.Game.Tests.Resources; using Realms; using SharpCompress.Archives; @@ -27,6 +29,8 @@ namespace osu.Game.Tests.Database [TestFixture] public class BeatmapImporterUpdateTests : RealmTest { + private const int count_beatmaps = 12; + [Test] public void TestNewDifficultyAdded() { @@ -48,7 +52,7 @@ namespace osu.Game.Tests.Database Debug.Assert(importBeforeUpdate != null); checkCount(realm, 1, s => !s.DeletePending); - Assert.That(importBeforeUpdate.Value.Beatmaps, Has.Count.EqualTo(11)); + Assert.That(importBeforeUpdate.Value.Beatmaps, Has.Count.EqualTo(count_beatmaps - 1)); // Second import matches first but contains one extra .osu file. var importAfterUpdate = await importer.ImportAsUpdate(new ProgressNotification(), new ImportTask(pathOriginal), importBeforeUpdate.Value); @@ -56,12 +60,291 @@ namespace osu.Game.Tests.Database Assert.That(importAfterUpdate, Is.Not.Null); Debug.Assert(importAfterUpdate != null); - checkCount(realm, 12); - checkCount(realm, 12); + checkCount(realm, count_beatmaps); + checkCount(realm, count_beatmaps); checkCount(realm, 1); // check the newly "imported" beatmap is not the original. Assert.That(importBeforeUpdate.ID, Is.Not.EqualTo(importAfterUpdate.ID)); + + // Previous beatmap set has no beatmaps so will be completely purged on the spot. + Assert.That(importBeforeUpdate.Value.IsValid, Is.False); + }); + } + + [Test] + public void TestExistingDifficultyModified() + { + RunTestWithRealmAsync(async (realm, storage) => + { + var importer = new BeatmapImporter(storage, realm); + using var rulesets = new RealmRulesetStore(realm, storage); + + using var __ = getBeatmapArchive(out string pathOriginal); + using var _ = getBeatmapArchiveWithModifications(out string pathModified, directory => + { + // Modify one .osu file with different content. + var firstOsuFile = directory.GetFiles("*.osu").First(); + + string existingContent = File.ReadAllText(firstOsuFile.FullName); + + File.WriteAllText(firstOsuFile.FullName, existingContent + "\n# I am new content"); + }); + + var importBeforeUpdate = await importer.Import(new ImportTask(pathOriginal)); + + Assert.That(importBeforeUpdate, Is.Not.Null); + Debug.Assert(importBeforeUpdate != null); + + checkCount(realm, 1, s => !s.DeletePending); + Assert.That(importBeforeUpdate.Value.Beatmaps, Has.Count.EqualTo(count_beatmaps)); + + // Second import matches first but contains one extra .osu file. + var importAfterUpdate = await importer.ImportAsUpdate(new ProgressNotification(), new ImportTask(pathModified), importBeforeUpdate.Value); + + Assert.That(importAfterUpdate, Is.Not.Null); + Debug.Assert(importAfterUpdate != null); + + // should only contain the modified beatmap (others purged). + Assert.That(importBeforeUpdate.Value.Beatmaps, Has.Count.EqualTo(1)); + Assert.That(importAfterUpdate.Value.Beatmaps, Has.Count.EqualTo(count_beatmaps)); + + checkCount(realm, count_beatmaps + 1); + checkCount(realm, count_beatmaps + 1); + + checkCount(realm, 1, s => !s.DeletePending); + checkCount(realm, 1, s => s.DeletePending); + }); + } + + [Test] + public void TestExistingDifficultyRemoved() + { + RunTestWithRealmAsync(async (realm, storage) => + { + var importer = new BeatmapImporter(storage, realm); + using var rulesets = new RealmRulesetStore(realm, storage); + + using var __ = getBeatmapArchive(out string pathOriginal); + using var _ = getBeatmapArchiveWithModifications(out string pathMissingOneBeatmap, directory => + { + // remove one difficulty before first import + directory.GetFiles("*.osu").First().Delete(); + }); + + var importBeforeUpdate = await importer.Import(new ImportTask(pathOriginal)); + + Assert.That(importBeforeUpdate, Is.Not.Null); + Debug.Assert(importBeforeUpdate != null); + + Assert.That(importBeforeUpdate.Value.Beatmaps, Has.Count.EqualTo(count_beatmaps)); + Assert.That(importBeforeUpdate.Value.Beatmaps.First().OnlineID, Is.GreaterThan(-1)); + + // Second import matches first but contains one extra .osu file. + var importAfterUpdate = await importer.ImportAsUpdate(new ProgressNotification(), new ImportTask(pathMissingOneBeatmap), importBeforeUpdate.Value); + + Assert.That(importAfterUpdate, Is.Not.Null); + Debug.Assert(importAfterUpdate != null); + + checkCount(realm, count_beatmaps); + checkCount(realm, count_beatmaps); + checkCount(realm, 2); + + // previous set should contain the removed beatmap still. + Assert.That(importBeforeUpdate.Value.Beatmaps, Has.Count.EqualTo(1)); + Assert.That(importBeforeUpdate.Value.Beatmaps.First().OnlineID, Is.EqualTo(-1)); + + // Previous beatmap set has no beatmaps so will be completely purged on the spot. + Assert.That(importAfterUpdate.Value.Beatmaps, Has.Count.EqualTo(count_beatmaps - 1)); + }); + } + + [Test] + public void TestUpdatedImportContainsNothing() + { + RunTestWithRealmAsync(async (realm, storage) => + { + var importer = new BeatmapImporter(storage, realm); + using var rulesets = new RealmRulesetStore(realm, storage); + + using var __ = getBeatmapArchive(out string pathOriginal); + using var _ = getBeatmapArchiveWithModifications(out string pathEmpty, directory => + { + foreach (var file in directory.GetFiles()) + file.Delete(); + }); + + var importBeforeUpdate = await importer.Import(new ImportTask(pathOriginal)); + + Assert.That(importBeforeUpdate, Is.Not.Null); + Debug.Assert(importBeforeUpdate != null); + + var importAfterUpdate = await importer.ImportAsUpdate(new ProgressNotification(), new ImportTask(pathEmpty), importBeforeUpdate.Value); + Assert.That(importAfterUpdate, Is.Null); + + checkCount(realm, 1); + checkCount(realm, count_beatmaps); + checkCount(realm, count_beatmaps); + + Assert.That(importBeforeUpdate.Value.IsValid, Is.True); + }); + } + + [Test] + public void TestNoChanges() + { + RunTestWithRealmAsync(async (realm, storage) => + { + var importer = new BeatmapImporter(storage, realm); + using var rulesets = new RealmRulesetStore(realm, storage); + + using var __ = getBeatmapArchive(out string pathOriginal); + using var _ = getBeatmapArchive(out string pathOriginalSecond); + + var importBeforeUpdate = await importer.Import(new ImportTask(pathOriginal)); + + Assert.That(importBeforeUpdate, Is.Not.Null); + Debug.Assert(importBeforeUpdate != null); + + var importAfterUpdate = await importer.ImportAsUpdate(new ProgressNotification(), new ImportTask(pathOriginalSecond), importBeforeUpdate.Value); + + Assert.That(importAfterUpdate, Is.Not.Null); + Debug.Assert(importAfterUpdate != null); + + checkCount(realm, 1); + checkCount(realm, count_beatmaps); + checkCount(realm, count_beatmaps); + + Assert.That(importBeforeUpdate.Value.Beatmaps.First().OnlineID, Is.GreaterThan(-1)); + Assert.That(importBeforeUpdate.ID, Is.EqualTo(importAfterUpdate.ID)); + }); + } + + [Test] + public void TestScoreTransferredOnUnchanged() + { + RunTestWithRealmAsync(async (realm, storage) => + { + var importer = new BeatmapImporter(storage, realm); + using var rulesets = new RealmRulesetStore(realm, storage); + + using var __ = getBeatmapArchive(out string pathOriginal); + using var _ = getBeatmapArchiveWithModifications(out string pathMissingOneBeatmap, directory => + { + // arbitrary beatmap removal + directory.GetFiles("*.osu").First().Delete(); + }); + + var importBeforeUpdate = await importer.Import(new ImportTask(pathOriginal)); + + Assert.That(importBeforeUpdate, Is.Not.Null); + Debug.Assert(importBeforeUpdate != null); + + string scoreTargetBeatmapHash = string.Empty; + + importBeforeUpdate.PerformWrite(s => + { + var beatmapInfo = s.Beatmaps.Last(); + scoreTargetBeatmapHash = beatmapInfo.Hash; + s.Realm.Add(new ScoreInfo(beatmapInfo, s.Realm.All().First(), new RealmUser())); + }); + + checkCount(realm, 1); + + var importAfterUpdate = await importer.ImportAsUpdate(new ProgressNotification(), new ImportTask(pathMissingOneBeatmap), importBeforeUpdate.Value); + + Assert.That(importAfterUpdate, Is.Not.Null); + Debug.Assert(importAfterUpdate != null); + + checkCount(realm, count_beatmaps); + checkCount(realm, count_beatmaps); + checkCount(realm, 2); + + // score is transferred across to the new set + checkCount(realm, 1); + Assert.That(importAfterUpdate.Value.Beatmaps.First(b => b.Hash == scoreTargetBeatmapHash).Scores, Has.Count.EqualTo(1)); + }); + } + + [Test] + public void TestScoreLostOnModification() + { + RunTestWithRealmAsync(async (realm, storage) => + { + var importer = new BeatmapImporter(storage, realm); + using var rulesets = new RealmRulesetStore(realm, storage); + + using var __ = getBeatmapArchive(out string pathOriginal); + + var importBeforeUpdate = await importer.Import(new ImportTask(pathOriginal)); + + Assert.That(importBeforeUpdate, Is.Not.Null); + Debug.Assert(importBeforeUpdate != null); + + string? scoreTargetFilename = string.Empty; + + importBeforeUpdate.PerformWrite(s => + { + var beatmapInfo = s.Beatmaps.Last(); + scoreTargetFilename = beatmapInfo.File?.Filename; + s.Realm.Add(new ScoreInfo(beatmapInfo, s.Realm.All().First(), new RealmUser())); + }); + + checkCount(realm, 1); + + using var _ = getBeatmapArchiveWithModifications(out string pathModified, directory => + { + // Modify one .osu file with different content. + var firstOsuFile = directory.GetFiles(scoreTargetFilename).First(); + + string existingContent = File.ReadAllText(firstOsuFile.FullName); + + File.WriteAllText(firstOsuFile.FullName, existingContent + "\n# I am new content"); + }); + + var importAfterUpdate = await importer.ImportAsUpdate(new ProgressNotification(), new ImportTask(pathModified), importBeforeUpdate.Value); + + Assert.That(importAfterUpdate, Is.Not.Null); + Debug.Assert(importAfterUpdate != null); + + checkCount(realm, count_beatmaps + 1); + checkCount(realm, count_beatmaps + 1); + checkCount(realm, 2); + + // score is not transferred due to modifications. + checkCount(realm, 1); + Assert.That(importBeforeUpdate.Value.Beatmaps.AsEnumerable().First(b => b.File?.Filename == scoreTargetFilename).Scores, Has.Count.EqualTo(1)); + Assert.That(importAfterUpdate.Value.Beatmaps.AsEnumerable().First(b => b.File?.Filename == scoreTargetFilename).Scores, Has.Count.EqualTo(0)); + }); + } + + [Test] + public void TestMetadataTransferred() + { + RunTestWithRealmAsync(async (realm, storage) => + { + var importer = new BeatmapImporter(storage, realm); + using var rulesets = new RealmRulesetStore(realm, storage); + + using var __ = getBeatmapArchive(out string pathOriginal); + using var _ = getBeatmapArchiveWithModifications(out string pathMissingOneBeatmap, directory => + { + // arbitrary beatmap removal + directory.GetFiles("*.osu").First().Delete(); + }); + + var importBeforeUpdate = await importer.Import(new ImportTask(pathOriginal)); + + Assert.That(importBeforeUpdate, Is.Not.Null); + Debug.Assert(importBeforeUpdate != null); + + var importAfterUpdate = await importer.ImportAsUpdate(new ProgressNotification(), new ImportTask(pathMissingOneBeatmap), importBeforeUpdate.Value); + + Assert.That(importAfterUpdate, Is.Not.Null); + Debug.Assert(importAfterUpdate != null); + + Assert.That(importBeforeUpdate.ID, Is.Not.EqualTo(importAfterUpdate.ID)); + Assert.That(importBeforeUpdate.Value.DateAdded, Is.EqualTo(importAfterUpdate.Value.DateAdded)); }); } From 003aec86ae8b2304804d129c3c90cf2776aa627e Mon Sep 17 00:00:00 2001 From: Andrew Hong Date: Tue, 26 Jul 2022 04:27:22 -0400 Subject: [PATCH 080/278] Rearrange sizeaxes --- osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs b/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs index c02c42786b..9e14122ae4 100644 --- a/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs +++ b/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs @@ -93,7 +93,8 @@ namespace osu.Game.Overlays.BeatmapSet }, new OsuContextMenuContainer { - RelativeSizeAxes = Axes.Both, + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, Child = new Container { RelativeSizeAxes = Axes.X, From ee694c12576369bd0b04cf58a4b4607e22812375 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 26 Jul 2022 17:27:23 +0900 Subject: [PATCH 081/278] Add test coverage of no online ID scenario --- .../Database/BeatmapImporterUpdateTests.cs | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs b/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs index 515bed5c35..a82386fd51 100644 --- a/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs +++ b/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs @@ -72,6 +72,58 @@ namespace osu.Game.Tests.Database }); } + /// + /// Regression test covering https://github.com/ppy/osu/issues/19369 (import potentially duplicating if original has no ). + /// + [Test] + public void TestNewDifficultyAddedNoOnlineID() + { + RunTestWithRealmAsync(async (realm, storage) => + { + var importer = new BeatmapImporter(storage, realm); + using var rulesets = new RealmRulesetStore(realm, storage); + + using var __ = getBeatmapArchive(out string pathOriginal); + using var _ = getBeatmapArchiveWithModifications(out string pathMissingOneBeatmap, directory => + { + // remove one difficulty before first import + directory.GetFiles("*.osu").First().Delete(); + }); + + var importBeforeUpdate = await importer.Import(new ImportTask(pathMissingOneBeatmap)); + + Assert.That(importBeforeUpdate, Is.Not.Null); + Debug.Assert(importBeforeUpdate != null); + + // This test is the same as TestNewDifficultyAdded except for this block. + importBeforeUpdate.PerformWrite(s => + { + s.OnlineID = -1; + foreach (var beatmap in s.Beatmaps) + beatmap.ResetOnlineInfo(); + }); + + checkCount(realm, 1, s => !s.DeletePending); + Assert.That(importBeforeUpdate.Value.Beatmaps, Has.Count.EqualTo(count_beatmaps - 1)); + + // Second import matches first but contains one extra .osu file. + var importAfterUpdate = await importer.ImportAsUpdate(new ProgressNotification(), new ImportTask(pathOriginal), importBeforeUpdate.Value); + + Assert.That(importAfterUpdate, Is.Not.Null); + Debug.Assert(importAfterUpdate != null); + + checkCount(realm, count_beatmaps); + checkCount(realm, count_beatmaps); + checkCount(realm, 1); + + // check the newly "imported" beatmap is not the original. + Assert.That(importBeforeUpdate.ID, Is.Not.EqualTo(importAfterUpdate.ID)); + + // Previous beatmap set has no beatmaps so will be completely purged on the spot. + Assert.That(importBeforeUpdate.Value.IsValid, Is.False); + }); + } + [Test] public void TestExistingDifficultyModified() { From 1539fa704bb1b8c1b64a297862007ba615d6bc78 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 26 Jul 2022 17:46:23 +0900 Subject: [PATCH 082/278] Always allow selecting the top-most button using the select binding --- osu.Game/Overlays/DialogOverlay.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/DialogOverlay.cs b/osu.Game/Overlays/DialogOverlay.cs index 493cd66258..ba8083e535 100644 --- a/osu.Game/Overlays/DialogOverlay.cs +++ b/osu.Game/Overlays/DialogOverlay.cs @@ -121,7 +121,11 @@ namespace osu.Game.Overlays switch (e.Action) { case GlobalAction.Select: - CurrentDialog?.Buttons.OfType().FirstOrDefault()?.TriggerClick(); + var clickableButton = + CurrentDialog?.Buttons.OfType().FirstOrDefault() ?? + CurrentDialog?.Buttons.First(); + + clickableButton?.TriggerClick(); return true; } From 91732719005dde9e7aa6e031f8a76067fc4c873a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 26 Jul 2022 17:58:09 +0900 Subject: [PATCH 083/278] Fix new update pathway not actually being used --- osu.Game/Database/ModelDownloader.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/osu.Game/Database/ModelDownloader.cs b/osu.Game/Database/ModelDownloader.cs index 7ce0fa46b7..edb8563c65 100644 --- a/osu.Game/Database/ModelDownloader.cs +++ b/osu.Game/Database/ModelDownloader.cs @@ -67,11 +67,15 @@ namespace osu.Game.Database { Task.Factory.StartNew(async () => { - // This gets scheduled back to the update thread, but we want the import to run in the background. - var imported = await importer.Import(notification, new ImportTask(filename)).ConfigureAwait(false); + bool importSuccessful; + + if (originalModel != null) + importSuccessful = (await importer.ImportAsUpdate(notification, new ImportTask(filename), originalModel)) != null; + else + importSuccessful = (await importer.Import(notification, new ImportTask(filename))).Any(); // for now a failed import will be marked as a failed download for simplicity. - if (!imported.Any()) + if (!importSuccessful) DownloadFailed?.Invoke(request); CurrentDownloads.Remove(request); From e782590b3cc3f58a4a126041dc40a702edea6c66 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 26 Jul 2022 18:20:43 +0900 Subject: [PATCH 084/278] Don't show audio playback issue notification if debugger is attached I've hit this countless times recently when debugging during the startup procedure. --- osu.Game/Screens/Menu/IntroScreen.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/Menu/IntroScreen.cs b/osu.Game/Screens/Menu/IntroScreen.cs index c1621ce78f..a2ecd7eacb 100644 --- a/osu.Game/Screens/Menu/IntroScreen.cs +++ b/osu.Game/Screens/Menu/IntroScreen.cs @@ -4,6 +4,7 @@ #nullable disable using System; +using System.Diagnostics; using System.Linq; using JetBrains.Annotations; using osu.Framework.Allocation; @@ -195,10 +196,14 @@ namespace osu.Game.Screens.Menu PrepareMenuLoad(); LoadMenu(); - notifications.Post(new SimpleErrorNotification + + if (!Debugger.IsAttached) { - Text = "osu! doesn't seem to be able to play audio correctly.\n\nPlease try changing your audio device to a working setting." - }); + notifications.Post(new SimpleErrorNotification + { + Text = "osu! doesn't seem to be able to play audio correctly.\n\nPlease try changing your audio device to a working setting." + }); + } }, 5000); } From e28584da89b2694ebbaff3e75c91a7747594207e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=82=BA=E4=BB=80=E9=BA=BC?= Date: Sun, 10 Jul 2022 23:44:14 +0800 Subject: [PATCH 085/278] Remove nullable disable annotation in the Osu ruleset. --- osu.Game.Rulesets.Osu/Mods/IHidesApproachCircles.cs | 2 -- osu.Game.Rulesets.Osu/Mods/IRequiresApproachCircles.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModApproachDifferent.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModAutoplay.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModBarrelRoll.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModCinema.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModClassic.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModDaycore.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModDeflate.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModDifficultyAdjust.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModDoubleTime.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModEasy.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModGrow.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModHalfTime.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModHardRock.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModHidden.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModMagnetised.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModMirror.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModMuted.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModNightcore.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModNoFail.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModNoScope.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModObjectScaleTween.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModPerfect.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModRelax.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModSpinIn.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModSpunOut.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModStrictTracking.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModSuddenDeath.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModTouchDevice.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModTraceable.cs | 4 +--- osu.Game.Rulesets.Osu/Mods/OsuModTransform.cs | 2 -- osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs | 2 -- 37 files changed, 1 insertion(+), 75 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/IHidesApproachCircles.cs b/osu.Game.Rulesets.Osu/Mods/IHidesApproachCircles.cs index affc0bae6a..4a3b187e83 100644 --- a/osu.Game.Rulesets.Osu/Mods/IHidesApproachCircles.cs +++ b/osu.Game.Rulesets.Osu/Mods/IHidesApproachCircles.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - namespace osu.Game.Rulesets.Osu.Mods { /// diff --git a/osu.Game.Rulesets.Osu/Mods/IRequiresApproachCircles.cs b/osu.Game.Rulesets.Osu/Mods/IRequiresApproachCircles.cs index a108f5fd14..1458abfe05 100644 --- a/osu.Game.Rulesets.Osu/Mods/IRequiresApproachCircles.cs +++ b/osu.Game.Rulesets.Osu/Mods/IRequiresApproachCircles.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - namespace osu.Game.Rulesets.Osu.Mods { /// diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModApproachDifferent.cs b/osu.Game.Rulesets.Osu/Mods/OsuModApproachDifferent.cs index e25845f5ab..e6889403a3 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModApproachDifferent.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModApproachDifferent.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using osu.Framework.Bindables; using osu.Framework.Graphics; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs b/osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs index a3f6448457..2d579e511e 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModAutoplay.cs b/osu.Game.Rulesets.Osu/Mods/OsuModAutoplay.cs index c4de77b8a3..7c1f6be9ed 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModAutoplay.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModAutoplay.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBarrelRoll.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBarrelRoll.cs index 71bdd98457..9e71f657ce 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBarrelRoll.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBarrelRoll.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Osu.Objects; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs index 17a9a81de8..e3aa8f93d0 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using osu.Framework.Allocation; using osu.Framework.Graphics; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModCinema.cs b/osu.Game.Rulesets.Osu/Mods/OsuModCinema.cs index d5096619b9..769694baf4 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModCinema.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModCinema.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModClassic.cs b/osu.Game.Rulesets.Osu/Mods/OsuModClassic.cs index 00009f4c3d..e021992f86 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModClassic.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModClassic.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Linq; using osu.Framework.Bindables; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModDaycore.cs b/osu.Game.Rulesets.Osu/Mods/OsuModDaycore.cs index c4cc0b4f48..371dfe6a1a 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModDaycore.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModDaycore.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Osu.Mods diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModDeflate.cs b/osu.Game.Rulesets.Osu/Mods/OsuModDeflate.cs index e95e61312e..ee6a7815e2 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModDeflate.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModDeflate.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Bindables; using osu.Framework.Graphics.Sprites; using osu.Game.Configuration; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModDifficultyAdjust.cs b/osu.Game.Rulesets.Osu/Mods/OsuModDifficultyAdjust.cs index be159523b7..3a6b232f9f 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModDifficultyAdjust.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModDifficultyAdjust.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Linq; using osu.Game.Beatmaps; using osu.Game.Configuration; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModDoubleTime.cs b/osu.Game.Rulesets.Osu/Mods/OsuModDoubleTime.cs index b86efe84ee..700a3f44bc 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModDoubleTime.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModDoubleTime.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Osu.Mods diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModEasy.cs b/osu.Game.Rulesets.Osu/Mods/OsuModEasy.cs index 90b22e8d9c..06b5b6cfb8 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModEasy.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModEasy.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Osu.Mods diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs b/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs index b72e6b4dcb..25b900752c 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Linq; using osu.Framework.Bindables; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModGrow.cs b/osu.Game.Rulesets.Osu/Mods/OsuModGrow.cs index 34840de983..182d6eeb4b 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModGrow.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModGrow.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Bindables; using osu.Framework.Graphics.Sprites; using osu.Game.Configuration; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModHalfTime.cs b/osu.Game.Rulesets.Osu/Mods/OsuModHalfTime.cs index 54c5c56ca6..4769e7660b 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModHalfTime.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModHalfTime.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Osu.Mods diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModHardRock.cs b/osu.Game.Rulesets.Osu/Mods/OsuModHardRock.cs index 1f25655c8c..5430929143 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModHardRock.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModHardRock.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Linq; using osu.Game.Rulesets.Mods; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModHidden.cs b/osu.Game.Rulesets.Osu/Mods/OsuModHidden.cs index 253eaf473b..97f201b2cc 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModHidden.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModHidden.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Diagnostics; using System.Linq; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModMagnetised.cs b/osu.Game.Rulesets.Osu/Mods/OsuModMagnetised.cs index f9a74d2a3a..97a573f1b4 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModMagnetised.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModMagnetised.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using osu.Framework.Bindables; using osu.Framework.Graphics.Sprites; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModMirror.cs b/osu.Game.Rulesets.Osu/Mods/OsuModMirror.cs index 1d822a2d4c..3faca0b01f 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModMirror.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModMirror.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using osu.Framework.Bindables; using osu.Game.Configuration; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModMuted.cs b/osu.Game.Rulesets.Osu/Mods/OsuModMuted.cs index 1d4650a379..5e3ee37b61 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModMuted.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModMuted.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Osu.Objects; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModNightcore.cs b/osu.Game.Rulesets.Osu/Mods/OsuModNightcore.cs index b1fe066a1e..b7838ebaa7 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModNightcore.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModNightcore.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Osu.Objects; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModNoFail.cs b/osu.Game.Rulesets.Osu/Mods/OsuModNoFail.cs index c20fcf0b1b..9f707a5aa6 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModNoFail.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModNoFail.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Linq; using osu.Game.Rulesets.Mods; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModNoScope.cs b/osu.Game.Rulesets.Osu/Mods/OsuModNoScope.cs index fe415cb967..8e377ea632 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModNoScope.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModNoScope.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Linq; using osu.Framework.Bindables; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModObjectScaleTween.cs b/osu.Game.Rulesets.Osu/Mods/OsuModObjectScaleTween.cs index 44942e9e37..59984f9a7b 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModObjectScaleTween.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModObjectScaleTween.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using osu.Framework.Bindables; using osu.Framework.Graphics; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModPerfect.cs b/osu.Game.Rulesets.Osu/Mods/OsuModPerfect.cs index bde7718da5..33581405a6 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModPerfect.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModPerfect.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Linq; using osu.Game.Rulesets.Mods; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModRelax.cs b/osu.Game.Rulesets.Osu/Mods/OsuModRelax.cs index 2030156f2e..4c70b8f22c 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModRelax.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModRelax.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModSpinIn.cs b/osu.Game.Rulesets.Osu/Mods/OsuModSpinIn.cs index 16e7780af0..95e7d13ee7 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModSpinIn.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModSpinIn.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModSpunOut.cs b/osu.Game.Rulesets.Osu/Mods/OsuModSpunOut.cs index 61028a1ee8..d9ab749ad3 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModSpunOut.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModSpunOut.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModStrictTracking.cs b/osu.Game.Rulesets.Osu/Mods/OsuModStrictTracking.cs index 565ff415be..0b34ab28a3 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModStrictTracking.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModStrictTracking.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Linq; using System.Threading; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModSuddenDeath.cs b/osu.Game.Rulesets.Osu/Mods/OsuModSuddenDeath.cs index 4eb7659152..429fe30fc5 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModSuddenDeath.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModSuddenDeath.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Linq; using osu.Game.Rulesets.Mods; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs b/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs index f03bcffdc8..43169dac68 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModTouchDevice.cs b/osu.Game.Rulesets.Osu/Mods/OsuModTouchDevice.cs index f8c1e1639d..7276cc753c 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModTouchDevice.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModTouchDevice.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Osu.Mods diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModTraceable.cs b/osu.Game.Rulesets.Osu/Mods/OsuModTraceable.cs index 6e5dd45a7a..d862d36670 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModTraceable.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModTraceable.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; @@ -59,7 +57,7 @@ namespace osu.Game.Rulesets.Osu.Mods } } - private void applyCirclePieceState(DrawableOsuHitObject hitObject, IDrawable hitCircle = null) + private void applyCirclePieceState(DrawableOsuHitObject hitObject, IDrawable? hitCircle = null) { var h = hitObject.HitObject; using (hitObject.BeginAbsoluteSequence(h.StartTime - h.TimePreempt)) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModTransform.cs b/osu.Game.Rulesets.Osu/Mods/OsuModTransform.cs index 84906f6eed..4354ecbe9a 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModTransform.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModTransform.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs index 8acd4fc422..6bfbe25471 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; From deb39bd33030194a3d35a3167441333af07d9805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=82=BA=E4=BB=80=E9=BA=BC?= Date: Sun, 10 Jul 2022 23:49:38 +0800 Subject: [PATCH 086/278] Mark the property as nullable or non-nullable. --- osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs | 4 ++-- osu.Game.Rulesets.Osu/Mods/OsuModRelax.cs | 2 +- osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs index e3aa8f93d0..39234147a9 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs @@ -53,9 +53,9 @@ namespace osu.Game.Rulesets.Osu.Mods /// /// Black background boxes behind blind panel textures. /// - private Box blackBoxLeft, blackBoxRight; + private Box blackBoxLeft = null!, blackBoxRight = null!; - private Drawable panelLeft, panelRight, bgPanelLeft, bgPanelRight; + private Drawable panelLeft = null!, panelRight = null!, bgPanelLeft = null!, bgPanelRight = null!; private readonly Beatmap beatmap; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModRelax.cs b/osu.Game.Rulesets.Osu/Mods/OsuModRelax.cs index 4c70b8f22c..c9c3fdfc89 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModRelax.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModRelax.cs @@ -31,7 +31,7 @@ namespace osu.Game.Rulesets.Osu.Mods private OsuInputManager osuInputManager; - private ReplayState state; + private ReplayState? state; private double lastStateChangeTime; private bool hasReplay; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs b/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs index 43169dac68..29f5b8f512 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs @@ -403,7 +403,7 @@ namespace osu.Game.Rulesets.Osu.Mods /// The list of hit objects in a beatmap, ordered by StartTime /// The point in time to get samples for /// Hit samples - private IList getSamplesAtTime(IEnumerable hitObjects, double time) + private IList? getSamplesAtTime(IEnumerable hitObjects, double time) { // Get a hit object that // either has StartTime equal to the target time From 9134525111130704a23ab0788c549449b6e1763b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=82=BA=E4=BB=80=E9=BA=BC?= Date: Sun, 10 Jul 2022 23:47:57 +0800 Subject: [PATCH 087/278] Mark the property as nullable and add some assert check. --- osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs | 12 +++++++--- osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs | 5 ++++- .../Mods/OsuModFlashlight.cs | 5 +++-- .../Mods/OsuModMagnetised.cs | 5 ++++- osu.Game.Rulesets.Osu/Mods/OsuModNoScope.cs | 5 +++-- osu.Game.Rulesets.Osu/Mods/OsuModRelax.cs | 6 ++++- osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs | 22 ++++++++++++++----- 7 files changed, 45 insertions(+), 15 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs b/osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs index 2d579e511e..03cc1a9305 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs @@ -3,7 +3,9 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; +using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics.Sprites; using osu.Framework.Input.StateChanges; using osu.Game.Graphics; @@ -28,16 +30,20 @@ namespace osu.Game.Rulesets.Osu.Mods public bool RestartOnFail => false; - private OsuInputManager inputManager; + private OsuInputManager? inputManager; - private IFrameStableClock gameplayClock; + private IFrameStableClock? gameplayClock; - private List replayFrames; + private List? replayFrames; private int currentFrame; public void Update(Playfield playfield) { + Debug.Assert(inputManager != null); + Debug.Assert(gameplayClock != null); + Debug.Assert(replayFrames != null); + if (currentFrame == replayFrames.Count - 1) return; double time = gameplayClock.CurrentTime; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs index 39234147a9..35054a50db 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Diagnostics; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -31,7 +32,7 @@ namespace osu.Game.Rulesets.Osu.Mods public override double ScoreMultiplier => UsesDefaultConfiguration ? 1.12 : 1; public override Type[] IncompatibleMods => new[] { typeof(OsuModFlashlight) }; - private DrawableOsuBlinds blinds; + private DrawableOsuBlinds? blinds; public void ApplyToDrawableRuleset(DrawableRuleset drawableRuleset) { @@ -40,6 +41,8 @@ namespace osu.Game.Rulesets.Osu.Mods public void ApplyToHealthProcessor(HealthProcessor healthProcessor) { + Debug.Assert(blinds != null); + healthProcessor.Health.ValueChanged += health => { blinds.AnimateClosedness((float)health.NewValue); }; } diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs b/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs index 25b900752c..510e95b13f 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs @@ -4,6 +4,7 @@ using System; using System.Linq; using osu.Framework.Bindables; +using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Framework.Input; using osu.Framework.Input.Events; @@ -51,14 +52,14 @@ namespace osu.Game.Rulesets.Osu.Mods public override float DefaultFlashlightSize => 180; - private OsuFlashlight flashlight; + private OsuFlashlight? flashlight; protected override Flashlight CreateFlashlight() => flashlight = new OsuFlashlight(this); public void ApplyToDrawableHitObject(DrawableHitObject drawable) { if (drawable is DrawableSlider s) - s.Tracking.ValueChanged += flashlight.OnSliderTrackingChange; + s.Tracking.ValueChanged += flashlight.AsNonNull().OnSliderTrackingChange; } private class OsuFlashlight : Flashlight, IRequireHighFrequencyMousePosition diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModMagnetised.cs b/osu.Game.Rulesets.Osu/Mods/OsuModMagnetised.cs index 97a573f1b4..107eac6430 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModMagnetised.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModMagnetised.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Diagnostics; using osu.Framework.Bindables; using osu.Framework.Graphics.Sprites; using osu.Framework.Utils; @@ -26,7 +27,7 @@ namespace osu.Game.Rulesets.Osu.Mods public override double ScoreMultiplier => 1; public override Type[] IncompatibleMods => new[] { typeof(OsuModAutopilot), typeof(OsuModWiggle), typeof(OsuModTransform), typeof(ModAutoplay), typeof(OsuModRelax), typeof(OsuModRepel) }; - private IFrameStableClock gameplayClock; + private IFrameStableClock? gameplayClock; [SettingSource("Attraction strength", "How strong the pull is.", 0)] public BindableFloat AttractionStrength { get; } = new BindableFloat(0.5f) @@ -74,6 +75,8 @@ namespace osu.Game.Rulesets.Osu.Mods { double dampLength = Interpolation.Lerp(3000, 40, AttractionStrength.Value); + Debug.Assert(gameplayClock != null); + float x = (float)Interpolation.DampContinuously(hitObject.X, destination.X, dampLength, gameplayClock.ElapsedFrameTime); float y = (float)Interpolation.DampContinuously(hitObject.Y, destination.Y, dampLength, gameplayClock.ElapsedFrameTime); diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModNoScope.cs b/osu.Game.Rulesets.Osu/Mods/OsuModNoScope.cs index 8e377ea632..0197b7cb1b 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModNoScope.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModNoScope.cs @@ -4,6 +4,7 @@ using System; using System.Linq; using osu.Framework.Bindables; +using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Utils; using osu.Game.Beatmaps; using osu.Game.Configuration; @@ -19,7 +20,7 @@ namespace osu.Game.Rulesets.Osu.Mods { public override string Description => "Where's the cursor?"; - private PeriodTracker spinnerPeriods; + private PeriodTracker? spinnerPeriods; [SettingSource( "Hidden at combo", @@ -41,7 +42,7 @@ namespace osu.Game.Rulesets.Osu.Mods public void Update(Playfield playfield) { - bool shouldAlwaysShowCursor = IsBreakTime.Value || spinnerPeriods.IsInAny(playfield.Clock.CurrentTime); + bool shouldAlwaysShowCursor = IsBreakTime.Value || spinnerPeriods.AsNonNull().IsInAny(playfield.Clock.CurrentTime); float targetAlpha = shouldAlwaysShowCursor ? 1 : ComboBasedAlpha; playfield.Cursor.Alpha = (float)Interpolation.Lerp(playfield.Cursor.Alpha, targetAlpha, Math.Clamp(playfield.Time.Elapsed / TRANSITION_DURATION, 0, 1)); } diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModRelax.cs b/osu.Game.Rulesets.Osu/Mods/OsuModRelax.cs index c9c3fdfc89..ac45ce2ade 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModRelax.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModRelax.cs @@ -29,7 +29,7 @@ namespace osu.Game.Rulesets.Osu.Mods private bool isDownState; private bool wasLeft; - private OsuInputManager osuInputManager; + private OsuInputManager? osuInputManager; private ReplayState? state; private double lastStateChangeTime; @@ -44,6 +44,8 @@ namespace osu.Game.Rulesets.Osu.Mods public void ApplyToPlayer(Player player) { + Debug.Assert(osuInputManager != null); + if (osuInputManager.ReplayInputHandler != null) { hasReplay = true; @@ -132,6 +134,8 @@ namespace osu.Game.Rulesets.Osu.Mods wasLeft = !wasLeft; } + Debug.Assert(osuInputManager != null); + state?.Apply(osuInputManager.CurrentState, osuInputManager); } } diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs b/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs index 29f5b8f512..36f21ba291 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs @@ -3,8 +3,10 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using osu.Framework.Bindables; +using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; using osu.Framework.Utils; @@ -94,11 +96,11 @@ namespace osu.Game.Rulesets.Osu.Mods #region Private Fields - private ControlPointInfo controlPointInfo; + private ControlPointInfo? controlPointInfo; - private List originalHitObjects; + private List? originalHitObjects; - private Random rng; + private Random? rng; #endregion @@ -158,7 +160,7 @@ namespace osu.Game.Rulesets.Osu.Mods circle.ApproachCircle.Hide(); } - using (circle.BeginAbsoluteSequence(startTime - controlPointInfo.TimingPointAt(startTime).BeatLength - undim_duration)) + using (circle.BeginAbsoluteSequence(startTime - controlPointInfo.AsNonNull().TimingPointAt(startTime).BeatLength - undim_duration)) circle.FadeColour(Color4.White, undim_duration); } @@ -200,6 +202,8 @@ namespace osu.Game.Rulesets.Osu.Mods private IEnumerable generateBeats(IBeatmap beatmap) { + Debug.Assert(originalHitObjects != null); + double startTime = originalHitObjects.First().StartTime; double endTime = originalHitObjects.Last().GetEndTime(); @@ -228,6 +232,8 @@ namespace osu.Game.Rulesets.Osu.Mods private void addHitSamples(IEnumerable hitObjects) { + Debug.Assert(originalHitObjects != null); + foreach (var obj in hitObjects) { var samples = getSamplesAtTime(originalHitObjects, obj.StartTime); @@ -240,6 +246,8 @@ namespace osu.Game.Rulesets.Osu.Mods private void fixComboInfo(List hitObjects) { + Debug.Assert(originalHitObjects != null); + // Copy combo indices from an original object at the same time or from the closest preceding object // (Objects lying between two combos are assumed to belong to the preceding combo) hitObjects.ForEach(newObj => @@ -276,7 +284,7 @@ namespace osu.Game.Rulesets.Osu.Mods { if (hitObjects.Count == 0) return; - float nextSingle(float max = 1f) => (float)(rng.NextDouble() * max); + float nextSingle(float max = 1f) => (float)(rng.AsNonNull().NextDouble() * max); const float two_pi = MathF.PI * 2; @@ -357,6 +365,8 @@ namespace osu.Game.Rulesets.Osu.Mods /// The time to be checked.= private bool isInsideBreakPeriod(IEnumerable breaks, double time) { + Debug.Assert(originalHitObjects != null); + return breaks.Any(breakPeriod => { var firstObjAfterBreak = originalHitObjects.First(obj => almostBigger(obj.StartTime, breakPeriod.EndTime)); @@ -372,6 +382,8 @@ namespace osu.Game.Rulesets.Osu.Mods int i = 0; double currentTime = timingPoint.Time; + Debug.Assert(controlPointInfo != null); + while (!definitelyBigger(currentTime, mapEndTime) && ReferenceEquals(controlPointInfo.TimingPointAt(currentTime), timingPoint)) { beats.Add(Math.Floor(currentTime)); From 8fa576557398ce1e51ee262430fdab07ab7bd15e Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 20 Jul 2022 20:34:55 +0800 Subject: [PATCH 088/278] Remove nullable disable annotation in the Osu test case. --- osu.Game.Rulesets.Osu.Tests/Mods/OsuModTestScene.cs | 2 -- .../Mods/TestSceneOsuModAlternate.cs | 2 -- .../Mods/TestSceneOsuModAutoplay.cs | 7 +++---- .../Mods/TestSceneOsuModDifficultyAdjust.cs | 2 -- .../Mods/TestSceneOsuModDoubleTime.cs | 2 -- .../Mods/TestSceneOsuModHidden.cs | 4 +--- .../Mods/TestSceneOsuModMagnetised.cs | 2 -- .../Mods/TestSceneOsuModMuted.cs | 4 +--- .../Mods/TestSceneOsuModNoScope.cs | 2 -- .../Mods/TestSceneOsuModPerfect.cs | 2 -- .../Mods/TestSceneOsuModSpunOut.cs | 12 +++++------- 11 files changed, 10 insertions(+), 31 deletions(-) diff --git a/osu.Game.Rulesets.Osu.Tests/Mods/OsuModTestScene.cs b/osu.Game.Rulesets.Osu.Tests/Mods/OsuModTestScene.cs index 4f005a0c70..d3cb3bcf59 100644 --- a/osu.Game.Rulesets.Osu.Tests/Mods/OsuModTestScene.cs +++ b/osu.Game.Rulesets.Osu.Tests/Mods/OsuModTestScene.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Tests.Visual; namespace osu.Game.Rulesets.Osu.Tests.Mods diff --git a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModAlternate.cs b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModAlternate.cs index 3d59e4fb51..5e46498aca 100644 --- a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModAlternate.cs +++ b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModAlternate.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Collections.Generic; using NUnit.Framework; using osu.Game.Beatmaps; diff --git a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModAutoplay.cs b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModAutoplay.cs index 378b71ccf7..3563995234 100644 --- a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModAutoplay.cs +++ b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModAutoplay.cs @@ -1,10 +1,9 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Linq; using NUnit.Framework; +using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Testing; using osu.Framework.Utils; using osu.Game.Beatmaps; @@ -35,7 +34,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Mods private void runSpmTest(Mod mod) { - SpinnerSpmCalculator spmCalculator = null; + SpinnerSpmCalculator? spmCalculator = null; CreateModTest(new ModTestData { @@ -61,7 +60,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Mods return spmCalculator != null; }); - AddUntilStep("SPM is correct", () => Precision.AlmostEquals(spmCalculator.Result.Value, 477, 5)); + AddUntilStep("SPM is correct", () => Precision.AlmostEquals(spmCalculator.AsNonNull().Result.Value, 477, 5)); } } } diff --git a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModDifficultyAdjust.cs b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModDifficultyAdjust.cs index 80dc83d7dc..9d06ff5801 100644 --- a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModDifficultyAdjust.cs +++ b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModDifficultyAdjust.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Collections.Generic; using System.Linq; using NUnit.Framework; diff --git a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModDoubleTime.cs b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModDoubleTime.cs index e1bed5153b..335ef31019 100644 --- a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModDoubleTime.cs +++ b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModDoubleTime.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using NUnit.Framework; using osu.Framework.Utils; using osu.Game.Rulesets.Osu.Mods; diff --git a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModHidden.cs b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModHidden.cs index 5ed25baca3..e692f8ecbc 100644 --- a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModHidden.cs +++ b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModHidden.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Collections.Generic; using System.Linq; using NUnit.Framework; @@ -162,7 +160,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Mods private class TestOsuModHidden : OsuModHidden { - public new HitObject FirstObject => base.FirstObject; + public new HitObject? FirstObject => base.FirstObject; } } } diff --git a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModMagnetised.cs b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModMagnetised.cs index 1f1db04c24..9b49e60363 100644 --- a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModMagnetised.cs +++ b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModMagnetised.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using NUnit.Framework; using osu.Game.Rulesets.Osu.Mods; diff --git a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModMuted.cs b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModMuted.cs index 99c9036ac0..68669d1a53 100644 --- a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModMuted.cs +++ b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModMuted.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Linq; using NUnit.Framework; using osu.Framework.Testing; @@ -33,7 +31,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Mods [Test] public void TestModCopy() { - OsuModMuted muted = null; + OsuModMuted muted = null!; AddStep("create inversed mod", () => muted = new OsuModMuted { diff --git a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModNoScope.cs b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModNoScope.cs index 47e7ad320c..44404ca245 100644 --- a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModNoScope.cs +++ b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModNoScope.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Collections.Generic; using System.Linq; using NUnit.Framework; diff --git a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModPerfect.cs b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModPerfect.cs index b7669624ff..985baa8cf5 100644 --- a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModPerfect.cs +++ b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModPerfect.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using NUnit.Framework; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Types; diff --git a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModSpunOut.cs b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModSpunOut.cs index 4f6d6376bf..e121e6103d 100644 --- a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModSpunOut.cs +++ b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModSpunOut.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Collections.Generic; using System.Linq; @@ -30,8 +28,8 @@ namespace osu.Game.Rulesets.Osu.Tests.Mods [Test] public void TestSpinnerAutoCompleted() { - DrawableSpinner spinner = null; - JudgementResult lastResult = null; + DrawableSpinner? spinner = null; + JudgementResult? lastResult = null; CreateModTest(new ModTestData { @@ -63,11 +61,11 @@ namespace osu.Game.Rulesets.Osu.Tests.Mods [TestCase(null)] [TestCase(typeof(OsuModDoubleTime))] [TestCase(typeof(OsuModHalfTime))] - public void TestSpinRateUnaffectedByMods(Type additionalModType) + public void TestSpinRateUnaffectedByMods(Type? additionalModType) { var mods = new List { new OsuModSpunOut() }; if (additionalModType != null) - mods.Add((Mod)Activator.CreateInstance(additionalModType)); + mods.Add((Mod)Activator.CreateInstance(additionalModType)!); CreateModTest(new ModTestData { @@ -96,7 +94,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Mods [Test] public void TestSpinnerGetsNoBonusScore() { - DrawableSpinner spinner = null; + DrawableSpinner? spinner = null; List results = new List(); CreateModTest(new ModTestData From 0fe64d1e803202028ca9d20c4006641bad961675 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 27 Jul 2022 01:05:50 +0800 Subject: [PATCH 089/278] Remove unused namespace. --- osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs b/osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs index 03cc1a9305..83c1deb3b9 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics.Sprites; using osu.Framework.Input.StateChanges; using osu.Game.Graphics; From 6b0f3674c320f345caaff0068f6c00bfebdafb22 Mon Sep 17 00:00:00 2001 From: Nitrous Date: Wed, 27 Jul 2022 08:51:55 +0800 Subject: [PATCH 090/278] implement `LegacySongProgress` --- osu.Game/Skinning/LegacySongProgress.cs | 101 ++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 osu.Game/Skinning/LegacySongProgress.cs diff --git a/osu.Game/Skinning/LegacySongProgress.cs b/osu.Game/Skinning/LegacySongProgress.cs new file mode 100644 index 0000000000..57280fff07 --- /dev/null +++ b/osu.Game/Skinning/LegacySongProgress.cs @@ -0,0 +1,101 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +#nullable disable + +using System; +using System.Linq; +using osu.Framework.Allocation; +using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.UserInterface; +using osu.Game.Beatmaps; +using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.UI; +using osu.Game.Screens.Play; +using osuTK; + +namespace osu.Game.Skinning +{ + public class LegacySongProgress : CompositeDrawable, ISkinnableDrawable + { + public bool UsesFixedAnchor { get; set; } + + [Resolved] + private GameplayClock gameplayClock { get; set; } + + [Resolved(canBeNull: true)] + private DrawableRuleset drawableRuleset { get; set; } + + [Resolved(canBeNull: true)] + private IBindable beatmap { get; set; } + + private double lastHitTime; + private double firstHitTime; + private double firstEventTime; + private CircularProgress pie; + + [BackgroundDependencyLoader] + private void load() + { + Size = new Vector2(35); + + InternalChildren = new Drawable[] + { + pie = new CircularProgress + { + RelativeSizeAxes = Axes.Both, + Alpha = 0.5f, + }, + new CircularContainer + { + RelativeSizeAxes = Axes.Both, + Masking = true, + BorderColour = Colour4.White, + BorderThickness = 2, + Child = new Box + { + RelativeSizeAxes = Axes.Both, + AlwaysPresent = true, + Alpha = 0, + } + }, + new Circle + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Colour = Colour4.White, + Size = new Vector2(3), + } + }; + + firstEventTime = beatmap?.Value.Storyboard.EarliestEventTime ?? 0; + firstHitTime = drawableRuleset.Objects.First().StartTime; + lastHitTime = drawableRuleset.Objects.Last().GetEndTime() + 1; + } + + protected override void Update() + { + base.Update(); + + double gameplayTime = gameplayClock?.CurrentTime ?? Time.Current; + + if (gameplayTime < firstHitTime) + { + pie.Scale = new Vector2(-1, 1); + pie.Anchor = Anchor.TopRight; + pie.Colour = Colour4.LimeGreen; + pie.Current.Value = 1 - Math.Clamp((gameplayTime - firstEventTime) / (firstHitTime - firstEventTime), 0, 1); + } + else + { + pie.Scale = new Vector2(1); + pie.Anchor = Anchor.TopLeft; + pie.Colour = Colour4.White; + pie.Current.Value = Math.Clamp((gameplayTime - firstHitTime) / (lastHitTime - firstHitTime), 0, 1); + } + } + } +} From a2320aeb278281c51f17f51386988e4c69574ba1 Mon Sep 17 00:00:00 2001 From: Nitrous Date: Wed, 27 Jul 2022 08:52:27 +0800 Subject: [PATCH 091/278] replace `SongProgress` with `LegacySongProgress` --- osu.Game/Skinning/LegacySkin.cs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/osu.Game/Skinning/LegacySkin.cs b/osu.Game/Skinning/LegacySkin.cs index 34219722a1..c3872f4fa0 100644 --- a/osu.Game/Skinning/LegacySkin.cs +++ b/osu.Game/Skinning/LegacySkin.cs @@ -16,12 +16,13 @@ using osu.Framework.IO.Stores; using osu.Game.Audio; using osu.Game.Beatmaps.Formats; using osu.Game.Database; +using osu.Game.Extensions; using osu.Game.IO; using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Scoring; -using osu.Game.Screens.Play; using osu.Game.Screens.Play.HUD; using osu.Game.Screens.Play.HUD.HitErrorMeters; +using osuTK; using osuTK.Graphics; namespace osu.Game.Skinning @@ -344,7 +345,15 @@ namespace osu.Game.Skinning accuracy.Y = container.ToLocalSpace(score.ScreenSpaceDrawQuad.BottomRight).Y; } - var songProgress = container.OfType().FirstOrDefault(); + var songProgress = container.OfType().FirstOrDefault(); + + if (songProgress != null && accuracy != null) + { + songProgress.Anchor = Anchor.TopRight; + songProgress.Origin = Anchor.CentreRight; + songProgress.X = -accuracy.ScreenSpaceDeltaToParentSpace(accuracy.ScreenSpaceDrawQuad.Size).X - 10; + songProgress.Y = container.ToLocalSpace(accuracy.ScreenSpaceDrawQuad.TopLeft).Y + (accuracy.ScreenSpaceDeltaToParentSpace(accuracy.ScreenSpaceDrawQuad.Size).Y / 2); + } var hitError = container.OfType().FirstOrDefault(); @@ -354,12 +363,6 @@ namespace osu.Game.Skinning hitError.Origin = Anchor.CentreLeft; hitError.Rotation = -90; } - - if (songProgress != null) - { - if (hitError != null) hitError.Y -= SongProgress.MAX_HEIGHT; - if (combo != null) combo.Y -= SongProgress.MAX_HEIGHT; - } }) { Children = new Drawable[] @@ -368,7 +371,7 @@ namespace osu.Game.Skinning new LegacyScoreCounter(), new LegacyAccuracyCounter(), new LegacyHealthDisplay(), - new SongProgress(), + new LegacySongProgress(), new BarHitErrorMeter(), } }; From 842ab3c5c1c4a08ae0518223e16537590405559b Mon Sep 17 00:00:00 2001 From: Nitrous Date: Wed, 27 Jul 2022 09:41:58 +0800 Subject: [PATCH 092/278] remove unused using --- osu.Game/Skinning/LegacySkin.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Skinning/LegacySkin.cs b/osu.Game/Skinning/LegacySkin.cs index c3872f4fa0..66258fb4a2 100644 --- a/osu.Game/Skinning/LegacySkin.cs +++ b/osu.Game/Skinning/LegacySkin.cs @@ -22,7 +22,6 @@ using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Scoring; using osu.Game.Screens.Play.HUD; using osu.Game.Screens.Play.HUD.HitErrorMeters; -using osuTK; using osuTK.Graphics; namespace osu.Game.Skinning From b803ec543f3423afa408c340d88bb63fe7cab43e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 27 Jul 2022 13:50:03 +0900 Subject: [PATCH 093/278] Remove unused `combo` DI retrieval --- osu.Game/Skinning/LegacySkin.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Skinning/LegacySkin.cs b/osu.Game/Skinning/LegacySkin.cs index 66258fb4a2..15d4965a1d 100644 --- a/osu.Game/Skinning/LegacySkin.cs +++ b/osu.Game/Skinning/LegacySkin.cs @@ -337,7 +337,6 @@ namespace osu.Game.Skinning { var score = container.OfType().FirstOrDefault(); var accuracy = container.OfType().FirstOrDefault(); - var combo = container.OfType().FirstOrDefault(); if (score != null && accuracy != null) { From 62ca3aada6bb969de3185065df1001834aa2034c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 27 Jul 2022 13:53:25 +0900 Subject: [PATCH 094/278] Transfer TODO comment across to copy-pasted implmentation --- osu.Game/Skinning/LegacySongProgress.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game/Skinning/LegacySongProgress.cs b/osu.Game/Skinning/LegacySongProgress.cs index 57280fff07..4d8838e031 100644 --- a/osu.Game/Skinning/LegacySongProgress.cs +++ b/osu.Game/Skinning/LegacySongProgress.cs @@ -73,6 +73,7 @@ namespace osu.Game.Skinning firstEventTime = beatmap?.Value.Storyboard.EarliestEventTime ?? 0; firstHitTime = drawableRuleset.Objects.First().StartTime; + //TODO: this isn't always correct (consider mania where a non-last object may last for longer than the last in the list). lastHitTime = drawableRuleset.Objects.Last().GetEndTime() + 1; } From d8e605d8aaa8e8119bdd3397fcaa7d3685942824 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 27 Jul 2022 13:58:01 +0900 Subject: [PATCH 095/278] Fix broken tests due to badly reimplemented copy-pasted code --- osu.Game/Skinning/LegacySongProgress.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/osu.Game/Skinning/LegacySongProgress.cs b/osu.Game/Skinning/LegacySongProgress.cs index 4d8838e031..2fd4180139 100644 --- a/osu.Game/Skinning/LegacySongProgress.cs +++ b/osu.Game/Skinning/LegacySongProgress.cs @@ -72,9 +72,13 @@ namespace osu.Game.Skinning }; firstEventTime = beatmap?.Value.Storyboard.EarliestEventTime ?? 0; - firstHitTime = drawableRuleset.Objects.First().StartTime; - //TODO: this isn't always correct (consider mania where a non-last object may last for longer than the last in the list). - lastHitTime = drawableRuleset.Objects.Last().GetEndTime() + 1; + + if (drawableRuleset != null) + { + firstHitTime = drawableRuleset.Objects.First().StartTime; + //TODO: this isn't always correct (consider mania where a non-last object may last for longer than the last in the list). + lastHitTime = drawableRuleset.Objects.Last().GetEndTime() + 1; + } } protected override void Update() From 6b73f7c7ec5b411c9f30ec7b9c8d94d2a2d12e34 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 27 Jul 2022 15:04:09 +0900 Subject: [PATCH 096/278] Split out legacy import path from realm manager --- .../Collections/IO/ImportCollectionsTest.cs | 3 +- osu.Game.Tests/ImportTest.cs | 2 +- .../TestSceneManageCollectionsDialog.cs | 2 +- .../SongSelect/TestSceneFilterControl.cs | 2 +- osu.Game/Beatmaps/RealmBeatmapCollection.cs | 40 +++ osu.Game/Collections/BeatmapCollection.cs | 17 - osu.Game/Collections/CollectionManager.cs | 331 ++---------------- osu.Game/Database/LegacyCollectionImporter.cs | 167 +++++++++ osu.Game/Database/LegacyImportManager.cs | 4 +- osu.Game/OsuGame.cs | 2 +- 10 files changed, 237 insertions(+), 333 deletions(-) create mode 100644 osu.Game/Beatmaps/RealmBeatmapCollection.cs create mode 100644 osu.Game/Database/LegacyCollectionImporter.cs diff --git a/osu.Game.Tests/Collections/IO/ImportCollectionsTest.cs b/osu.Game.Tests/Collections/IO/ImportCollectionsTest.cs index 9a8f29647d..685586ff02 100644 --- a/osu.Game.Tests/Collections/IO/ImportCollectionsTest.cs +++ b/osu.Game.Tests/Collections/IO/ImportCollectionsTest.cs @@ -11,6 +11,7 @@ using NUnit.Framework; using osu.Framework.Extensions; using osu.Framework.Platform; using osu.Framework.Testing; +using osu.Game.Database; using osu.Game.Tests.Resources; namespace osu.Game.Tests.Collections.IO @@ -187,7 +188,7 @@ namespace osu.Game.Tests.Collections.IO { // intentionally spin this up on a separate task to avoid disposal deadlocks. // see https://github.com/EventStore/EventStore/issues/1179 - await Task.Factory.StartNew(() => osu.CollectionManager.Import(stream).WaitSafely(), TaskCreationOptions.LongRunning); + await Task.Factory.StartNew(() => new LegacyCollectionImporter(osu.CollectionManager).Import(stream).WaitSafely(), TaskCreationOptions.LongRunning); } } } diff --git a/osu.Game.Tests/ImportTest.cs b/osu.Game.Tests/ImportTest.cs index 32b6dc649c..1f18f92158 100644 --- a/osu.Game.Tests/ImportTest.cs +++ b/osu.Game.Tests/ImportTest.cs @@ -63,7 +63,7 @@ namespace osu.Game.Tests if (withBeatmap) BeatmapManager.Import(TestResources.GetTestBeatmapForImport()).WaitSafely(); - AddInternal(CollectionManager = new CollectionManager(Storage)); + AddInternal(CollectionManager = new CollectionManager()); } } } diff --git a/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs b/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs index 3f30fa367c..789139f483 100644 --- a/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs +++ b/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs @@ -46,7 +46,7 @@ namespace osu.Game.Tests.Visual.Collections base.Content.AddRange(new Drawable[] { - manager = new CollectionManager(LocalStorage), + manager = new CollectionManager(), Content, dialogOverlay = new DialogOverlay(), }); diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs index 6807180640..01bf312ddd 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs @@ -46,7 +46,7 @@ namespace osu.Game.Tests.Visual.SongSelect base.Content.AddRange(new Drawable[] { - collectionManager = new CollectionManager(LocalStorage), + collectionManager = new CollectionManager(), Content }); diff --git a/osu.Game/Beatmaps/RealmBeatmapCollection.cs b/osu.Game/Beatmaps/RealmBeatmapCollection.cs new file mode 100644 index 0000000000..d3261fc39e --- /dev/null +++ b/osu.Game/Beatmaps/RealmBeatmapCollection.cs @@ -0,0 +1,40 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Collections.Generic; +using JetBrains.Annotations; +using osu.Game.Database; +using Realms; + +namespace osu.Game.Beatmaps +{ + public class RealmBeatmapCollection : RealmObject, IHasGuidPrimaryKey + { + [PrimaryKey] + public Guid ID { get; } + + public string Name { get; set; } = string.Empty; + + public List BeatmapMD5Hashes { get; set; } = null!; + + /// + /// The date when this collection was last modified. + /// + public DateTimeOffset LastModified { get; set; } + + public RealmBeatmapCollection(string? name, List? beatmapMD5Hashes) + { + ID = Guid.NewGuid(); + Name = name ?? string.Empty; + BeatmapMD5Hashes = beatmapMD5Hashes ?? new List(); + + LastModified = DateTimeOffset.UtcNow; + } + + [UsedImplicitly] + private RealmBeatmapCollection() + { + } + } +} diff --git a/osu.Game/Collections/BeatmapCollection.cs b/osu.Game/Collections/BeatmapCollection.cs index 742d757bec..abfd0e6dd0 100644 --- a/osu.Game/Collections/BeatmapCollection.cs +++ b/osu.Game/Collections/BeatmapCollection.cs @@ -14,11 +14,6 @@ namespace osu.Game.Collections /// public class BeatmapCollection { - /// - /// Invoked whenever any change occurs on this . - /// - public event Action Changed; - /// /// The collection's name. /// @@ -33,17 +28,5 @@ namespace osu.Game.Collections /// The date when this collection was last modified. /// public DateTimeOffset LastModifyDate { get; private set; } = DateTimeOffset.UtcNow; - - public BeatmapCollection() - { - BeatmapHashes.CollectionChanged += (_, _) => onChange(); - Name.ValueChanged += _ => onChange(); - } - - private void onChange() - { - LastModifyDate = DateTimeOffset.Now; - Changed?.Invoke(); - } } } diff --git a/osu.Game/Collections/CollectionManager.cs b/osu.Game/Collections/CollectionManager.cs index 796b3c426c..0d4ee5c722 100644 --- a/osu.Game/Collections/CollectionManager.cs +++ b/osu.Game/Collections/CollectionManager.cs @@ -4,346 +4,59 @@ #nullable disable using System; -using System.Collections.Generic; -using System.Collections.Specialized; -using System.IO; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; -using osu.Framework.Logging; -using osu.Framework.Platform; +using osu.Game.Beatmaps; using osu.Game.Database; -using osu.Game.IO; -using osu.Game.IO.Legacy; using osu.Game.Overlays.Notifications; +using Realms; namespace osu.Game.Collections { /// /// Handles user-defined collections of beatmaps. /// - /// - /// This is currently reading and writing from the osu-stable file format. This is a temporary arrangement until we refactor the - /// database backing the game. Going forward writing should be done in a similar way to other model stores. - /// public class CollectionManager : Component, IPostNotifications { - /// - /// Database version in stable-compatible YYYYMMDD format. - /// - private const int database_version = 30000000; - - private const string database_name = "collection.db"; - private const string database_backup_name = "collection.db.bak"; - public readonly BindableList Collections = new BindableList(); - private readonly Storage storage; - - public CollectionManager(Storage storage) - { - this.storage = storage; - } - - [Resolved(canBeNull: true)] - private DatabaseContextFactory efContextFactory { get; set; } = null!; + [Resolved] + private RealmAccess realm { get; set; } [BackgroundDependencyLoader] private void load() { - efContextFactory?.WaitForMigrationCompletion(); - - Collections.CollectionChanged += collectionsChanged; - - if (storage.Exists(database_backup_name)) - { - // If a backup file exists, it means the previous write operation didn't run to completion. - // Always prefer the backup file in such a case as it's the most recent copy that is guaranteed to not be malformed. - // - // The database is saved 100ms after any change, and again when the game is closed, so there shouldn't be a large diff between the two files in the worst case. - if (storage.Exists(database_name)) - storage.Delete(database_name); - File.Copy(storage.GetFullPath(database_backup_name), storage.GetFullPath(database_name)); - } - - if (storage.Exists(database_name)) - { - List beatmapCollections; - - using (var stream = storage.GetStream(database_name)) - beatmapCollections = readCollections(stream); - - // intentionally fire-and-forget async. - importCollections(beatmapCollections); - } } - private void collectionsChanged(object sender, NotifyCollectionChangedEventArgs e) => Schedule(() => + protected override void LoadComplete() { - switch (e.Action) + base.LoadComplete(); + + realm.RegisterForNotifications(r => r.All(), collectionsChanged); + } + + private void collectionsChanged(IRealmCollection sender, ChangeSet changes, Exception error) + { + // TODO: hook up with realm changes. + + if (changes == null) { - case NotifyCollectionChangedAction.Add: - foreach (var c in e.NewItems.Cast()) - c.Changed += backgroundSave; - break; - - case NotifyCollectionChangedAction.Remove: - foreach (var c in e.OldItems.Cast()) - c.Changed -= backgroundSave; - break; - - case NotifyCollectionChangedAction.Replace: - foreach (var c in e.OldItems.Cast()) - c.Changed -= backgroundSave; - - foreach (var c in e.NewItems.Cast()) - c.Changed += backgroundSave; - break; + foreach (var collection in sender) + Collections.Add(new BeatmapCollection + { + Name = { Value = collection.Name }, + BeatmapHashes = { Value = collection.BeatmapMD5Hashes }, + }); } - - backgroundSave(); - }); + } public Action PostNotification { protected get; set; } - public Task GetAvailableCount(StableStorage stableStorage) - { - if (!stableStorage.Exists(database_name)) - return Task.FromResult(0); - - return Task.Run(() => - { - using (var stream = stableStorage.GetStream(database_name)) - return readCollections(stream).Count; - }); - } - - /// - /// This is a temporary method and will likely be replaced by a full-fledged (and more correctly placed) migration process in the future. - /// - public Task ImportFromStableAsync(StableStorage stableStorage) - { - if (!stableStorage.Exists(database_name)) - { - // This handles situations like when the user does not have a collections.db file - Logger.Log($"No {database_name} available in osu!stable installation", LoggingTarget.Information, LogLevel.Error); - return Task.CompletedTask; - } - - return Task.Run(async () => - { - using (var stream = stableStorage.GetStream(database_name)) - await Import(stream).ConfigureAwait(false); - }); - } - - public async Task Import(Stream stream) - { - var notification = new ProgressNotification - { - State = ProgressNotificationState.Active, - Text = "Collections import is initialising..." - }; - - PostNotification?.Invoke(notification); - - var collections = readCollections(stream, notification); - await importCollections(collections).ConfigureAwait(false); - - notification.CompletionText = $"Imported {collections.Count} collections"; - notification.State = ProgressNotificationState.Completed; - } - - private Task importCollections(List newCollections) - { - var tcs = new TaskCompletionSource(); - - Schedule(() => - { - try - { - foreach (var newCol in newCollections) - { - var existing = Collections.FirstOrDefault(c => c.Name.Value == newCol.Name.Value); - if (existing == null) - Collections.Add(existing = new BeatmapCollection { Name = { Value = newCol.Name.Value } }); - - foreach (string newBeatmap in newCol.BeatmapHashes) - { - if (!existing.BeatmapHashes.Contains(newBeatmap)) - existing.BeatmapHashes.Add(newBeatmap); - } - } - - tcs.SetResult(true); - } - catch (Exception e) - { - Logger.Error(e, "Failed to import collection."); - tcs.SetException(e); - } - }); - - return tcs.Task; - } - - private List readCollections(Stream stream, ProgressNotification notification = null) - { - if (notification != null) - { - notification.Text = "Reading collections..."; - notification.Progress = 0; - } - - var result = new List(); - - try - { - using (var sr = new SerializationReader(stream)) - { - sr.ReadInt32(); // Version - - int collectionCount = sr.ReadInt32(); - result.Capacity = collectionCount; - - for (int i = 0; i < collectionCount; i++) - { - if (notification?.CancellationToken.IsCancellationRequested == true) - return result; - - var collection = new BeatmapCollection { Name = { Value = sr.ReadString() } }; - int mapCount = sr.ReadInt32(); - - for (int j = 0; j < mapCount; j++) - { - if (notification?.CancellationToken.IsCancellationRequested == true) - return result; - - string checksum = sr.ReadString(); - - collection.BeatmapHashes.Add(checksum); - } - - if (notification != null) - { - notification.Text = $"Imported {i + 1} of {collectionCount} collections"; - notification.Progress = (float)(i + 1) / collectionCount; - } - - result.Add(collection); - } - } - } - catch (Exception e) - { - Logger.Error(e, "Failed to read collection database."); - } - - return result; - } - public void DeleteAll() { Collections.Clear(); PostNotification?.Invoke(new ProgressCompletionNotification { Text = "Deleted all collections!" }); } - - private readonly object saveLock = new object(); - private int lastSave; - private int saveFailures; - - /// - /// Perform a save with debounce. - /// - private void backgroundSave() - { - int current = Interlocked.Increment(ref lastSave); - Task.Delay(100).ContinueWith(_ => - { - if (current != lastSave) - return; - - if (!save()) - backgroundSave(); - }); - } - - private bool save() - { - lock (saveLock) - { - Interlocked.Increment(ref lastSave); - - // This is NOT thread-safe!! - try - { - string tempPath = Path.GetTempFileName(); - - using (var ms = new MemoryStream()) - { - using (var sw = new SerializationWriter(ms, true)) - { - sw.Write(database_version); - - var collectionsCopy = Collections.ToArray(); - sw.Write(collectionsCopy.Length); - - foreach (var c in collectionsCopy) - { - sw.Write(c.Name.Value); - - string[] beatmapsCopy = c.BeatmapHashes.ToArray(); - - sw.Write(beatmapsCopy.Length); - - foreach (string b in beatmapsCopy) - sw.Write(b); - } - } - - using (var fs = File.OpenWrite(tempPath)) - ms.WriteTo(fs); - - string databasePath = storage.GetFullPath(database_name); - string databaseBackupPath = storage.GetFullPath(database_backup_name); - - // Back up the existing database, clearing any existing backup. - if (File.Exists(databaseBackupPath)) - File.Delete(databaseBackupPath); - if (File.Exists(databasePath)) - File.Move(databasePath, databaseBackupPath); - - // Move the new database in-place of the existing one. - File.Move(tempPath, databasePath); - - // If everything succeeded up to this point, remove the backup file. - if (File.Exists(databaseBackupPath)) - File.Delete(databaseBackupPath); - } - - if (saveFailures < 10) - saveFailures = 0; - return true; - } - catch (Exception e) - { - // Since this code is not thread-safe, we may run into random exceptions (such as collection enumeration or out of range indexing). - // Failures are thus only alerted if they exceed a threshold (once) to indicate "actual" errors having occurred. - if (++saveFailures == 10) - Logger.Error(e, "Failed to save collection database!"); - } - - return false; - } - } - - protected override void Dispose(bool isDisposing) - { - base.Dispose(isDisposing); - save(); - } } } diff --git a/osu.Game/Database/LegacyCollectionImporter.cs b/osu.Game/Database/LegacyCollectionImporter.cs new file mode 100644 index 0000000000..8168419e80 --- /dev/null +++ b/osu.Game/Database/LegacyCollectionImporter.cs @@ -0,0 +1,167 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +#nullable disable +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using osu.Framework.Logging; +using osu.Game.Collections; +using osu.Game.IO; +using osu.Game.IO.Legacy; +using osu.Game.Overlays.Notifications; + +namespace osu.Game.Database +{ + public class LegacyCollectionImporter + { + private readonly CollectionManager collections; + + public LegacyCollectionImporter(CollectionManager collections) + { + this.collections = collections; + } + + public Action PostNotification { protected get; set; } + + private const string database_name = "collection.db"; + + public Task GetAvailableCount(StableStorage stableStorage) + { + if (!stableStorage.Exists(database_name)) + return Task.FromResult(0); + + return Task.Run(() => + { + using (var stream = stableStorage.GetStream(database_name)) + return readCollections(stream).Count; + }); + } + + /// + /// This is a temporary method and will likely be replaced by a full-fledged (and more correctly placed) migration process in the future. + /// + public Task ImportFromStableAsync(StableStorage stableStorage) + { + if (!stableStorage.Exists(database_name)) + { + // This handles situations like when the user does not have a collections.db file + Logger.Log($"No {database_name} available in osu!stable installation", LoggingTarget.Information, LogLevel.Error); + return Task.CompletedTask; + } + + return Task.Run(async () => + { + using (var stream = stableStorage.GetStream(database_name)) + await Import(stream).ConfigureAwait(false); + }); + } + + public async Task Import(Stream stream) + { + var notification = new ProgressNotification + { + State = ProgressNotificationState.Active, + Text = "Collections import is initialising..." + }; + + PostNotification?.Invoke(notification); + + var importedCollections = readCollections(stream, notification); + await importCollections(importedCollections).ConfigureAwait(false); + + notification.CompletionText = $"Imported {importedCollections.Count} collections"; + notification.State = ProgressNotificationState.Completed; + } + + private Task importCollections(List newCollections) + { + var tcs = new TaskCompletionSource(); + + // Schedule(() => + // { + try + { + foreach (var newCol in newCollections) + { + var existing = collections.Collections.FirstOrDefault(c => c.Name.Value == newCol.Name.Value); + if (existing == null) + collections.Collections.Add(existing = new BeatmapCollection { Name = { Value = newCol.Name.Value } }); + + foreach (string newBeatmap in newCol.BeatmapHashes) + { + if (!existing.BeatmapHashes.Contains(newBeatmap)) + existing.BeatmapHashes.Add(newBeatmap); + } + } + + tcs.SetResult(true); + } + catch (Exception e) + { + Logger.Error(e, "Failed to import collection."); + tcs.SetException(e); + } + // }); + + return tcs.Task; + } + + private List readCollections(Stream stream, ProgressNotification notification = null) + { + if (notification != null) + { + notification.Text = "Reading collections..."; + notification.Progress = 0; + } + + var result = new List(); + + try + { + using (var sr = new SerializationReader(stream)) + { + sr.ReadInt32(); // Version + + int collectionCount = sr.ReadInt32(); + result.Capacity = collectionCount; + + for (int i = 0; i < collectionCount; i++) + { + if (notification?.CancellationToken.IsCancellationRequested == true) + return result; + + var collection = new BeatmapCollection { Name = { Value = sr.ReadString() } }; + int mapCount = sr.ReadInt32(); + + for (int j = 0; j < mapCount; j++) + { + if (notification?.CancellationToken.IsCancellationRequested == true) + return result; + + string checksum = sr.ReadString(); + + collection.BeatmapHashes.Add(checksum); + } + + if (notification != null) + { + notification.Text = $"Imported {i + 1} of {collectionCount} collections"; + notification.Progress = (float)(i + 1) / collectionCount; + } + + result.Add(collection); + } + } + } + catch (Exception e) + { + Logger.Error(e, "Failed to read collection database."); + } + + return result; + } + } +} diff --git a/osu.Game/Database/LegacyImportManager.cs b/osu.Game/Database/LegacyImportManager.cs index f40e0d33c2..05bd5ceb54 100644 --- a/osu.Game/Database/LegacyImportManager.cs +++ b/osu.Game/Database/LegacyImportManager.cs @@ -72,7 +72,7 @@ namespace osu.Game.Database return await new LegacySkinImporter(skins).GetAvailableCount(stableStorage); case StableContent.Collections: - return await collections.GetAvailableCount(stableStorage); + return await new LegacyCollectionImporter(collections).GetAvailableCount(stableStorage); case StableContent.Scores: return await new LegacyScoreImporter(scores).GetAvailableCount(stableStorage); @@ -109,7 +109,7 @@ namespace osu.Game.Database importTasks.Add(new LegacySkinImporter(skins).ImportFromStableAsync(stableStorage)); if (content.HasFlagFast(StableContent.Collections)) - importTasks.Add(beatmapImportTask.ContinueWith(_ => collections.ImportFromStableAsync(stableStorage), TaskContinuationOptions.OnlyOnRanToCompletion)); + importTasks.Add(beatmapImportTask.ContinueWith(_ => new LegacyCollectionImporter(collections).ImportFromStableAsync(stableStorage), TaskContinuationOptions.OnlyOnRanToCompletion)); if (content.HasFlagFast(StableContent.Scores)) importTasks.Add(beatmapImportTask.ContinueWith(_ => new LegacyScoreImporter(scores).ImportFromStableAsync(stableStorage), TaskContinuationOptions.OnlyOnRanToCompletion)); diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 1ee53e2848..8d8864a46a 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -858,7 +858,7 @@ namespace osu.Game d.Origin = Anchor.TopRight; }), rightFloatingOverlayContent.Add, true); - loadComponentSingleFile(new CollectionManager(Storage) + loadComponentSingleFile(new CollectionManager { PostNotification = n => Notifications.Post(n), }, Add, true); From 2d4655f61e011d71f504202cadc6601bd6ac580f Mon Sep 17 00:00:00 2001 From: Andrew Hong Date: Wed, 27 Jul 2022 02:25:40 -0400 Subject: [PATCH 097/278] Add Toast Notification to Copy URL --- .../UserInterface/ExternalLinkButton.cs | 25 ++++++++++++++++++- osu.Game/Localisation/ToastStrings.cs | 5 ++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs b/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs index acabeca66e..810cd6ef58 100644 --- a/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs +++ b/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs @@ -12,7 +12,10 @@ using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; using osu.Framework.Input.Events; using osu.Framework.Localisation; +using osu.Game.Localisation; using osu.Framework.Platform; +using osu.Game.Overlays; +using osu.Game.Overlays.OSD; using osuTK; using osuTK.Graphics; @@ -27,6 +30,9 @@ namespace osu.Game.Graphics.UserInterface [Resolved] private GameHost host { get; set; } + [Resolved(canBeNull: true)] + private OnScreenDisplay onScreenDisplay { get; set; } + private readonly SpriteIcon linkIcon; public ExternalLinkButton(string link = null) @@ -44,6 +50,23 @@ namespace osu.Game.Graphics.UserInterface }; } + private class CopyUrlToast : Toast + { + public CopyUrlToast(LocalisableString value) + : base(UserInterfaceStrings.GeneralHeader, value, "") + { + } + } + + private void copyUrl() + { + if (Link != null) + { + host.GetClipboard()?.SetText(Link); + onScreenDisplay?.Display(new CopyUrlToast(ToastStrings.CopiedUrl)); + } + } + public MenuItem[] ContextMenuItems { get @@ -53,7 +76,7 @@ namespace osu.Game.Graphics.UserInterface if (Link != null) { items.Add(new OsuMenuItem("Open", MenuItemType.Standard, () => host.OpenUrlExternally(Link))); - items.Add(new OsuMenuItem("Copy URL", MenuItemType.Standard, () => host.GetClipboard()?.SetText(Link))); + items.Add(new OsuMenuItem("Copy URL", MenuItemType.Standard, () => copyUrl())); } return items.ToArray(); diff --git a/osu.Game/Localisation/ToastStrings.cs b/osu.Game/Localisation/ToastStrings.cs index 9ceee807e6..d6771fcd96 100644 --- a/osu.Game/Localisation/ToastStrings.cs +++ b/osu.Game/Localisation/ToastStrings.cs @@ -44,6 +44,11 @@ namespace osu.Game.Localisation /// public static LocalisableString SkinSaved => new TranslatableString(getKey(@"skin_saved"), @"Skin saved"); + /// + /// "Copied URL" + /// + public static LocalisableString CopiedUrl => new TranslatableString(getKey(@"copied_url"), @"Copied URL"); + private static string getKey(string key) => $@"{prefix}:{key}"; } } From a12676c25de8486987374068b3636d4c4fe5a882 Mon Sep 17 00:00:00 2001 From: Nitrous Date: Wed, 27 Jul 2022 14:35:18 +0800 Subject: [PATCH 098/278] scale down graph from bleeding through border --- osu.Game/Skinning/LegacySongProgress.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/osu.Game/Skinning/LegacySongProgress.cs b/osu.Game/Skinning/LegacySongProgress.cs index 2fd4180139..a141a5f91e 100644 --- a/osu.Game/Skinning/LegacySongProgress.cs +++ b/osu.Game/Skinning/LegacySongProgress.cs @@ -44,10 +44,16 @@ namespace osu.Game.Skinning InternalChildren = new Drawable[] { - pie = new CircularProgress + new Container { + Size = new Vector2(0.95f), + Anchor = Anchor.Centre, + Origin = Anchor.Centre, RelativeSizeAxes = Axes.Both, - Alpha = 0.5f, + Child = pie = new CircularProgress + { + RelativeSizeAxes = Axes.Both, + }, }, new CircularContainer { @@ -91,14 +97,14 @@ namespace osu.Game.Skinning { pie.Scale = new Vector2(-1, 1); pie.Anchor = Anchor.TopRight; - pie.Colour = Colour4.LimeGreen; + pie.Colour = new Colour4(199, 255, 47, 153); pie.Current.Value = 1 - Math.Clamp((gameplayTime - firstEventTime) / (firstHitTime - firstEventTime), 0, 1); } else { pie.Scale = new Vector2(1); pie.Anchor = Anchor.TopLeft; - pie.Colour = Colour4.White; + pie.Colour = new Colour4(255, 255, 255, 153); pie.Current.Value = Math.Clamp((gameplayTime - firstHitTime) / (lastHitTime - firstHitTime), 0, 1); } } From 89644a652e09be0fa46f446921f1e92a094e4a9c Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Wed, 27 Jul 2022 10:13:40 +0300 Subject: [PATCH 099/278] Separate combined fields --- osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs index 35054a50db..808e7720a4 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs @@ -58,7 +58,10 @@ namespace osu.Game.Rulesets.Osu.Mods /// private Box blackBoxLeft = null!, blackBoxRight = null!; - private Drawable panelLeft = null!, panelRight = null!, bgPanelLeft = null!, bgPanelRight = null!; + private Drawable panelLeft = null!; + private Drawable panelRight = null!; + private Drawable bgPanelLeft = null!; + private Drawable bgPanelRight = null!; private readonly Beatmap beatmap; From 37e642b0bd41f30265e239b737faafecabc6bac9 Mon Sep 17 00:00:00 2001 From: Nitrous Date: Wed, 27 Jul 2022 15:19:21 +0800 Subject: [PATCH 100/278] make `SongProgress` abstract - move unrelated logic to `DefaultSongProgress` - make `LegacySongProgress` inherit `SongProgress` --- .../Visual/Gameplay/TestSceneSongProgress.cs | 4 +- .../DefaultSongProgress.cs} | 67 ++++----------- osu.Game/Screens/Play/HUD/SongProgress.cs | 85 +++++++++++++++++++ .../Screens/Play/{ => HUD}/SongProgressBar.cs | 2 +- .../Play/{ => HUD}/SongProgressGraph.cs | 2 +- .../Play/{ => HUD}/SongProgressInfo.cs | 2 +- osu.Game/Skinning/DefaultSkin.cs | 2 +- osu.Game/Skinning/LegacySongProgress.cs | 53 ++++-------- 8 files changed, 126 insertions(+), 91 deletions(-) rename osu.Game/Screens/Play/{SongProgress.cs => HUD/DefaultSongProgress.cs} (82%) create mode 100644 osu.Game/Screens/Play/HUD/SongProgress.cs rename osu.Game/Screens/Play/{ => HUD}/SongProgressBar.cs (99%) rename osu.Game/Screens/Play/{ => HUD}/SongProgressGraph.cs (97%) rename osu.Game/Screens/Play/{ => HUD}/SongProgressInfo.cs (98%) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs index 07efb25b46..6f2853b095 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs @@ -21,7 +21,7 @@ namespace osu.Game.Tests.Visual.Gameplay [TestFixture] public class TestSceneSongProgress : OsuTestScene { - private SongProgress progress; + private DefaultSongProgress progress; private TestSongProgressGraph graph; private readonly Container progressContainer; @@ -62,7 +62,7 @@ namespace osu.Game.Tests.Visual.Gameplay progress = null; } - progressContainer.Add(progress = new SongProgress + progressContainer.Add(progress = new DefaultSongProgress { RelativeSizeAxes = Axes.X, Anchor = Anchor.BottomLeft, diff --git a/osu.Game/Screens/Play/SongProgress.cs b/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs similarity index 82% rename from osu.Game/Screens/Play/SongProgress.cs rename to osu.Game/Screens/Play/HUD/DefaultSongProgress.cs index d1510d10c2..7c2d8a9de2 100644 --- a/osu.Game/Screens/Play/SongProgress.cs +++ b/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs @@ -5,12 +5,9 @@ using System; using System.Collections.Generic; -using System.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Timing; using osu.Game.Configuration; using osu.Game.Graphics; using osu.Game.Rulesets.Objects; @@ -18,9 +15,9 @@ using osu.Game.Rulesets.UI; using osu.Game.Skinning; using osuTK; -namespace osu.Game.Screens.Play +namespace osu.Game.Screens.Play.HUD { - public class SongProgress : OverlayContainer, ISkinnableDrawable + public class DefaultSongProgress : SongProgress { public const float MAX_HEIGHT = info_height + bottom_bar_height + graph_height + handle_height; @@ -52,41 +49,13 @@ namespace osu.Game.Screens.Play protected override bool BlockScrollInput => false; - private double firstHitTime => objects.First().StartTime; - - //TODO: this isn't always correct (consider mania where a non-last object may last for longer than the last in the list). - private double lastHitTime => objects.Last().GetEndTime() + 1; - - private IEnumerable objects; - - public IEnumerable Objects - { - set - { - graph.Objects = objects = value; - - info.StartTime = firstHitTime; - info.EndTime = lastHitTime; - - bar.StartTime = firstHitTime; - bar.EndTime = lastHitTime; - } - } - [Resolved(canBeNull: true)] private Player player { get; set; } - [Resolved] - private GameplayClock gameplayClock { get; set; } - [Resolved(canBeNull: true)] private DrawableRuleset drawableRuleset { get; set; } - private IClock referenceClock; - - public bool UsesFixedAnchor { get; set; } - - public SongProgress() + public DefaultSongProgress() { RelativeSizeAxes = Axes.X; Anchor = Anchor.BottomRight; @@ -127,9 +96,6 @@ namespace osu.Game.Screens.Play { if (player?.Configuration.AllowUserInteraction == true) ((IBindable)AllowSeeking).BindTo(drawableRuleset.HasReplayLoaded); - - referenceClock = drawableRuleset.FrameStableClock; - Objects = drawableRuleset.Objects; } graph.FillColour = bar.FillColour = colours.BlueLighter; @@ -203,21 +169,24 @@ namespace osu.Game.Screens.Play this.FadeOut(100); } + protected override void UpdateObjects(IEnumerable objects) + { + graph.Objects = objects; + info.StartTime = FirstHitTime; + info.EndTime = LastHitTime; + bar.StartTime = FirstHitTime; + bar.EndTime = LastHitTime; + } + + protected override void UpdateProgress(double progress, double time, bool isIntro) + { + bar.CurrentTime = time; + graph.Progress = (int)(graph.ColumnCount * progress); + } + protected override void Update() { base.Update(); - - if (objects == null) - return; - - double gameplayTime = gameplayClock?.CurrentTime ?? Time.Current; - double frameStableTime = referenceClock?.CurrentTime ?? gameplayTime; - - double progress = Math.Min(1, (frameStableTime - firstHitTime) / (lastHitTime - firstHitTime)); - - bar.CurrentTime = gameplayTime; - graph.Progress = (int)(graph.ColumnCount * progress); - Height = bottom_bar_height + graph_height + handle_size.Y + info_height - graph.Y; } diff --git a/osu.Game/Screens/Play/HUD/SongProgress.cs b/osu.Game/Screens/Play/HUD/SongProgress.cs new file mode 100644 index 0000000000..c245a47554 --- /dev/null +++ b/osu.Game/Screens/Play/HUD/SongProgress.cs @@ -0,0 +1,85 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +#nullable disable + +using System.Collections.Generic; +using System.Linq; +using osu.Framework.Allocation; +using osu.Framework.Bindables; +using osu.Framework.Graphics.Containers; +using osu.Framework.Timing; +using osu.Game.Beatmaps; +using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.UI; +using osu.Game.Skinning; + +namespace osu.Game.Screens.Play.HUD +{ + public abstract class SongProgress : OverlayContainer, ISkinnableDrawable + { + public bool UsesFixedAnchor { get; set; } + + [Resolved] + private GameplayClock gameplayClock { get; set; } + + [Resolved(canBeNull: true)] + private DrawableRuleset drawableRuleset { get; set; } + + [Resolved(canBeNull: true)] + private IBindable beatmap { get; set; } + + private IClock referenceClock; + private IEnumerable objects; + + public IEnumerable Objects + { + set => UpdateObjects(objects = value); + } + + protected double FirstHitTime => objects.FirstOrDefault()?.StartTime ?? 0; + + //TODO: this isn't always correct (consider mania where a non-last object may last for longer than the last in the list). + protected double LastHitTime => objects.LastOrDefault()?.GetEndTime() ?? 0; + + protected double FirstEventTime { get; private set; } + + protected abstract void UpdateProgress(double progress, double time, bool isIntro); + protected abstract void UpdateObjects(IEnumerable objects); + + [BackgroundDependencyLoader] + private void load() + { + if (drawableRuleset != null) + { + Objects = drawableRuleset.Objects; + referenceClock = drawableRuleset.FrameStableClock; + } + + if (beatmap != null) + { + FirstEventTime = beatmap.Value.Storyboard.EarliestEventTime ?? 0; + } + } + + protected override void Update() + { + base.Update(); + + if (objects == null) + return; + + double gameplayTime = gameplayClock?.CurrentTime ?? Time.Current; + double frameStableTime = referenceClock?.CurrentTime ?? gameplayTime; + + if (frameStableTime < FirstHitTime) + { + UpdateProgress((frameStableTime - FirstEventTime) / (FirstHitTime - FirstEventTime), gameplayTime, true); + } + else + { + UpdateProgress((frameStableTime - FirstHitTime) / (LastHitTime - FirstHitTime), gameplayTime, false); + } + } + } +} diff --git a/osu.Game/Screens/Play/SongProgressBar.cs b/osu.Game/Screens/Play/HUD/SongProgressBar.cs similarity index 99% rename from osu.Game/Screens/Play/SongProgressBar.cs rename to osu.Game/Screens/Play/HUD/SongProgressBar.cs index 67923f4b6a..db4e200724 100644 --- a/osu.Game/Screens/Play/SongProgressBar.cs +++ b/osu.Game/Screens/Play/HUD/SongProgressBar.cs @@ -13,7 +13,7 @@ using osu.Framework.Graphics.UserInterface; using osu.Framework.Utils; using osu.Framework.Threading; -namespace osu.Game.Screens.Play +namespace osu.Game.Screens.Play.HUD { public class SongProgressBar : SliderBar { diff --git a/osu.Game/Screens/Play/SongProgressGraph.cs b/osu.Game/Screens/Play/HUD/SongProgressGraph.cs similarity index 97% rename from osu.Game/Screens/Play/SongProgressGraph.cs rename to osu.Game/Screens/Play/HUD/SongProgressGraph.cs index c742df67ce..f234b45922 100644 --- a/osu.Game/Screens/Play/SongProgressGraph.cs +++ b/osu.Game/Screens/Play/HUD/SongProgressGraph.cs @@ -8,7 +8,7 @@ using System.Collections.Generic; using System.Diagnostics; using osu.Game.Rulesets.Objects; -namespace osu.Game.Screens.Play +namespace osu.Game.Screens.Play.HUD { public class SongProgressGraph : SquareGraph { diff --git a/osu.Game/Screens/Play/SongProgressInfo.cs b/osu.Game/Screens/Play/HUD/SongProgressInfo.cs similarity index 98% rename from osu.Game/Screens/Play/SongProgressInfo.cs rename to osu.Game/Screens/Play/HUD/SongProgressInfo.cs index 40759c3a3b..8f10e84509 100644 --- a/osu.Game/Screens/Play/SongProgressInfo.cs +++ b/osu.Game/Screens/Play/HUD/SongProgressInfo.cs @@ -10,7 +10,7 @@ using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using System; -namespace osu.Game.Screens.Play +namespace osu.Game.Screens.Play.HUD { public class SongProgressInfo : Container { diff --git a/osu.Game/Skinning/DefaultSkin.cs b/osu.Game/Skinning/DefaultSkin.cs index 5267861e3e..0848f42360 100644 --- a/osu.Game/Skinning/DefaultSkin.cs +++ b/osu.Game/Skinning/DefaultSkin.cs @@ -147,7 +147,7 @@ namespace osu.Game.Skinning new DefaultScoreCounter(), new DefaultAccuracyCounter(), new DefaultHealthDisplay(), - new SongProgress(), + new DefaultSongProgress(), new BarHitErrorMeter(), new BarHitErrorMeter(), new PerformancePointsCounter() diff --git a/osu.Game/Skinning/LegacySongProgress.cs b/osu.Game/Skinning/LegacySongProgress.cs index a141a5f91e..5f27d73761 100644 --- a/osu.Game/Skinning/LegacySongProgress.cs +++ b/osu.Game/Skinning/LegacySongProgress.cs @@ -3,38 +3,20 @@ #nullable disable -using System; -using System.Linq; +using System.Collections.Generic; using osu.Framework.Allocation; -using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.UserInterface; -using osu.Game.Beatmaps; using osu.Game.Rulesets.Objects; -using osu.Game.Rulesets.UI; -using osu.Game.Screens.Play; +using osu.Game.Screens.Play.HUD; using osuTK; namespace osu.Game.Skinning { - public class LegacySongProgress : CompositeDrawable, ISkinnableDrawable + public class LegacySongProgress : SongProgress { - public bool UsesFixedAnchor { get; set; } - - [Resolved] - private GameplayClock gameplayClock { get; set; } - - [Resolved(canBeNull: true)] - private DrawableRuleset drawableRuleset { get; set; } - - [Resolved(canBeNull: true)] - private IBindable beatmap { get; set; } - - private double lastHitTime; - private double firstHitTime; - private double firstEventTime; private CircularProgress pie; [BackgroundDependencyLoader] @@ -76,36 +58,35 @@ namespace osu.Game.Skinning Size = new Vector2(3), } }; - - firstEventTime = beatmap?.Value.Storyboard.EarliestEventTime ?? 0; - - if (drawableRuleset != null) - { - firstHitTime = drawableRuleset.Objects.First().StartTime; - //TODO: this isn't always correct (consider mania where a non-last object may last for longer than the last in the list). - lastHitTime = drawableRuleset.Objects.Last().GetEndTime() + 1; - } } - protected override void Update() + protected override void PopIn() { - base.Update(); + } - double gameplayTime = gameplayClock?.CurrentTime ?? Time.Current; + protected override void PopOut() + { + } - if (gameplayTime < firstHitTime) + protected override void UpdateObjects(IEnumerable objects) + { + } + + protected override void UpdateProgress(double progress, double time, bool isIntro) + { + if (isIntro) { pie.Scale = new Vector2(-1, 1); pie.Anchor = Anchor.TopRight; pie.Colour = new Colour4(199, 255, 47, 153); - pie.Current.Value = 1 - Math.Clamp((gameplayTime - firstEventTime) / (firstHitTime - firstEventTime), 0, 1); + pie.Current.Value = 1 - progress; } else { pie.Scale = new Vector2(1); pie.Anchor = Anchor.TopLeft; pie.Colour = new Colour4(255, 255, 255, 153); - pie.Current.Value = Math.Clamp((gameplayTime - firstHitTime) / (lastHitTime - firstHitTime), 0, 1); + pie.Current.Value = progress; } } } From 494486ad0926dca9fa17bb733e3ccd65f18b4ebf Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 27 Jul 2022 16:27:10 +0900 Subject: [PATCH 101/278] Fix potential test failure if scores are added to the beatmap which is subsequently removed --- osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs b/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs index a82386fd51..fdc9f2569d 100644 --- a/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs +++ b/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs @@ -279,12 +279,16 @@ namespace osu.Game.Tests.Database { var importer = new BeatmapImporter(storage, realm); using var rulesets = new RealmRulesetStore(realm, storage); + string removedFilename = null!; using var __ = getBeatmapArchive(out string pathOriginal); using var _ = getBeatmapArchiveWithModifications(out string pathMissingOneBeatmap, directory => { // arbitrary beatmap removal - directory.GetFiles("*.osu").First().Delete(); + var fileToRemove = directory.GetFiles("*.osu").First(); + + removedFilename = fileToRemove.Name; + fileToRemove.Delete(); }); var importBeforeUpdate = await importer.Import(new ImportTask(pathOriginal)); @@ -296,7 +300,9 @@ namespace osu.Game.Tests.Database importBeforeUpdate.PerformWrite(s => { - var beatmapInfo = s.Beatmaps.Last(); + // make sure not to add scores to the same beatmap that is removed in the update. + var beatmapInfo = s.Beatmaps.First(b => b.File?.Filename != removedFilename); + scoreTargetBeatmapHash = beatmapInfo.Hash; s.Realm.Add(new ScoreInfo(beatmapInfo, s.Realm.All().First(), new RealmUser())); }); From 1e013bd4e90ce2b22830fff88ca5ab283f0a77bd Mon Sep 17 00:00:00 2001 From: Nitrous Date: Wed, 27 Jul 2022 15:57:23 +0800 Subject: [PATCH 102/278] move song progress graph to its own test scene --- .../Gameplay/TestSceneSongProgressGraph.cs | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 osu.Game.Tests/Visual/Gameplay/TestSceneSongProgressGraph.cs diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgressGraph.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgressGraph.cs new file mode 100644 index 0000000000..2fa3c0c7ec --- /dev/null +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgressGraph.cs @@ -0,0 +1,73 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +#nullable disable + +using System.Collections.Generic; +using NUnit.Framework; +using osu.Framework.Graphics; +using osu.Framework.Testing; +using osu.Framework.Utils; +using osu.Game.Rulesets.Objects; +using osu.Game.Screens.Play.HUD; + +namespace osu.Game.Tests.Visual.Gameplay +{ + [TestFixture] + public class TestSceneSongProgressGraph : OsuTestScene + { + private TestSongProgressGraph graph; + + [SetUpSteps] + public void SetupSteps() + { + AddStep("add new big graph", () => + { + if (graph != null) + { + graph.Expire(); + graph = null; + } + + Add(graph = new TestSongProgressGraph + { + RelativeSizeAxes = Axes.X, + Height = 200, + Anchor = Anchor.TopLeft, + Origin = Anchor.TopLeft, + }); + }); + } + + [Test] + public void TestGraphRecreation() + { + AddAssert("ensure not created", () => graph.CreationCount == 0); + AddStep("display values", displayRandomValues); + AddUntilStep("wait for creation count", () => graph.CreationCount == 1); + AddRepeatStep("new values", displayRandomValues, 5); + AddWaitStep("wait some", 5); + AddAssert("ensure recreation debounced", () => graph.CreationCount == 2); + } + + private void displayRandomValues() + { + var objects = new List(); + for (double i = 0; i < 5000; i += RNG.NextDouble() * 10 + i / 1000) + objects.Add(new HitObject { StartTime = i }); + + graph.Objects = objects; + } + + private class TestSongProgressGraph : SongProgressGraph + { + public int CreationCount { get; private set; } + + protected override void RecreateGraph() + { + base.RecreateGraph(); + CreationCount++; + } + } + } +} From 6af6f03e293b22b763dc6b55c833fff2414fc36a Mon Sep 17 00:00:00 2001 From: Nitrous Date: Wed, 27 Jul 2022 15:57:47 +0800 Subject: [PATCH 103/278] refactor song progress test scene --- .../Visual/Gameplay/TestSceneSongProgress.cs | 115 +++++------------- 1 file changed, 30 insertions(+), 85 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs index 6f2853b095..f32a7e7cab 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs @@ -7,23 +7,20 @@ using System.Collections.Generic; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; using osu.Framework.Testing; -using osu.Framework.Utils; using osu.Framework.Timing; -using osu.Game.Graphics; using osu.Game.Rulesets.Objects; using osu.Game.Screens.Play; +using osu.Game.Screens.Play.HUD; +using osu.Game.Skinning; namespace osu.Game.Tests.Visual.Gameplay { [TestFixture] - public class TestSceneSongProgress : OsuTestScene + public class TestSceneSongProgress : SkinnableHUDComponentTestScene { private DefaultSongProgress progress; - private TestSongProgressGraph graph; - private readonly Container progressContainer; + private readonly List progresses = new List(); private readonly StopwatchClock clock; private readonly FramedClock framedClock; @@ -35,77 +32,18 @@ namespace osu.Game.Tests.Visual.Gameplay { clock = new StopwatchClock(); gameplayClock = new GameplayClock(framedClock = new FramedClock(clock)); - - Add(progressContainer = new Container - { - RelativeSizeAxes = Axes.X, - Anchor = Anchor.BottomCentre, - Origin = Anchor.BottomCentre, - Height = 100, - Y = -100, - Child = new Box - { - RelativeSizeAxes = Axes.Both, - Colour = OsuColour.Gray(1), - } - }); } [SetUpSteps] public void SetupSteps() { - AddStep("add new song progress", () => - { - if (progress != null) - { - progress.Expire(); - progress = null; - } - - progressContainer.Add(progress = new DefaultSongProgress - { - RelativeSizeAxes = Axes.X, - Anchor = Anchor.BottomLeft, - Origin = Anchor.BottomLeft, - }); - }); - - AddStep("add new big graph", () => - { - if (graph != null) - { - graph.Expire(); - graph = null; - } - - Add(graph = new TestSongProgressGraph - { - RelativeSizeAxes = Axes.X, - Height = 200, - Anchor = Anchor.TopLeft, - Origin = Anchor.TopLeft, - }); - }); - AddStep("reset clock", clock.Reset); } - [Test] - public void TestGraphRecreation() - { - AddAssert("ensure not created", () => graph.CreationCount == 0); - AddStep("display values", displayRandomValues); - AddUntilStep("wait for creation count", () => graph.CreationCount == 1); - AddRepeatStep("new values", displayRandomValues, 5); - AddWaitStep("wait some", 5); - AddAssert("ensure recreation debounced", () => graph.CreationCount == 2); - } - [Test] public void TestDisplay() { AddStep("display max values", displayMaxValues); - AddUntilStep("wait for graph", () => graph.CreationCount == 1); AddStep("start", clock.Start); AddStep("allow seeking", () => progress.AllowSeeking.Value = true); AddStep("hide graph", () => progress.ShowGraph.Value = false); @@ -115,15 +53,6 @@ namespace osu.Game.Tests.Visual.Gameplay AddStep("stop", clock.Stop); } - private void displayRandomValues() - { - var objects = new List(); - for (double i = 0; i < 5000; i += RNG.NextDouble() * 10 + i / 1000) - objects.Add(new HitObject { StartTime = i }); - - replaceObjects(objects); - } - private void displayMaxValues() { var objects = new List(); @@ -135,10 +64,12 @@ namespace osu.Game.Tests.Visual.Gameplay private void replaceObjects(List objects) { - progress.Objects = objects; - graph.Objects = objects; - progress.RequestSeek = pos => clock.Seek(pos); + + foreach (var progress in progresses) + { + progress.Objects = objects; + } } protected override void Update() @@ -147,15 +78,29 @@ namespace osu.Game.Tests.Visual.Gameplay framedClock.ProcessFrame(); } - private class TestSongProgressGraph : SongProgressGraph + protected override Drawable CreateDefaultImplementation() { - public int CreationCount { get; private set; } - - protected override void RecreateGraph() + progress = new DefaultSongProgress { - base.RecreateGraph(); - CreationCount++; - } + RelativeSizeAxes = Axes.X, + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + }; + + progresses.Add(progress); + return progress; + } + + protected override Drawable CreateLegacyImplementation() + { + var progress = new LegacySongProgress + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + }; + + progresses.Add(progress); + return progress; } } } From a222278710568f240b75b69dc4600941ecb395f4 Mon Sep 17 00:00:00 2001 From: Nitrous Date: Wed, 27 Jul 2022 16:01:35 +0800 Subject: [PATCH 104/278] remove unused using --- osu.Game/Skinning/DefaultSkin.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Skinning/DefaultSkin.cs b/osu.Game/Skinning/DefaultSkin.cs index 0848f42360..7d217dd956 100644 --- a/osu.Game/Skinning/DefaultSkin.cs +++ b/osu.Game/Skinning/DefaultSkin.cs @@ -16,7 +16,6 @@ using osu.Game.Audio; using osu.Game.Beatmaps.Formats; using osu.Game.Extensions; using osu.Game.IO; -using osu.Game.Screens.Play; using osu.Game.Screens.Play.HUD; using osu.Game.Screens.Play.HUD.HitErrorMeters; using osuTK; From 9c543fef481b0afda90d60288a111dd10a544067 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 27 Jul 2022 15:59:36 +0900 Subject: [PATCH 105/278] Remove `CollectionManager` --- .../Collections/IO/ImportCollectionsTest.cs | 83 ++++++++---- osu.Game.Tests/ImportTest.cs | 6 +- .../TestSceneManageCollectionsDialog.cs | 120 +++++++++++------- .../SongSelect/TestSceneFilterControl.cs | 52 ++++---- osu.Game/Beatmaps/RealmBeatmapCollection.cs | 4 +- .../Collections/CollectionFilterDropdown.cs | 6 +- osu.Game/Collections/CollectionManager.cs | 62 --------- .../Collections/CollectionToggleMenuItem.cs | 10 +- .../Collections/DeleteCollectionDialog.cs | 5 +- .../Collections/DrawableCollectionList.cs | 17 ++- .../Collections/DrawableCollectionListItem.cs | 47 ++++--- .../Collections/ManageCollectionsDialog.cs | 5 - osu.Game/Database/LegacyCollectionImporter.cs | 54 ++++---- osu.Game/Database/LegacyImportManager.cs | 11 +- osu.Game/OsuGame.cs | 5 - .../Maintenance/CollectionsSettings.cs | 23 +++- .../OnlinePlay/DrawableRoomPlaylistItem.cs | 10 +- .../Carousel/DrawableCarouselBeatmap.cs | 18 ++- .../Carousel/DrawableCarouselBeatmapSet.cs | 30 ++--- 19 files changed, 276 insertions(+), 292 deletions(-) delete mode 100644 osu.Game/Collections/CollectionManager.cs diff --git a/osu.Game.Tests/Collections/IO/ImportCollectionsTest.cs b/osu.Game.Tests/Collections/IO/ImportCollectionsTest.cs index 685586ff02..32503cdb12 100644 --- a/osu.Game.Tests/Collections/IO/ImportCollectionsTest.cs +++ b/osu.Game.Tests/Collections/IO/ImportCollectionsTest.cs @@ -5,12 +5,14 @@ using System; using System.IO; +using System.Linq; using System.Text; using System.Threading.Tasks; using NUnit.Framework; using osu.Framework.Extensions; using osu.Framework.Platform; using osu.Framework.Testing; +using osu.Game.Beatmaps; using osu.Game.Database; using osu.Game.Tests.Resources; @@ -30,7 +32,11 @@ namespace osu.Game.Tests.Collections.IO await importCollectionsFromStream(osu, new MemoryStream()); - Assert.That(osu.CollectionManager.Collections.Count, Is.Zero); + osu.Realm.Run(realm => + { + var collections = realm.All().ToList(); + Assert.That(collections.Count, Is.Zero); + }); } finally { @@ -50,18 +56,22 @@ namespace osu.Game.Tests.Collections.IO await importCollectionsFromStream(osu, TestResources.OpenResource("Collections/collections.db")); - Assert.That(osu.CollectionManager.Collections.Count, Is.EqualTo(2)); + osu.Realm.Run(realm => + { + var collections = realm.All().ToList(); + Assert.That(collections.Count, Is.EqualTo(2)); - // Even with no beatmaps imported, collections are tracking the hashes and will continue to. - // In the future this whole mechanism will be replaced with having the collections in realm, - // but until that happens it makes rough sense that we want to track not-yet-imported beatmaps - // and have them associate with collections if/when they become available. + // Even with no beatmaps imported, collections are tracking the hashes and will continue to. + // In the future this whole mechanism will be replaced with having the collections in realm, + // but until that happens it makes rough sense that we want to track not-yet-imported beatmaps + // and have them associate with collections if/when they become available. - Assert.That(osu.CollectionManager.Collections[0].Name.Value, Is.EqualTo("First")); - Assert.That(osu.CollectionManager.Collections[0].BeatmapHashes.Count, Is.EqualTo(1)); + Assert.That(collections[0].Name, Is.EqualTo("First")); + Assert.That(collections[0].BeatmapMD5Hashes.Count, Is.EqualTo(1)); - Assert.That(osu.CollectionManager.Collections[1].Name.Value, Is.EqualTo("Second")); - Assert.That(osu.CollectionManager.Collections[1].BeatmapHashes.Count, Is.EqualTo(12)); + Assert.That(collections[1].Name, Is.EqualTo("Second")); + Assert.That(collections[1].BeatmapMD5Hashes.Count, Is.EqualTo(12)); + }); } finally { @@ -81,13 +91,18 @@ namespace osu.Game.Tests.Collections.IO await importCollectionsFromStream(osu, TestResources.OpenResource("Collections/collections.db")); - Assert.That(osu.CollectionManager.Collections.Count, Is.EqualTo(2)); + osu.Realm.Run(realm => + { + var collections = realm.All().ToList(); - Assert.That(osu.CollectionManager.Collections[0].Name.Value, Is.EqualTo("First")); - Assert.That(osu.CollectionManager.Collections[0].BeatmapHashes.Count, Is.EqualTo(1)); + Assert.That(collections.Count, Is.EqualTo(2)); - Assert.That(osu.CollectionManager.Collections[1].Name.Value, Is.EqualTo("Second")); - Assert.That(osu.CollectionManager.Collections[1].BeatmapHashes.Count, Is.EqualTo(12)); + Assert.That(collections[0].Name, Is.EqualTo("First")); + Assert.That(collections[0].BeatmapMD5Hashes.Count, Is.EqualTo(1)); + + Assert.That(collections[1].Name, Is.EqualTo("Second")); + Assert.That(collections[1].BeatmapMD5Hashes.Count, Is.EqualTo(12)); + }); } finally { @@ -124,7 +139,11 @@ namespace osu.Game.Tests.Collections.IO } Assert.That(exceptionThrown, Is.False); - Assert.That(osu.CollectionManager.Collections.Count, Is.EqualTo(0)); + osu.Realm.Run(realm => + { + var collections = realm.All().ToList(); + Assert.That(collections.Count, Is.EqualTo(0)); + }); } finally { @@ -149,12 +168,18 @@ namespace osu.Game.Tests.Collections.IO await importCollectionsFromStream(osu, TestResources.OpenResource("Collections/collections.db")); - // Move first beatmap from second collection into the first. - osu.CollectionManager.Collections[0].BeatmapHashes.Add(osu.CollectionManager.Collections[1].BeatmapHashes[0]); - osu.CollectionManager.Collections[1].BeatmapHashes.RemoveAt(0); + // ReSharper disable once MethodHasAsyncOverload + osu.Realm.Write(realm => + { + var collections = realm.All().ToList(); - // Rename the second collecction. - osu.CollectionManager.Collections[1].Name.Value = "Another"; + // Move first beatmap from second collection into the first. + collections[0].BeatmapMD5Hashes.Add(collections[1].BeatmapMD5Hashes[0]); + collections[1].BeatmapMD5Hashes.RemoveAt(0); + + // Rename the second collecction. + collections[1].Name = "Another"; + }); } finally { @@ -169,13 +194,17 @@ namespace osu.Game.Tests.Collections.IO { var osu = LoadOsuIntoHost(host, true); - Assert.That(osu.CollectionManager.Collections.Count, Is.EqualTo(2)); + osu.Realm.Run(realm => + { + var collections = realm.All().ToList(); + Assert.That(collections.Count, Is.EqualTo(2)); - Assert.That(osu.CollectionManager.Collections[0].Name.Value, Is.EqualTo("First")); - Assert.That(osu.CollectionManager.Collections[0].BeatmapHashes.Count, Is.EqualTo(2)); + Assert.That(collections[0].Name, Is.EqualTo("First")); + Assert.That(collections[0].BeatmapMD5Hashes.Count, Is.EqualTo(2)); - Assert.That(osu.CollectionManager.Collections[1].Name.Value, Is.EqualTo("Another")); - Assert.That(osu.CollectionManager.Collections[1].BeatmapHashes.Count, Is.EqualTo(11)); + Assert.That(collections[1].Name, Is.EqualTo("Another")); + Assert.That(collections[1].BeatmapMD5Hashes.Count, Is.EqualTo(11)); + }); } finally { @@ -188,7 +217,7 @@ namespace osu.Game.Tests.Collections.IO { // intentionally spin this up on a separate task to avoid disposal deadlocks. // see https://github.com/EventStore/EventStore/issues/1179 - await Task.Factory.StartNew(() => new LegacyCollectionImporter(osu.CollectionManager).Import(stream).WaitSafely(), TaskCreationOptions.LongRunning); + await Task.Factory.StartNew(() => new LegacyCollectionImporter(osu.Realm).Import(stream).WaitSafely(), TaskCreationOptions.LongRunning); } } } diff --git a/osu.Game.Tests/ImportTest.cs b/osu.Game.Tests/ImportTest.cs index 1f18f92158..23ca31ee42 100644 --- a/osu.Game.Tests/ImportTest.cs +++ b/osu.Game.Tests/ImportTest.cs @@ -10,7 +10,7 @@ using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Extensions; using osu.Framework.Platform; -using osu.Game.Collections; +using osu.Game.Database; using osu.Game.Tests.Resources; namespace osu.Game.Tests @@ -47,7 +47,7 @@ namespace osu.Game.Tests public class TestOsuGameBase : OsuGameBase { - public CollectionManager CollectionManager { get; private set; } + public RealmAccess Realm => Dependencies.Get(); private readonly bool withBeatmap; @@ -62,8 +62,6 @@ namespace osu.Game.Tests // Beatmap must be imported before the collection manager is loaded. if (withBeatmap) BeatmapManager.Import(TestResources.GetTestBeatmapForImport()).WaitSafely(); - - AddInternal(CollectionManager = new CollectionManager()); } } } diff --git a/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs b/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs index 789139f483..21d2b0328b 100644 --- a/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs +++ b/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; @@ -27,13 +25,10 @@ namespace osu.Game.Tests.Visual.Collections { protected override Container Content { get; } = new Container { RelativeSizeAxes = Axes.Both }; - private DialogOverlay dialogOverlay; - private CollectionManager manager; - - private RulesetStore rulesets; - private BeatmapManager beatmapManager; - - private ManageCollectionsDialog dialog; + private DialogOverlay dialogOverlay = null!; + private RulesetStore rulesets = null!; + private BeatmapManager beatmapManager = null!; + private ManageCollectionsDialog dialog = null!; [BackgroundDependencyLoader] private void load(GameHost host) @@ -46,19 +41,17 @@ namespace osu.Game.Tests.Visual.Collections base.Content.AddRange(new Drawable[] { - manager = new CollectionManager(), Content, dialogOverlay = new DialogOverlay(), }); - Dependencies.Cache(manager); Dependencies.CacheAs(dialogOverlay); } [SetUp] public void SetUp() => Schedule(() => { - manager.Collections.Clear(); + Realm.Write(r => r.RemoveAll()); Child = dialog = new ManageCollectionsDialog(); }); @@ -78,17 +71,17 @@ namespace osu.Game.Tests.Visual.Collections [Test] public void TestLastItemIsPlaceholder() { - AddAssert("last item is placeholder", () => !manager.Collections.Contains(dialog.ChildrenOfType().Last().Model)); + AddAssert("last item is placeholder", () => !dialog.ChildrenOfType().Last().Model.IsManaged); } [Test] public void TestAddCollectionExternal() { - AddStep("add collection", () => manager.Collections.Add(new BeatmapCollection { Name = { Value = "First collection" } })); + AddStep("add collection", () => Realm.Write(r => r.Add(new RealmBeatmapCollection(name: "First collection")))); assertCollectionCount(1); assertCollectionName(0, "First collection"); - AddStep("add another collection", () => manager.Collections.Add(new BeatmapCollection { Name = { Value = "Second collection" } })); + AddStep("add another collection", () => Realm.Write(r => r.Add(new RealmBeatmapCollection(name: "Second collection")))); assertCollectionCount(2); assertCollectionName(1, "Second collection"); } @@ -108,7 +101,7 @@ namespace osu.Game.Tests.Visual.Collections [Test] public void TestAddCollectionViaPlaceholder() { - DrawableCollectionListItem placeholderItem = null; + DrawableCollectionListItem placeholderItem = null!; AddStep("focus placeholder", () => { @@ -117,23 +110,31 @@ namespace osu.Game.Tests.Visual.Collections }); // Done directly via the collection since InputManager methods cannot add text to textbox... - AddStep("change collection name", () => placeholderItem.Model.Name.Value = "a"); + AddStep("change collection name", () => placeholderItem.Model.Name = "a"); assertCollectionCount(1); - AddAssert("collection now exists", () => manager.Collections.Contains(placeholderItem.Model)); + AddAssert("collection now exists", () => placeholderItem.Model.IsManaged); - AddAssert("last item is placeholder", () => !manager.Collections.Contains(dialog.ChildrenOfType().Last().Model)); + AddAssert("last item is placeholder", () => !dialog.ChildrenOfType().Last().Model.IsManaged); } [Test] public void TestRemoveCollectionExternal() { - AddStep("add two collections", () => manager.Collections.AddRange(new[] - { - new BeatmapCollection { Name = { Value = "1" } }, - new BeatmapCollection { Name = { Value = "2" } }, - })); + RealmBeatmapCollection first = null!; - AddStep("remove first collection", () => manager.Collections.RemoveAt(0)); + AddStep("add two collections", () => + { + Realm.Write(r => + { + r.Add(new[] + { + first = new RealmBeatmapCollection(name: "1"), + new RealmBeatmapCollection(name: "2"), + }); + }); + }); + + AddStep("change first collection name", () => Realm.Write(r => r.Remove(first))); assertCollectionCount(1); assertCollectionName(0, "2"); } @@ -151,21 +152,27 @@ namespace osu.Game.Tests.Visual.Collections Width = 0.4f, }); }); - AddStep("add two collections with same name", () => manager.Collections.AddRange(new[] + AddStep("add two collections with same name", () => Realm.Write(r => r.Add(new[] { - new BeatmapCollection { Name = { Value = "1" } }, - new BeatmapCollection { Name = { Value = "1" }, BeatmapHashes = { beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0].MD5Hash } }, - })); + new RealmBeatmapCollection(name: "1"), + new RealmBeatmapCollection(name: "1") + { + BeatmapMD5Hashes = { beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0].MD5Hash } + }, + }))); } [Test] public void TestRemoveCollectionViaButton() { - AddStep("add two collections", () => manager.Collections.AddRange(new[] + AddStep("add two collections", () => Realm.Write(r => r.Add(new[] { - new BeatmapCollection { Name = { Value = "1" } }, - new BeatmapCollection { Name = { Value = "2" }, BeatmapHashes = { beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0].MD5Hash } }, - })); + new RealmBeatmapCollection(name: "1"), + new RealmBeatmapCollection(name: "2") + { + BeatmapMD5Hashes = { beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0].MD5Hash } + }, + }))); assertCollectionCount(2); @@ -198,10 +205,13 @@ namespace osu.Game.Tests.Visual.Collections [Test] public void TestCollectionNotRemovedWhenDialogCancelled() { - AddStep("add two collections", () => manager.Collections.AddRange(new[] + AddStep("add collection", () => Realm.Write(r => r.Add(new[] { - new BeatmapCollection { Name = { Value = "1" }, BeatmapHashes = { beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0].MD5Hash } }, - })); + new RealmBeatmapCollection(name: "1") + { + BeatmapMD5Hashes = { beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0].MD5Hash } + }, + }))); assertCollectionCount(1); @@ -224,13 +234,21 @@ namespace osu.Game.Tests.Visual.Collections [Test] public void TestCollectionRenamedExternal() { - AddStep("add two collections", () => manager.Collections.AddRange(new[] - { - new BeatmapCollection { Name = { Value = "1" } }, - new BeatmapCollection { Name = { Value = "2" } }, - })); + RealmBeatmapCollection first = null!; - AddStep("change first collection name", () => manager.Collections[0].Name.Value = "First"); + AddStep("add two collections", () => + { + Realm.Write(r => + { + r.Add(new[] + { + first = new RealmBeatmapCollection(name: "1"), + new RealmBeatmapCollection(name: "2"), + }); + }); + }); + + AddStep("change first collection name", () => Realm.Write(_ => first.Name = "First")); assertCollectionName(0, "First"); } @@ -238,16 +256,24 @@ namespace osu.Game.Tests.Visual.Collections [Test] public void TestCollectionRenamedOnTextChange() { - AddStep("add two collections", () => manager.Collections.AddRange(new[] + RealmBeatmapCollection first = null!; + + AddStep("add two collections", () => { - new BeatmapCollection { Name = { Value = "1" } }, - new BeatmapCollection { Name = { Value = "2" } }, - })); + Realm.Write(r => + { + r.Add(new[] + { + first = new RealmBeatmapCollection(name: "1"), + new RealmBeatmapCollection(name: "2"), + }); + }); + }); assertCollectionCount(2); AddStep("change first collection name", () => dialog.ChildrenOfType().First().Text = "First"); - AddAssert("collection has new name", () => manager.Collections[0].Name.Value == "First"); + AddUntilStep("collection has new name", () => first.Name == "First"); } private void assertCollectionCount(int count) diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs index 01bf312ddd..e4d69334a3 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Collections.Generic; using System.Linq; using NUnit.Framework; @@ -28,12 +26,9 @@ namespace osu.Game.Tests.Visual.SongSelect { protected override Container Content { get; } = new Container { RelativeSizeAxes = Axes.Both }; - private CollectionManager collectionManager; - - private RulesetStore rulesets; - private BeatmapManager beatmapManager; - - private FilterControl control; + private RulesetStore rulesets = null!; + private BeatmapManager beatmapManager = null!; + private FilterControl control = null!; [BackgroundDependencyLoader] private void load(GameHost host) @@ -46,17 +41,14 @@ namespace osu.Game.Tests.Visual.SongSelect base.Content.AddRange(new Drawable[] { - collectionManager = new CollectionManager(), Content }); - - Dependencies.Cache(collectionManager); } [SetUp] public void SetUp() => Schedule(() => { - collectionManager.Collections.Clear(); + Realm.Write(r => r.RemoveAll()); Child = control = new FilterControl { @@ -77,8 +69,8 @@ namespace osu.Game.Tests.Visual.SongSelect [Test] public void TestCollectionAddedToDropdown() { - AddStep("add collection", () => collectionManager.Collections.Add(new BeatmapCollection { Name = { Value = "1" } })); - AddStep("add collection", () => collectionManager.Collections.Add(new BeatmapCollection { Name = { Value = "2" } })); + AddStep("add collection", () => Realm.Write(r => r.Add(new RealmBeatmapCollection(name: "1")))); + AddStep("add collection", () => Realm.Write(r => r.Add(new RealmBeatmapCollection(name: "2")))); assertCollectionDropdownContains("1"); assertCollectionDropdownContains("2"); } @@ -86,9 +78,11 @@ namespace osu.Game.Tests.Visual.SongSelect [Test] public void TestCollectionRemovedFromDropdown() { - AddStep("add collection", () => collectionManager.Collections.Add(new BeatmapCollection { Name = { Value = "1" } })); - AddStep("add collection", () => collectionManager.Collections.Add(new BeatmapCollection { Name = { Value = "2" } })); - AddStep("remove collection", () => collectionManager.Collections.RemoveAt(0)); + var first = new RealmBeatmapCollection(name: "1"); + + AddStep("add collection", () => Realm.Write(r => r.Add(first))); + AddStep("add collection", () => Realm.Write(r => r.Add(new RealmBeatmapCollection(name: "2")))); + AddStep("remove collection", () => Realm.Write(r => r.Remove(first))); assertCollectionDropdownContains("1", false); assertCollectionDropdownContains("2"); @@ -97,7 +91,7 @@ namespace osu.Game.Tests.Visual.SongSelect [Test] public void TestCollectionRenamed() { - AddStep("add collection", () => collectionManager.Collections.Add(new BeatmapCollection { Name = { Value = "1" } })); + AddStep("add collection", () => Realm.Write(r => r.Add(new RealmBeatmapCollection(name: "1")))); AddStep("select collection", () => { var dropdown = control.ChildrenOfType().Single(); @@ -106,7 +100,7 @@ namespace osu.Game.Tests.Visual.SongSelect addExpandHeaderStep(); - AddStep("change name", () => collectionManager.Collections[0].Name.Value = "First"); + AddStep("change name", () => Realm.Write(_ => getFirstCollection().Name = "First")); assertCollectionDropdownContains("First"); assertCollectionHeaderDisplays("First"); @@ -124,7 +118,7 @@ namespace osu.Game.Tests.Visual.SongSelect public void TestCollectionFilterHasAddButton() { addExpandHeaderStep(); - AddStep("add collection", () => collectionManager.Collections.Add(new BeatmapCollection { Name = { Value = "1" } })); + AddStep("add collection", () => Realm.Write(r => r.Add(new RealmBeatmapCollection(name: "1")))); AddStep("hover collection", () => InputManager.MoveMouseTo(getAddOrRemoveButton(1))); AddAssert("collection has add button", () => getAddOrRemoveButton(1).IsPresent); } @@ -134,7 +128,7 @@ namespace osu.Game.Tests.Visual.SongSelect { addExpandHeaderStep(); - AddStep("add collection", () => collectionManager.Collections.Add(new BeatmapCollection { Name = { Value = "1" } })); + AddStep("add collection", () => Realm.Write(r => r.Add(new RealmBeatmapCollection(name: "1")))); AddStep("select available beatmap", () => Beatmap.Value = beatmapManager.GetWorkingBeatmap(beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0])); AddAssert("button enabled", () => getAddOrRemoveButton(1).Enabled.Value); @@ -150,13 +144,13 @@ namespace osu.Game.Tests.Visual.SongSelect AddStep("select available beatmap", () => Beatmap.Value = beatmapManager.GetWorkingBeatmap(beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0])); - AddStep("add collection", () => collectionManager.Collections.Add(new BeatmapCollection { Name = { Value = "1" } })); + AddStep("add collection", () => Realm.Write(r => r.Add(new RealmBeatmapCollection(name: "1")))); AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusSquare)); - AddStep("add beatmap to collection", () => collectionManager.Collections[0].BeatmapHashes.Add(Beatmap.Value.BeatmapInfo.MD5Hash)); + AddStep("add beatmap to collection", () => getFirstCollection().BeatmapMD5Hashes.Add(Beatmap.Value.BeatmapInfo.MD5Hash)); AddAssert("button is minus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.MinusSquare)); - AddStep("remove beatmap from collection", () => collectionManager.Collections[0].BeatmapHashes.Clear()); + AddStep("remove beatmap from collection", () => getFirstCollection().BeatmapMD5Hashes.Clear()); AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusSquare)); } @@ -167,15 +161,15 @@ namespace osu.Game.Tests.Visual.SongSelect AddStep("select available beatmap", () => Beatmap.Value = beatmapManager.GetWorkingBeatmap(beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0])); - AddStep("add collection", () => collectionManager.Collections.Add(new BeatmapCollection { Name = { Value = "1" } })); + AddStep("add collection", () => Realm.Write(r => r.Add(new RealmBeatmapCollection(name: "1")))); AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusSquare)); addClickAddOrRemoveButtonStep(1); - AddAssert("collection contains beatmap", () => collectionManager.Collections[0].BeatmapHashes.Contains(Beatmap.Value.BeatmapInfo.MD5Hash)); + AddAssert("collection contains beatmap", () => getFirstCollection().BeatmapMD5Hashes.Contains(Beatmap.Value.BeatmapInfo.MD5Hash)); AddAssert("button is minus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.MinusSquare)); addClickAddOrRemoveButtonStep(1); - AddAssert("collection does not contain beatmap", () => !collectionManager.Collections[0].BeatmapHashes.Contains(Beatmap.Value.BeatmapInfo.MD5Hash)); + AddAssert("collection does not contain beatmap", () => !getFirstCollection().BeatmapMD5Hashes.Contains(Beatmap.Value.BeatmapInfo.MD5Hash)); AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusSquare)); } @@ -184,7 +178,7 @@ namespace osu.Game.Tests.Visual.SongSelect { addExpandHeaderStep(); - AddStep("add collection", () => collectionManager.Collections.Add(new BeatmapCollection { Name = { Value = "1" } })); + AddStep("add collection", () => Realm.Write(r => r.Add(new RealmBeatmapCollection(name: "1")))); AddStep("select collection", () => { InputManager.MoveMouseTo(getCollectionDropdownItems().ElementAt(1)); @@ -202,6 +196,8 @@ namespace osu.Game.Tests.Visual.SongSelect AddAssert("collection filter still selected", () => control.CreateCriteria().Collection?.Name.Value == "1"); } + private RealmBeatmapCollection getFirstCollection() => Realm.Run(r => r.All().First()); + private void assertCollectionHeaderDisplays(string collectionName, bool shouldDisplay = true) => AddAssert($"collection dropdown header displays '{collectionName}'", () => shouldDisplay == (control.ChildrenOfType().Single().ChildrenOfType().First().Text == collectionName)); diff --git a/osu.Game/Beatmaps/RealmBeatmapCollection.cs b/osu.Game/Beatmaps/RealmBeatmapCollection.cs index d3261fc39e..22ba9d5789 100644 --- a/osu.Game/Beatmaps/RealmBeatmapCollection.cs +++ b/osu.Game/Beatmaps/RealmBeatmapCollection.cs @@ -16,14 +16,14 @@ namespace osu.Game.Beatmaps public string Name { get; set; } = string.Empty; - public List BeatmapMD5Hashes { get; set; } = null!; + public IList BeatmapMD5Hashes { get; } = null!; /// /// The date when this collection was last modified. /// public DateTimeOffset LastModified { get; set; } - public RealmBeatmapCollection(string? name, List? beatmapMD5Hashes) + public RealmBeatmapCollection(string? name = null, IList? beatmapMD5Hashes = null) { ID = Guid.NewGuid(); Name = name ?? string.Empty; diff --git a/osu.Game/Collections/CollectionFilterDropdown.cs b/osu.Game/Collections/CollectionFilterDropdown.cs index d099eb6e1b..ed2c0c7cfb 100644 --- a/osu.Game/Collections/CollectionFilterDropdown.cs +++ b/osu.Game/Collections/CollectionFilterDropdown.cs @@ -46,9 +46,6 @@ namespace osu.Game.Collections [Resolved(CanBeNull = true)] private ManageCollectionsDialog manageCollectionsDialog { get; set; } - [Resolved(CanBeNull = true)] - private CollectionManager collectionManager { get; set; } - public CollectionFilterDropdown() { ItemSource = filters; @@ -59,8 +56,7 @@ namespace osu.Game.Collections { base.LoadComplete(); - if (collectionManager != null) - collections.BindTo(collectionManager.Collections); + // TODO: bind to realm data // Dropdown has logic which triggers a change on the bindable with every change to the contained items. // This is not desirable here, as it leads to multiple filter operations running even though nothing has changed. diff --git a/osu.Game/Collections/CollectionManager.cs b/osu.Game/Collections/CollectionManager.cs deleted file mode 100644 index 0d4ee5c722..0000000000 --- a/osu.Game/Collections/CollectionManager.cs +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -#nullable disable - -using System; -using osu.Framework.Allocation; -using osu.Framework.Bindables; -using osu.Framework.Graphics; -using osu.Game.Beatmaps; -using osu.Game.Database; -using osu.Game.Overlays.Notifications; -using Realms; - -namespace osu.Game.Collections -{ - /// - /// Handles user-defined collections of beatmaps. - /// - public class CollectionManager : Component, IPostNotifications - { - public readonly BindableList Collections = new BindableList(); - - [Resolved] - private RealmAccess realm { get; set; } - - [BackgroundDependencyLoader] - private void load() - { - } - - protected override void LoadComplete() - { - base.LoadComplete(); - - realm.RegisterForNotifications(r => r.All(), collectionsChanged); - } - - private void collectionsChanged(IRealmCollection sender, ChangeSet changes, Exception error) - { - // TODO: hook up with realm changes. - - if (changes == null) - { - foreach (var collection in sender) - Collections.Add(new BeatmapCollection - { - Name = { Value = collection.Name }, - BeatmapHashes = { Value = collection.BeatmapMD5Hashes }, - }); - } - } - - public Action PostNotification { protected get; set; } - - public void DeleteAll() - { - Collections.Clear(); - PostNotification?.Invoke(new ProgressCompletionNotification { Text = "Deleted all collections!" }); - } - } -} diff --git a/osu.Game/Collections/CollectionToggleMenuItem.cs b/osu.Game/Collections/CollectionToggleMenuItem.cs index f2b10305b8..632249913d 100644 --- a/osu.Game/Collections/CollectionToggleMenuItem.cs +++ b/osu.Game/Collections/CollectionToggleMenuItem.cs @@ -8,16 +8,16 @@ namespace osu.Game.Collections { public class CollectionToggleMenuItem : ToggleMenuItem { - public CollectionToggleMenuItem(BeatmapCollection collection, IBeatmapInfo beatmap) - : base(collection.Name.Value, MenuItemType.Standard, state => + public CollectionToggleMenuItem(RealmBeatmapCollection collection, IBeatmapInfo beatmap) + : base(collection.Name, MenuItemType.Standard, state => { if (state) - collection.BeatmapHashes.Add(beatmap.MD5Hash); + collection.BeatmapMD5Hashes.Add(beatmap.MD5Hash); else - collection.BeatmapHashes.Remove(beatmap.MD5Hash); + collection.BeatmapMD5Hashes.Remove(beatmap.MD5Hash); }) { - State.Value = collection.BeatmapHashes.Contains(beatmap.MD5Hash); + State.Value = collection.BeatmapMD5Hashes.Contains(beatmap.MD5Hash); } } } diff --git a/osu.Game/Collections/DeleteCollectionDialog.cs b/osu.Game/Collections/DeleteCollectionDialog.cs index 1da2870913..33c2174623 100644 --- a/osu.Game/Collections/DeleteCollectionDialog.cs +++ b/osu.Game/Collections/DeleteCollectionDialog.cs @@ -6,16 +6,17 @@ using System; using Humanizer; using osu.Framework.Graphics.Sprites; +using osu.Game.Beatmaps; using osu.Game.Overlays.Dialog; namespace osu.Game.Collections { public class DeleteCollectionDialog : PopupDialog { - public DeleteCollectionDialog(BeatmapCollection collection, Action deleteAction) + public DeleteCollectionDialog(RealmBeatmapCollection collection, Action deleteAction) { HeaderText = "Confirm deletion of"; - BodyText = $"{collection.Name.Value} ({"beatmap".ToQuantity(collection.BeatmapHashes.Count)})"; + BodyText = $"{collection.Name} ({"beatmap".ToQuantity(collection.BeatmapMD5Hashes.Count)})"; Icon = FontAwesome.Regular.TrashAlt; diff --git a/osu.Game/Collections/DrawableCollectionList.cs b/osu.Game/Collections/DrawableCollectionList.cs index 4fe5733c2f..63f04641f4 100644 --- a/osu.Game/Collections/DrawableCollectionList.cs +++ b/osu.Game/Collections/DrawableCollectionList.cs @@ -7,28 +7,31 @@ using System.Linq; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Game.Beatmaps; using osu.Game.Graphics.Containers; using osuTK; namespace osu.Game.Collections { /// - /// Visualises a list of s. + /// Visualises a list of s. /// - public class DrawableCollectionList : OsuRearrangeableListContainer + public class DrawableCollectionList : OsuRearrangeableListContainer { private Scroll scroll; protected override ScrollContainer CreateScrollContainer() => scroll = new Scroll(); - protected override FillFlowContainer> CreateListFillFlowContainer() => new Flow + protected override FillFlowContainer> CreateListFillFlowContainer() => new Flow { DragActive = { BindTarget = DragActive } }; - protected override OsuRearrangeableListItem CreateOsuDrawable(BeatmapCollection item) + // TODO: source from realm + + protected override OsuRearrangeableListItem CreateOsuDrawable(RealmBeatmapCollection item) { - if (item == scroll.PlaceholderItem.Model) + if (item.ID == scroll.PlaceholderItem.Model.ID) return scroll.ReplacePlaceholder(); return new DrawableCollectionListItem(item, true); @@ -95,7 +98,7 @@ namespace osu.Game.Collections var previous = PlaceholderItem; placeholderContainer.Clear(false); - placeholderContainer.Add(PlaceholderItem = new DrawableCollectionListItem(new BeatmapCollection(), false)); + placeholderContainer.Add(PlaceholderItem = new DrawableCollectionListItem(new RealmBeatmapCollection(), false)); return previous; } @@ -104,7 +107,7 @@ namespace osu.Game.Collections /// /// The flow of . Disables layout easing unless a drag is in progress. /// - private class Flow : FillFlowContainer> + private class Flow : FillFlowContainer> { public readonly IBindable DragActive = new Bindable(); diff --git a/osu.Game/Collections/DrawableCollectionListItem.cs b/osu.Game/Collections/DrawableCollectionListItem.cs index 4596fc0e52..a29b2ef81c 100644 --- a/osu.Game/Collections/DrawableCollectionListItem.cs +++ b/osu.Game/Collections/DrawableCollectionListItem.cs @@ -12,6 +12,8 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; using osu.Framework.Input.Events; +using osu.Game.Beatmaps; +using osu.Game.Database; using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.UserInterface; @@ -22,15 +24,15 @@ using osuTK.Graphics; namespace osu.Game.Collections { /// - /// Visualises a inside a . + /// Visualises a inside a . /// - public class DrawableCollectionListItem : OsuRearrangeableListItem + public class DrawableCollectionListItem : OsuRearrangeableListItem { private const float item_height = 35; private const float button_width = item_height * 0.75f; /// - /// Whether the currently exists inside the . + /// Whether the currently exists inside realm. /// public IBindable IsCreated => isCreated; @@ -39,9 +41,9 @@ namespace osu.Game.Collections /// /// Creates a new . /// - /// The . - /// Whether currently exists inside the . - public DrawableCollectionListItem(BeatmapCollection item, bool isCreated) + /// The . + /// Whether currently exists inside realm. + public DrawableCollectionListItem(RealmBeatmapCollection item, bool isCreated) : base(item) { this.isCreated.Value = isCreated; @@ -61,24 +63,18 @@ namespace osu.Game.Collections { public readonly Bindable IsCreated = new Bindable(); - private readonly IBindable collectionName; - private readonly BeatmapCollection collection; - - [Resolved(CanBeNull = true)] - private CollectionManager collectionManager { get; set; } + private readonly RealmBeatmapCollection collection; private Container textBoxPaddingContainer; private ItemTextBox textBox; - public ItemContent(BeatmapCollection collection) + public ItemContent(RealmBeatmapCollection collection) { this.collection = collection; RelativeSizeAxes = Axes.X; Height = item_height; Masking = true; - - collectionName = collection.Name.GetBoundCopy(); } [BackgroundDependencyLoader] @@ -111,14 +107,17 @@ namespace osu.Game.Collections }; } + [Resolved] + private RealmAccess realm { get; set; } + protected override void LoadComplete() { base.LoadComplete(); // Bind late, as the collection name may change externally while still loading. - textBox.Current = collection.Name; + textBox.Current.Value = collection.Name; + textBox.Current.BindValueChanged(_ => createNewCollection(), true); - collectionName.BindValueChanged(_ => createNewCollection(), true); IsCreated.BindValueChanged(created => textBoxPaddingContainer.Padding = new MarginPadding { Right = created.NewValue ? button_width : 0 }, true); } @@ -127,11 +126,11 @@ namespace osu.Game.Collections if (IsCreated.Value) return; - if (string.IsNullOrEmpty(collectionName.Value)) + if (string.IsNullOrEmpty(textBox.Current.Value)) return; // Add the new collection and disable our placeholder. If all text is removed, the placeholder should not show back again. - collectionManager?.Collections.Add(collection); + realm.Write(r => r.Add(collection)); textBox.PlaceholderText = string.Empty; // When this item changes from placeholder to non-placeholder (via changing containers), its textbox will lose focus, so it needs to be re-focused. @@ -162,15 +161,15 @@ namespace osu.Game.Collections [Resolved(CanBeNull = true)] private IDialogOverlay dialogOverlay { get; set; } - [Resolved(CanBeNull = true)] - private CollectionManager collectionManager { get; set; } + [Resolved] + private RealmAccess realmAccess { get; set; } - private readonly BeatmapCollection collection; + private readonly RealmBeatmapCollection collection; private Drawable fadeContainer; private Drawable background; - public DeleteButton(BeatmapCollection collection) + public DeleteButton(RealmBeatmapCollection collection) { this.collection = collection; RelativeSizeAxes = Axes.Y; @@ -227,7 +226,7 @@ namespace osu.Game.Collections { background.FlashColour(Color4.White, 150); - if (collection.BeatmapHashes.Count == 0) + if (collection.BeatmapMD5Hashes.Count == 0) deleteCollection(); else dialogOverlay?.Push(new DeleteCollectionDialog(collection, deleteCollection)); @@ -235,7 +234,7 @@ namespace osu.Game.Collections return true; } - private void deleteCollection() => collectionManager?.Collections.Remove(collection); + private void deleteCollection() => realmAccess.Write(r => r.Remove(collection)); } } } diff --git a/osu.Game/Collections/ManageCollectionsDialog.cs b/osu.Game/Collections/ManageCollectionsDialog.cs index a9d699bc9f..721e0d632e 100644 --- a/osu.Game/Collections/ManageCollectionsDialog.cs +++ b/osu.Game/Collections/ManageCollectionsDialog.cs @@ -5,7 +5,6 @@ using osu.Framework.Allocation; using osu.Framework.Audio; -using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; @@ -26,9 +25,6 @@ namespace osu.Game.Collections private AudioFilter lowPassFilter; - [Resolved(CanBeNull = true)] - private CollectionManager collectionManager { get; set; } - public ManageCollectionsDialog() { Anchor = Anchor.Centre; @@ -107,7 +103,6 @@ namespace osu.Game.Collections new DrawableCollectionList { RelativeSizeAxes = Axes.Both, - Items = { BindTarget = collectionManager?.Collections ?? new BindableList() } } } } diff --git a/osu.Game/Database/LegacyCollectionImporter.cs b/osu.Game/Database/LegacyCollectionImporter.cs index 8168419e80..aa98c491b1 100644 --- a/osu.Game/Database/LegacyCollectionImporter.cs +++ b/osu.Game/Database/LegacyCollectionImporter.cs @@ -1,14 +1,13 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using osu.Framework.Logging; -using osu.Game.Collections; +using osu.Game.Beatmaps; using osu.Game.IO; using osu.Game.IO.Legacy; using osu.Game.Overlays.Notifications; @@ -17,17 +16,17 @@ namespace osu.Game.Database { public class LegacyCollectionImporter { - private readonly CollectionManager collections; + public Action? PostNotification { protected get; set; } - public LegacyCollectionImporter(CollectionManager collections) - { - this.collections = collections; - } - - public Action PostNotification { protected get; set; } + private readonly RealmAccess realm; private const string database_name = "collection.db"; + public LegacyCollectionImporter(RealmAccess realm) + { + this.realm = realm; + } + public Task GetAvailableCount(StableStorage stableStorage) { if (!stableStorage.Exists(database_name)) @@ -76,26 +75,30 @@ namespace osu.Game.Database notification.State = ProgressNotificationState.Completed; } - private Task importCollections(List newCollections) + private Task importCollections(List newCollections) { var tcs = new TaskCompletionSource(); - // Schedule(() => - // { try { - foreach (var newCol in newCollections) + realm.Write(r => { - var existing = collections.Collections.FirstOrDefault(c => c.Name.Value == newCol.Name.Value); - if (existing == null) - collections.Collections.Add(existing = new BeatmapCollection { Name = { Value = newCol.Name.Value } }); - - foreach (string newBeatmap in newCol.BeatmapHashes) + foreach (var collection in newCollections) { - if (!existing.BeatmapHashes.Contains(newBeatmap)) - existing.BeatmapHashes.Add(newBeatmap); + var existing = r.All().FirstOrDefault(c => c.Name == collection.Name); + + if (existing != null) + { + foreach (string newBeatmap in existing.BeatmapMD5Hashes) + { + if (!existing.BeatmapMD5Hashes.Contains(newBeatmap)) + existing.BeatmapMD5Hashes.Add(newBeatmap); + } + } + else + r.Add(collection); } - } + }); tcs.SetResult(true); } @@ -104,12 +107,11 @@ namespace osu.Game.Database Logger.Error(e, "Failed to import collection."); tcs.SetException(e); } - // }); return tcs.Task; } - private List readCollections(Stream stream, ProgressNotification notification = null) + private List readCollections(Stream stream, ProgressNotification? notification = null) { if (notification != null) { @@ -117,7 +119,7 @@ namespace osu.Game.Database notification.Progress = 0; } - var result = new List(); + var result = new List(); try { @@ -133,7 +135,7 @@ namespace osu.Game.Database if (notification?.CancellationToken.IsCancellationRequested == true) return result; - var collection = new BeatmapCollection { Name = { Value = sr.ReadString() } }; + var collection = new RealmBeatmapCollection(sr.ReadString()); int mapCount = sr.ReadInt32(); for (int j = 0; j < mapCount; j++) @@ -143,7 +145,7 @@ namespace osu.Game.Database string checksum = sr.ReadString(); - collection.BeatmapHashes.Add(checksum); + collection.BeatmapMD5Hashes.Add(checksum); } if (notification != null) diff --git a/osu.Game/Database/LegacyImportManager.cs b/osu.Game/Database/LegacyImportManager.cs index 05bd5ceb54..baa117fe07 100644 --- a/osu.Game/Database/LegacyImportManager.cs +++ b/osu.Game/Database/LegacyImportManager.cs @@ -13,7 +13,6 @@ using osu.Framework.Extensions.EnumExtensions; using osu.Framework.Graphics; using osu.Framework.Platform; using osu.Game.Beatmaps; -using osu.Game.Collections; using osu.Game.IO; using osu.Game.Overlays; using osu.Game.Overlays.Settings.Sections.Maintenance; @@ -36,15 +35,15 @@ namespace osu.Game.Database [Resolved] private ScoreManager scores { get; set; } - [Resolved] - private CollectionManager collections { get; set; } - [Resolved(canBeNull: true)] private OsuGame game { get; set; } [Resolved] private IDialogOverlay dialogOverlay { get; set; } + [Resolved] + private RealmAccess realmAccess { get; set; } + [Resolved(canBeNull: true)] private DesktopGameHost desktopGameHost { get; set; } @@ -72,7 +71,7 @@ namespace osu.Game.Database return await new LegacySkinImporter(skins).GetAvailableCount(stableStorage); case StableContent.Collections: - return await new LegacyCollectionImporter(collections).GetAvailableCount(stableStorage); + return await new LegacyCollectionImporter(realmAccess).GetAvailableCount(stableStorage); case StableContent.Scores: return await new LegacyScoreImporter(scores).GetAvailableCount(stableStorage); @@ -109,7 +108,7 @@ namespace osu.Game.Database importTasks.Add(new LegacySkinImporter(skins).ImportFromStableAsync(stableStorage)); if (content.HasFlagFast(StableContent.Collections)) - importTasks.Add(beatmapImportTask.ContinueWith(_ => new LegacyCollectionImporter(collections).ImportFromStableAsync(stableStorage), TaskContinuationOptions.OnlyOnRanToCompletion)); + importTasks.Add(beatmapImportTask.ContinueWith(_ => new LegacyCollectionImporter(realmAccess).ImportFromStableAsync(stableStorage), TaskContinuationOptions.OnlyOnRanToCompletion)); if (content.HasFlagFast(StableContent.Scores)) importTasks.Add(beatmapImportTask.ContinueWith(_ => new LegacyScoreImporter(scores).ImportFromStableAsync(stableStorage), TaskContinuationOptions.OnlyOnRanToCompletion)); diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 8d8864a46a..78cc4d7f70 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -858,11 +858,6 @@ namespace osu.Game d.Origin = Anchor.TopRight; }), rightFloatingOverlayContent.Add, true); - loadComponentSingleFile(new CollectionManager - { - PostNotification = n => Notifications.Post(n), - }, Add, true); - loadComponentSingleFile(legacyImportManager, Add); loadComponentSingleFile(screenshotManager, Add); diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/CollectionsSettings.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/CollectionsSettings.cs index 5367f644ca..0b17ab9c6c 100644 --- a/osu.Game/Overlays/Settings/Sections/Maintenance/CollectionsSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Maintenance/CollectionsSettings.cs @@ -3,9 +3,10 @@ using osu.Framework.Allocation; using osu.Framework.Localisation; -using osu.Game.Collections; +using osu.Game.Beatmaps; using osu.Game.Database; using osu.Game.Localisation; +using osu.Game.Overlays.Notifications; namespace osu.Game.Overlays.Settings.Sections.Maintenance { @@ -15,11 +16,15 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance private SettingsButton importCollectionsButton = null!; - [BackgroundDependencyLoader] - private void load(CollectionManager? collectionManager, LegacyImportManager? legacyImportManager, IDialogOverlay? dialogOverlay) - { - if (collectionManager == null) return; + [Resolved] + private RealmAccess realm { get; set; } = null!; + [Resolved] + private INotificationOverlay notificationOverlay { get; set; } = null!; + + [BackgroundDependencyLoader] + private void load(LegacyImportManager? legacyImportManager, IDialogOverlay? dialogOverlay) + { if (legacyImportManager?.SupportsImportFromStable == true) { Add(importCollectionsButton = new SettingsButton @@ -38,9 +43,15 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance Text = MaintenanceSettingsStrings.DeleteAllCollections, Action = () => { - dialogOverlay?.Push(new MassDeleteConfirmationDialog(collectionManager.DeleteAll)); + dialogOverlay?.Push(new MassDeleteConfirmationDialog(deleteAllCollections)); } }); } + + private void deleteAllCollections() + { + realm.Write(r => r.RemoveAll()); + notificationOverlay.Post(new ProgressCompletionNotification { Text = "Deleted all collections!" }); + } } } diff --git a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs index f38077a9a7..b17c4934cd 100644 --- a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs +++ b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs @@ -94,6 +94,9 @@ namespace osu.Game.Screens.OnlinePlay private PanelBackground panelBackground; private FillFlowContainer mainFillFlow; + [Resolved] + private RealmAccess realm { get; set; } + [Resolved] private RulesetStore rulesets { get; set; } @@ -112,9 +115,6 @@ namespace osu.Game.Screens.OnlinePlay [Resolved(CanBeNull = true)] private BeatmapSetOverlay beatmapOverlay { get; set; } - [Resolved(CanBeNull = true)] - private CollectionManager collectionManager { get; set; } - [Resolved(CanBeNull = true)] private ManageCollectionsDialog manageCollectionsDialog { get; set; } @@ -495,11 +495,11 @@ namespace osu.Game.Screens.OnlinePlay if (beatmapOverlay != null) items.Add(new OsuMenuItem("Details...", MenuItemType.Standard, () => beatmapOverlay.FetchAndShowBeatmap(Item.Beatmap.OnlineID))); - if (collectionManager != null && beatmap != null) + if (beatmap != null) { if (beatmaps.QueryBeatmap(b => b.OnlineID == beatmap.OnlineID) is BeatmapInfo local && !local.BeatmapSet.AsNonNull().DeletePending) { - var collectionItems = collectionManager.Collections.Select(c => new CollectionToggleMenuItem(c, beatmap)).Cast().ToList(); + var collectionItems = realm.Realm.All().Select(c => new CollectionToggleMenuItem(c, beatmap)).Cast().ToList(); if (manageCollectionsDialog != null) collectionItems.Add(new OsuMenuItem("Manage...", MenuItemType.Standard, manageCollectionsDialog.Show)); diff --git a/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs b/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs index 50e30c68d5..bfc93b34e2 100644 --- a/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs +++ b/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs @@ -22,6 +22,7 @@ using osu.Framework.Input.Events; using osu.Game.Beatmaps; using osu.Game.Beatmaps.Drawables; using osu.Game.Collections; +using osu.Game.Database; using osu.Game.Graphics; using osu.Game.Graphics.Backgrounds; using osu.Game.Graphics.Sprites; @@ -63,12 +64,12 @@ namespace osu.Game.Screens.Select.Carousel [Resolved] private BeatmapDifficultyCache difficultyCache { get; set; } - [Resolved(CanBeNull = true)] - private CollectionManager collectionManager { get; set; } - [Resolved(CanBeNull = true)] private ManageCollectionsDialog manageCollectionsDialog { get; set; } + [Resolved] + private RealmAccess realm { get; set; } + private IBindable starDifficultyBindable; private CancellationTokenSource starDifficultyCancellationSource; @@ -237,14 +238,11 @@ namespace osu.Game.Screens.Select.Carousel if (beatmapInfo.OnlineID > 0 && beatmapOverlay != null) items.Add(new OsuMenuItem("Details...", MenuItemType.Standard, () => beatmapOverlay.FetchAndShowBeatmap(beatmapInfo.OnlineID))); - if (collectionManager != null) - { - var collectionItems = collectionManager.Collections.Select(c => new CollectionToggleMenuItem(c, beatmapInfo)).Cast().ToList(); - if (manageCollectionsDialog != null) - collectionItems.Add(new OsuMenuItem("Manage...", MenuItemType.Standard, manageCollectionsDialog.Show)); + var collectionItems = realm.Realm.All().Select(c => new CollectionToggleMenuItem(c, beatmapInfo)).Cast().ToList(); + if (manageCollectionsDialog != null) + collectionItems.Add(new OsuMenuItem("Manage...", MenuItemType.Standard, manageCollectionsDialog.Show)); - items.Add(new OsuMenuItem("Collections") { Items = collectionItems }); - } + items.Add(new OsuMenuItem("Collections") { Items = collectionItems }); if (hideRequested != null) items.Add(new OsuMenuItem(CommonStrings.ButtonsHide.ToSentence(), MenuItemType.Destructive, () => hideRequested(beatmapInfo))); diff --git a/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmapSet.cs b/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmapSet.cs index 8c266c8dff..3726d955bd 100644 --- a/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmapSet.cs +++ b/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmapSet.cs @@ -17,6 +17,7 @@ using osu.Framework.Graphics.UserInterface; using osu.Framework.Utils; using osu.Game.Beatmaps; using osu.Game.Collections; +using osu.Game.Database; using osu.Game.Graphics.UserInterface; using osu.Game.Overlays; @@ -32,12 +33,12 @@ namespace osu.Game.Screens.Select.Carousel [Resolved(CanBeNull = true)] private IDialogOverlay dialogOverlay { get; set; } - [Resolved(CanBeNull = true)] - private CollectionManager collectionManager { get; set; } - [Resolved(CanBeNull = true)] private ManageCollectionsDialog manageCollectionsDialog { get; set; } + [Resolved] + private RealmAccess realm { get; set; } + public IEnumerable DrawableBeatmaps => beatmapContainer?.IsLoaded != true ? Enumerable.Empty() : beatmapContainer.AliveChildren; [CanBeNull] @@ -223,14 +224,11 @@ namespace osu.Game.Screens.Select.Carousel if (beatmapSet.OnlineID > 0 && viewDetails != null) items.Add(new OsuMenuItem("Details...", MenuItemType.Standard, () => viewDetails(beatmapSet.OnlineID))); - if (collectionManager != null) - { - var collectionItems = collectionManager.Collections.Select(createCollectionMenuItem).ToList(); - if (manageCollectionsDialog != null) - collectionItems.Add(new OsuMenuItem("Manage...", MenuItemType.Standard, manageCollectionsDialog.Show)); + var collectionItems = realm.Realm.All().AsEnumerable().Select(createCollectionMenuItem).ToList(); + if (manageCollectionsDialog != null) + collectionItems.Add(new OsuMenuItem("Manage...", MenuItemType.Standard, manageCollectionsDialog.Show)); - items.Add(new OsuMenuItem("Collections") { Items = collectionItems }); - } + items.Add(new OsuMenuItem("Collections") { Items = collectionItems }); if (beatmapSet.Beatmaps.Any(b => b.Hidden)) items.Add(new OsuMenuItem("Restore all hidden", MenuItemType.Standard, () => restoreHiddenRequested(beatmapSet))); @@ -241,13 +239,13 @@ namespace osu.Game.Screens.Select.Carousel } } - private MenuItem createCollectionMenuItem(BeatmapCollection collection) + private MenuItem createCollectionMenuItem(RealmBeatmapCollection collection) { Debug.Assert(beatmapSet != null); TernaryState state; - int countExisting = beatmapSet.Beatmaps.Count(b => collection.BeatmapHashes.Contains(b.MD5Hash)); + int countExisting = beatmapSet.Beatmaps.Count(b => collection.BeatmapMD5Hashes.Contains(b.MD5Hash)); if (countExisting == beatmapSet.Beatmaps.Count) state = TernaryState.True; @@ -256,21 +254,21 @@ namespace osu.Game.Screens.Select.Carousel else state = TernaryState.False; - return new TernaryStateToggleMenuItem(collection.Name.Value, MenuItemType.Standard, s => + return new TernaryStateToggleMenuItem(collection.Name, MenuItemType.Standard, s => { foreach (var b in beatmapSet.Beatmaps) { switch (s) { case TernaryState.True: - if (collection.BeatmapHashes.Contains(b.MD5Hash)) + if (collection.BeatmapMD5Hashes.Contains(b.MD5Hash)) continue; - collection.BeatmapHashes.Add(b.MD5Hash); + collection.BeatmapMD5Hashes.Add(b.MD5Hash); break; case TernaryState.False: - collection.BeatmapHashes.Remove(b.MD5Hash); + collection.BeatmapMD5Hashes.Remove(b.MD5Hash); break; } } From 41393616d80440b78000abd8db504e8b73f19ef1 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 27 Jul 2022 16:46:23 +0900 Subject: [PATCH 106/278] Replace `BeatmapCollection` with `RealmBeatmapCollection` --- .../Collections/IO/ImportCollectionsTest.cs | 14 ++-- .../TestSceneManageCollectionsDialog.cs | 38 +++++----- .../SongSelect/TestSceneFilterControl.cs | 26 +++---- osu.Game/Beatmaps/RealmBeatmapCollection.cs | 40 ----------- osu.Game/Collections/BeatmapCollection.cs | 32 +++++++-- .../Collections/CollectionFilterDropdown.cs | 70 +++++++++++-------- .../Collections/CollectionFilterMenuItem.cs | 17 ++--- .../Collections/CollectionToggleMenuItem.cs | 2 +- .../Collections/DeleteCollectionDialog.cs | 5 +- .../Collections/DrawableCollectionList.cs | 21 +++--- .../Collections/DrawableCollectionListItem.cs | 45 ++++++------ osu.Game/Database/LegacyCollectionImporter.cs | 12 ++-- osu.Game/Overlays/Music/Playlist.cs | 2 +- .../Maintenance/CollectionsSettings.cs | 4 +- .../OnlinePlay/DrawableRoomPlaylistItem.cs | 2 +- .../Select/Carousel/CarouselBeatmap.cs | 2 +- .../Carousel/DrawableCarouselBeatmap.cs | 2 +- .../Carousel/DrawableCarouselBeatmapSet.cs | 4 +- 18 files changed, 158 insertions(+), 180 deletions(-) delete mode 100644 osu.Game/Beatmaps/RealmBeatmapCollection.cs diff --git a/osu.Game.Tests/Collections/IO/ImportCollectionsTest.cs b/osu.Game.Tests/Collections/IO/ImportCollectionsTest.cs index 32503cdb12..604b87dc4c 100644 --- a/osu.Game.Tests/Collections/IO/ImportCollectionsTest.cs +++ b/osu.Game.Tests/Collections/IO/ImportCollectionsTest.cs @@ -12,7 +12,7 @@ using NUnit.Framework; using osu.Framework.Extensions; using osu.Framework.Platform; using osu.Framework.Testing; -using osu.Game.Beatmaps; +using osu.Game.Collections; using osu.Game.Database; using osu.Game.Tests.Resources; @@ -34,7 +34,7 @@ namespace osu.Game.Tests.Collections.IO osu.Realm.Run(realm => { - var collections = realm.All().ToList(); + var collections = realm.All().ToList(); Assert.That(collections.Count, Is.Zero); }); } @@ -58,7 +58,7 @@ namespace osu.Game.Tests.Collections.IO osu.Realm.Run(realm => { - var collections = realm.All().ToList(); + var collections = realm.All().ToList(); Assert.That(collections.Count, Is.EqualTo(2)); // Even with no beatmaps imported, collections are tracking the hashes and will continue to. @@ -93,7 +93,7 @@ namespace osu.Game.Tests.Collections.IO osu.Realm.Run(realm => { - var collections = realm.All().ToList(); + var collections = realm.All().ToList(); Assert.That(collections.Count, Is.EqualTo(2)); @@ -141,7 +141,7 @@ namespace osu.Game.Tests.Collections.IO Assert.That(exceptionThrown, Is.False); osu.Realm.Run(realm => { - var collections = realm.All().ToList(); + var collections = realm.All().ToList(); Assert.That(collections.Count, Is.EqualTo(0)); }); } @@ -171,7 +171,7 @@ namespace osu.Game.Tests.Collections.IO // ReSharper disable once MethodHasAsyncOverload osu.Realm.Write(realm => { - var collections = realm.All().ToList(); + var collections = realm.All().ToList(); // Move first beatmap from second collection into the first. collections[0].BeatmapMD5Hashes.Add(collections[1].BeatmapMD5Hashes[0]); @@ -196,7 +196,7 @@ namespace osu.Game.Tests.Collections.IO osu.Realm.Run(realm => { - var collections = realm.All().ToList(); + var collections = realm.All().ToList(); Assert.That(collections.Count, Is.EqualTo(2)); Assert.That(collections[0].Name, Is.EqualTo("First")); diff --git a/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs b/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs index 21d2b0328b..8de38eb4e7 100644 --- a/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs +++ b/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs @@ -51,7 +51,7 @@ namespace osu.Game.Tests.Visual.Collections [SetUp] public void SetUp() => Schedule(() => { - Realm.Write(r => r.RemoveAll()); + Realm.Write(r => r.RemoveAll()); Child = dialog = new ManageCollectionsDialog(); }); @@ -77,11 +77,11 @@ namespace osu.Game.Tests.Visual.Collections [Test] public void TestAddCollectionExternal() { - AddStep("add collection", () => Realm.Write(r => r.Add(new RealmBeatmapCollection(name: "First collection")))); + AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "First collection")))); assertCollectionCount(1); assertCollectionName(0, "First collection"); - AddStep("add another collection", () => Realm.Write(r => r.Add(new RealmBeatmapCollection(name: "Second collection")))); + AddStep("add another collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "Second collection")))); assertCollectionCount(2); assertCollectionName(1, "Second collection"); } @@ -110,7 +110,7 @@ namespace osu.Game.Tests.Visual.Collections }); // Done directly via the collection since InputManager methods cannot add text to textbox... - AddStep("change collection name", () => placeholderItem.Model.Name = "a"); + AddStep("change collection name", () => placeholderItem.Model.PerformWrite(c => c.Name = "a")); assertCollectionCount(1); AddAssert("collection now exists", () => placeholderItem.Model.IsManaged); @@ -120,7 +120,7 @@ namespace osu.Game.Tests.Visual.Collections [Test] public void TestRemoveCollectionExternal() { - RealmBeatmapCollection first = null!; + BeatmapCollection first = null!; AddStep("add two collections", () => { @@ -128,13 +128,13 @@ namespace osu.Game.Tests.Visual.Collections { r.Add(new[] { - first = new RealmBeatmapCollection(name: "1"), - new RealmBeatmapCollection(name: "2"), + first = new BeatmapCollection(name: "1"), + new BeatmapCollection(name: "2"), }); }); }); - AddStep("change first collection name", () => Realm.Write(r => r.Remove(first))); + AddStep("remove first collection", () => Realm.Write(r => r.Remove(first))); assertCollectionCount(1); assertCollectionName(0, "2"); } @@ -154,8 +154,8 @@ namespace osu.Game.Tests.Visual.Collections }); AddStep("add two collections with same name", () => Realm.Write(r => r.Add(new[] { - new RealmBeatmapCollection(name: "1"), - new RealmBeatmapCollection(name: "1") + new BeatmapCollection(name: "1"), + new BeatmapCollection(name: "1") { BeatmapMD5Hashes = { beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0].MD5Hash } }, @@ -167,8 +167,8 @@ namespace osu.Game.Tests.Visual.Collections { AddStep("add two collections", () => Realm.Write(r => r.Add(new[] { - new RealmBeatmapCollection(name: "1"), - new RealmBeatmapCollection(name: "2") + new BeatmapCollection(name: "1"), + new BeatmapCollection(name: "2") { BeatmapMD5Hashes = { beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0].MD5Hash } }, @@ -207,7 +207,7 @@ namespace osu.Game.Tests.Visual.Collections { AddStep("add collection", () => Realm.Write(r => r.Add(new[] { - new RealmBeatmapCollection(name: "1") + new BeatmapCollection(name: "1") { BeatmapMD5Hashes = { beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0].MD5Hash } }, @@ -234,7 +234,7 @@ namespace osu.Game.Tests.Visual.Collections [Test] public void TestCollectionRenamedExternal() { - RealmBeatmapCollection first = null!; + BeatmapCollection first = null!; AddStep("add two collections", () => { @@ -242,8 +242,8 @@ namespace osu.Game.Tests.Visual.Collections { r.Add(new[] { - first = new RealmBeatmapCollection(name: "1"), - new RealmBeatmapCollection(name: "2"), + first = new BeatmapCollection(name: "1"), + new BeatmapCollection(name: "2"), }); }); }); @@ -256,7 +256,7 @@ namespace osu.Game.Tests.Visual.Collections [Test] public void TestCollectionRenamedOnTextChange() { - RealmBeatmapCollection first = null!; + BeatmapCollection first = null!; AddStep("add two collections", () => { @@ -264,8 +264,8 @@ namespace osu.Game.Tests.Visual.Collections { r.Add(new[] { - first = new RealmBeatmapCollection(name: "1"), - new RealmBeatmapCollection(name: "2"), + first = new BeatmapCollection(name: "1"), + new BeatmapCollection(name: "2"), }); }); }); diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs index e4d69334a3..2a4613c37b 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs @@ -48,7 +48,7 @@ namespace osu.Game.Tests.Visual.SongSelect [SetUp] public void SetUp() => Schedule(() => { - Realm.Write(r => r.RemoveAll()); + Realm.Write(r => r.RemoveAll()); Child = control = new FilterControl { @@ -69,8 +69,8 @@ namespace osu.Game.Tests.Visual.SongSelect [Test] public void TestCollectionAddedToDropdown() { - AddStep("add collection", () => Realm.Write(r => r.Add(new RealmBeatmapCollection(name: "1")))); - AddStep("add collection", () => Realm.Write(r => r.Add(new RealmBeatmapCollection(name: "2")))); + AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "1")))); + AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "2")))); assertCollectionDropdownContains("1"); assertCollectionDropdownContains("2"); } @@ -78,10 +78,10 @@ namespace osu.Game.Tests.Visual.SongSelect [Test] public void TestCollectionRemovedFromDropdown() { - var first = new RealmBeatmapCollection(name: "1"); + var first = new BeatmapCollection(name: "1"); AddStep("add collection", () => Realm.Write(r => r.Add(first))); - AddStep("add collection", () => Realm.Write(r => r.Add(new RealmBeatmapCollection(name: "2")))); + AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "2")))); AddStep("remove collection", () => Realm.Write(r => r.Remove(first))); assertCollectionDropdownContains("1", false); @@ -91,7 +91,7 @@ namespace osu.Game.Tests.Visual.SongSelect [Test] public void TestCollectionRenamed() { - AddStep("add collection", () => Realm.Write(r => r.Add(new RealmBeatmapCollection(name: "1")))); + AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "1")))); AddStep("select collection", () => { var dropdown = control.ChildrenOfType().Single(); @@ -118,7 +118,7 @@ namespace osu.Game.Tests.Visual.SongSelect public void TestCollectionFilterHasAddButton() { addExpandHeaderStep(); - AddStep("add collection", () => Realm.Write(r => r.Add(new RealmBeatmapCollection(name: "1")))); + AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "1")))); AddStep("hover collection", () => InputManager.MoveMouseTo(getAddOrRemoveButton(1))); AddAssert("collection has add button", () => getAddOrRemoveButton(1).IsPresent); } @@ -128,7 +128,7 @@ namespace osu.Game.Tests.Visual.SongSelect { addExpandHeaderStep(); - AddStep("add collection", () => Realm.Write(r => r.Add(new RealmBeatmapCollection(name: "1")))); + AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "1")))); AddStep("select available beatmap", () => Beatmap.Value = beatmapManager.GetWorkingBeatmap(beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0])); AddAssert("button enabled", () => getAddOrRemoveButton(1).Enabled.Value); @@ -144,7 +144,7 @@ namespace osu.Game.Tests.Visual.SongSelect AddStep("select available beatmap", () => Beatmap.Value = beatmapManager.GetWorkingBeatmap(beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0])); - AddStep("add collection", () => Realm.Write(r => r.Add(new RealmBeatmapCollection(name: "1")))); + AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "1")))); AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusSquare)); AddStep("add beatmap to collection", () => getFirstCollection().BeatmapMD5Hashes.Add(Beatmap.Value.BeatmapInfo.MD5Hash)); @@ -161,7 +161,7 @@ namespace osu.Game.Tests.Visual.SongSelect AddStep("select available beatmap", () => Beatmap.Value = beatmapManager.GetWorkingBeatmap(beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0])); - AddStep("add collection", () => Realm.Write(r => r.Add(new RealmBeatmapCollection(name: "1")))); + AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "1")))); AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusSquare)); addClickAddOrRemoveButtonStep(1); @@ -178,7 +178,7 @@ namespace osu.Game.Tests.Visual.SongSelect { addExpandHeaderStep(); - AddStep("add collection", () => Realm.Write(r => r.Add(new RealmBeatmapCollection(name: "1")))); + AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "1")))); AddStep("select collection", () => { InputManager.MoveMouseTo(getCollectionDropdownItems().ElementAt(1)); @@ -193,10 +193,10 @@ namespace osu.Game.Tests.Visual.SongSelect InputManager.Click(MouseButton.Left); }); - AddAssert("collection filter still selected", () => control.CreateCriteria().Collection?.Name.Value == "1"); + AddAssert("collection filter still selected", () => control.CreateCriteria().Collection?.Name == "1"); } - private RealmBeatmapCollection getFirstCollection() => Realm.Run(r => r.All().First()); + private BeatmapCollection getFirstCollection() => Realm.Run(r => r.All().First()); private void assertCollectionHeaderDisplays(string collectionName, bool shouldDisplay = true) => AddAssert($"collection dropdown header displays '{collectionName}'", diff --git a/osu.Game/Beatmaps/RealmBeatmapCollection.cs b/osu.Game/Beatmaps/RealmBeatmapCollection.cs deleted file mode 100644 index 22ba9d5789..0000000000 --- a/osu.Game/Beatmaps/RealmBeatmapCollection.cs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using System; -using System.Collections.Generic; -using JetBrains.Annotations; -using osu.Game.Database; -using Realms; - -namespace osu.Game.Beatmaps -{ - public class RealmBeatmapCollection : RealmObject, IHasGuidPrimaryKey - { - [PrimaryKey] - public Guid ID { get; } - - public string Name { get; set; } = string.Empty; - - public IList BeatmapMD5Hashes { get; } = null!; - - /// - /// The date when this collection was last modified. - /// - public DateTimeOffset LastModified { get; set; } - - public RealmBeatmapCollection(string? name = null, IList? beatmapMD5Hashes = null) - { - ID = Guid.NewGuid(); - Name = name ?? string.Empty; - BeatmapMD5Hashes = beatmapMD5Hashes ?? new List(); - - LastModified = DateTimeOffset.UtcNow; - } - - [UsedImplicitly] - private RealmBeatmapCollection() - { - } - } -} diff --git a/osu.Game/Collections/BeatmapCollection.cs b/osu.Game/Collections/BeatmapCollection.cs index abfd0e6dd0..2ffe17d9e6 100644 --- a/osu.Game/Collections/BeatmapCollection.cs +++ b/osu.Game/Collections/BeatmapCollection.cs @@ -1,32 +1,50 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; -using osu.Framework.Bindables; +using System.Collections.Generic; +using JetBrains.Annotations; using osu.Game.Beatmaps; +using osu.Game.Database; +using Realms; namespace osu.Game.Collections { /// /// A collection of beatmaps grouped by a name. /// - public class BeatmapCollection + public class BeatmapCollection : RealmObject, IHasGuidPrimaryKey { + [PrimaryKey] + public Guid ID { get; set; } + /// /// The collection's name. /// - public readonly Bindable Name = new Bindable(); + public string Name { get; set; } = string.Empty; /// /// The es of beatmaps contained by the collection. /// - public readonly BindableList BeatmapHashes = new BindableList(); + public IList BeatmapMD5Hashes { get; } = null!; /// /// The date when this collection was last modified. /// - public DateTimeOffset LastModifyDate { get; private set; } = DateTimeOffset.UtcNow; + public DateTimeOffset LastModified { get; set; } + + public BeatmapCollection(string? name = null, IList? beatmapMD5Hashes = null) + { + ID = Guid.NewGuid(); + Name = name ?? string.Empty; + BeatmapMD5Hashes = beatmapMD5Hashes ?? new List(); + + LastModified = DateTimeOffset.UtcNow; + } + + [UsedImplicitly] + private BeatmapCollection() + { + } } } diff --git a/osu.Game/Collections/CollectionFilterDropdown.cs b/osu.Game/Collections/CollectionFilterDropdown.cs index ed2c0c7cfb..1315cebc8b 100644 --- a/osu.Game/Collections/CollectionFilterDropdown.cs +++ b/osu.Game/Collections/CollectionFilterDropdown.cs @@ -1,12 +1,10 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - +using System; using System.Collections.Specialized; using System.Diagnostics; using System.Linq; -using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -15,6 +13,7 @@ using osu.Framework.Graphics.UserInterface; using osu.Framework.Input.Events; using osu.Framework.Localisation; using osu.Game.Beatmaps; +using osu.Game.Database; using osu.Game.Graphics.Containers; using osu.Game.Graphics.UserInterface; using osuTK; @@ -43,8 +42,8 @@ namespace osu.Game.Collections private readonly IBindableList beatmaps = new BindableList(); private readonly BindableList filters = new BindableList(); - [Resolved(CanBeNull = true)] - private ManageCollectionsDialog manageCollectionsDialog { get; set; } + [Resolved] + private ManageCollectionsDialog? manageCollectionsDialog { get; set; } public CollectionFilterDropdown() { @@ -81,7 +80,7 @@ namespace osu.Game.Collections if (ShowManageCollectionsItem) filters.Add(new ManageCollectionsFilterMenuItem()); - Current.Value = filters.SingleOrDefault(f => f.Collection != null && f.Collection == selectedItem) ?? filters[0]; + Current.Value = filters.SingleOrDefault(f => f.Collection != null && f.Collection.ID == selectedItem?.ID) ?? filters[0]; } /// @@ -92,11 +91,12 @@ namespace osu.Game.Collections // Binding the beatmaps will trigger a collection change event, which results in an infinite-loop. This is rebound later, when it's safe to do so. beatmaps.CollectionChanged -= filterBeatmapsChanged; - if (filter.OldValue?.Collection != null) - beatmaps.UnbindFrom(filter.OldValue.Collection.BeatmapHashes); - - if (filter.NewValue?.Collection != null) - beatmaps.BindTo(filter.NewValue.Collection.BeatmapHashes); + // TODO: binding with realm + // if (filter.OldValue?.Collection != null) + // beatmaps.UnbindFrom(filter.OldValue.Collection.BeatmapMD5Hashes); + // + // if (filter.NewValue?.Collection != null) + // beatmaps.BindTo(filter.NewValue.Collection.BeatmapMD5Hashes); beatmaps.CollectionChanged += filterBeatmapsChanged; @@ -187,26 +187,24 @@ namespace osu.Game.Collections protected class CollectionDropdownMenuItem : OsuDropdownMenu.DrawableOsuDropdownMenuItem { - [NotNull] protected new CollectionFilterMenuItem Item => ((DropdownMenuItem)base.Item).Value; [Resolved] - private IBindable beatmap { get; set; } + private IBindable beatmap { get; set; } = null!; - [CanBeNull] - private readonly BindableList collectionBeatmaps; - - [NotNull] private readonly Bindable collectionName; - private IconButton addOrRemoveButton; - private Content content; + private IconButton addOrRemoveButton = null!; + private Content content = null!; private bool beatmapInCollection; + private IDisposable? realmSubscription; + + private BeatmapCollection? collection => Item.Collection; + public CollectionDropdownMenuItem(MenuItem item) : base(item) { - collectionBeatmaps = Item.Collection?.BeatmapHashes.GetBoundCopy(); collectionName = Item.CollectionName.GetBoundCopy(); } @@ -223,14 +221,17 @@ namespace osu.Game.Collections }); } + [Resolved] + private RealmAccess realm { get; set; } = null!; + protected override void LoadComplete() { base.LoadComplete(); - if (collectionBeatmaps != null) + if (Item.Collection != null) { - collectionBeatmaps.CollectionChanged += (_, _) => collectionChanged(); - beatmap.BindValueChanged(_ => collectionChanged(), true); + realmSubscription = realm.SubscribeToPropertyChanged(r => r.Find(Item.Collection.ID), c => c.BeatmapMD5Hashes, _ => hashesChanged()); + beatmap.BindValueChanged(_ => hashesChanged(), true); } // Although the DrawableMenuItem binds to value changes of the item's text, the item is an internal implementation detail of Dropdown that has no knowledge @@ -252,11 +253,11 @@ namespace osu.Game.Collections base.OnHoverLost(e); } - private void collectionChanged() + private void hashesChanged() { - Debug.Assert(collectionBeatmaps != null); + Debug.Assert(collection != null); - beatmapInCollection = collectionBeatmaps.Contains(beatmap.Value.BeatmapInfo.MD5Hash); + beatmapInCollection = collection.BeatmapMD5Hashes.Contains(beatmap.Value.BeatmapInfo.MD5Hash); addOrRemoveButton.Enabled.Value = !beatmap.IsDefault; addOrRemoveButton.Icon = beatmapInCollection ? FontAwesome.Solid.MinusSquare : FontAwesome.Solid.PlusSquare; @@ -273,7 +274,7 @@ namespace osu.Game.Collections private void updateButtonVisibility() { - if (collectionBeatmaps == null) + if (collection == null) addOrRemoveButton.Alpha = 0; else addOrRemoveButton.Alpha = IsHovered || IsPreSelected || beatmapInCollection ? 1 : 0; @@ -281,13 +282,22 @@ namespace osu.Game.Collections private void addOrRemove() { - Debug.Assert(collectionBeatmaps != null); + Debug.Assert(collection != null); - if (!collectionBeatmaps.Remove(beatmap.Value.BeatmapInfo.MD5Hash)) - collectionBeatmaps.Add(beatmap.Value.BeatmapInfo.MD5Hash); + realm.Write(r => + { + if (!collection.BeatmapMD5Hashes.Remove(beatmap.Value.BeatmapInfo.MD5Hash)) + collection.BeatmapMD5Hashes.Add(beatmap.Value.BeatmapInfo.MD5Hash); + }); } protected override Drawable CreateContent() => content = (Content)base.CreateContent(); + + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + realmSubscription?.Dispose(); + } } } } diff --git a/osu.Game/Collections/CollectionFilterMenuItem.cs b/osu.Game/Collections/CollectionFilterMenuItem.cs index 031f05c0b4..4c132ba7b7 100644 --- a/osu.Game/Collections/CollectionFilterMenuItem.cs +++ b/osu.Game/Collections/CollectionFilterMenuItem.cs @@ -1,10 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; -using JetBrains.Annotations; using osu.Framework.Bindables; namespace osu.Game.Collections @@ -18,26 +15,26 @@ namespace osu.Game.Collections /// The collection to filter beatmaps from. /// May be null to not filter by collection (include all beatmaps). /// - [CanBeNull] - public readonly BeatmapCollection Collection; + public readonly BeatmapCollection? Collection; /// /// The name of the collection. /// - [NotNull] public readonly Bindable CollectionName; /// /// Creates a new . /// /// The collection to filter beatmaps from. - public CollectionFilterMenuItem([CanBeNull] BeatmapCollection collection) + public CollectionFilterMenuItem(BeatmapCollection? collection) { Collection = collection; - CollectionName = Collection?.Name.GetBoundCopy() ?? new Bindable("All beatmaps"); + CollectionName = new Bindable(collection?.Name ?? "All beatmaps"); } - public bool Equals(CollectionFilterMenuItem other) + // TODO: track name changes i guess? + + public bool Equals(CollectionFilterMenuItem? other) { if (other == null) return false; @@ -45,7 +42,7 @@ namespace osu.Game.Collections // collections may have the same name, so compare first on reference equality. // this relies on the assumption that only one instance of the BeatmapCollection exists game-wide, managed by CollectionManager. if (Collection != null) - return Collection == other.Collection; + return Collection.ID == other.Collection?.ID; // fallback to name-based comparison. // this is required for special dropdown items which don't have a collection (all beatmaps / manage collections items below). diff --git a/osu.Game/Collections/CollectionToggleMenuItem.cs b/osu.Game/Collections/CollectionToggleMenuItem.cs index 632249913d..8c0e3c587b 100644 --- a/osu.Game/Collections/CollectionToggleMenuItem.cs +++ b/osu.Game/Collections/CollectionToggleMenuItem.cs @@ -8,7 +8,7 @@ namespace osu.Game.Collections { public class CollectionToggleMenuItem : ToggleMenuItem { - public CollectionToggleMenuItem(RealmBeatmapCollection collection, IBeatmapInfo beatmap) + public CollectionToggleMenuItem(BeatmapCollection collection, IBeatmapInfo beatmap) : base(collection.Name, MenuItemType.Standard, state => { if (state) diff --git a/osu.Game/Collections/DeleteCollectionDialog.cs b/osu.Game/Collections/DeleteCollectionDialog.cs index 33c2174623..7594978870 100644 --- a/osu.Game/Collections/DeleteCollectionDialog.cs +++ b/osu.Game/Collections/DeleteCollectionDialog.cs @@ -1,19 +1,16 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using Humanizer; using osu.Framework.Graphics.Sprites; -using osu.Game.Beatmaps; using osu.Game.Overlays.Dialog; namespace osu.Game.Collections { public class DeleteCollectionDialog : PopupDialog { - public DeleteCollectionDialog(RealmBeatmapCollection collection, Action deleteAction) + public DeleteCollectionDialog(BeatmapCollection collection, Action deleteAction) { HeaderText = "Confirm deletion of"; BodyText = $"{collection.Name} ({"beatmap".ToQuantity(collection.BeatmapMD5Hashes.Count)})"; diff --git a/osu.Game/Collections/DrawableCollectionList.cs b/osu.Game/Collections/DrawableCollectionList.cs index 63f04641f4..f376d18224 100644 --- a/osu.Game/Collections/DrawableCollectionList.cs +++ b/osu.Game/Collections/DrawableCollectionList.cs @@ -1,35 +1,33 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - +using System.Diagnostics; using System.Linq; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Game.Beatmaps; using osu.Game.Graphics.Containers; using osuTK; namespace osu.Game.Collections { /// - /// Visualises a list of s. + /// Visualises a list of s. /// - public class DrawableCollectionList : OsuRearrangeableListContainer + public class DrawableCollectionList : OsuRearrangeableListContainer { - private Scroll scroll; + private Scroll scroll = null!; protected override ScrollContainer CreateScrollContainer() => scroll = new Scroll(); - protected override FillFlowContainer> CreateListFillFlowContainer() => new Flow + protected override FillFlowContainer> CreateListFillFlowContainer() => new Flow { DragActive = { BindTarget = DragActive } }; // TODO: source from realm - protected override OsuRearrangeableListItem CreateOsuDrawable(RealmBeatmapCollection item) + protected override OsuRearrangeableListItem CreateOsuDrawable(BeatmapCollection item) { if (item.ID == scroll.PlaceholderItem.Model.ID) return scroll.ReplacePlaceholder(); @@ -49,7 +47,7 @@ namespace osu.Game.Collections /// /// The currently-displayed placeholder item. /// - public DrawableCollectionListItem PlaceholderItem { get; private set; } + public DrawableCollectionListItem PlaceholderItem { get; private set; } = null!; protected override Container Content => content; private readonly Container content; @@ -79,6 +77,7 @@ namespace osu.Game.Collections }); ReplacePlaceholder(); + Debug.Assert(PlaceholderItem != null); } protected override void Update() @@ -98,7 +97,7 @@ namespace osu.Game.Collections var previous = PlaceholderItem; placeholderContainer.Clear(false); - placeholderContainer.Add(PlaceholderItem = new DrawableCollectionListItem(new RealmBeatmapCollection(), false)); + placeholderContainer.Add(PlaceholderItem = new DrawableCollectionListItem(new BeatmapCollection(), false)); return previous; } @@ -107,7 +106,7 @@ namespace osu.Game.Collections /// /// The flow of . Disables layout easing unless a drag is in progress. /// - private class Flow : FillFlowContainer> + private class Flow : FillFlowContainer> { public readonly IBindable DragActive = new Bindable(); diff --git a/osu.Game/Collections/DrawableCollectionListItem.cs b/osu.Game/Collections/DrawableCollectionListItem.cs index a29b2ef81c..6093e69deb 100644 --- a/osu.Game/Collections/DrawableCollectionListItem.cs +++ b/osu.Game/Collections/DrawableCollectionListItem.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using osu.Framework.Allocation; using osu.Framework.Bindables; @@ -12,7 +10,6 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; using osu.Framework.Input.Events; -using osu.Game.Beatmaps; using osu.Game.Database; using osu.Game.Graphics; using osu.Game.Graphics.Containers; @@ -24,15 +21,15 @@ using osuTK.Graphics; namespace osu.Game.Collections { /// - /// Visualises a inside a . + /// Visualises a inside a . /// - public class DrawableCollectionListItem : OsuRearrangeableListItem + public class DrawableCollectionListItem : OsuRearrangeableListItem { private const float item_height = 35; private const float button_width = item_height * 0.75f; /// - /// Whether the currently exists inside realm. + /// Whether the currently exists inside realm. /// public IBindable IsCreated => isCreated; @@ -41,9 +38,9 @@ namespace osu.Game.Collections /// /// Creates a new . /// - /// The . + /// The . /// Whether currently exists inside realm. - public DrawableCollectionListItem(RealmBeatmapCollection item, bool isCreated) + public DrawableCollectionListItem(BeatmapCollection item, bool isCreated) : base(item) { this.isCreated.Value = isCreated; @@ -63,12 +60,15 @@ namespace osu.Game.Collections { public readonly Bindable IsCreated = new Bindable(); - private readonly RealmBeatmapCollection collection; + private readonly BeatmapCollection collection; - private Container textBoxPaddingContainer; - private ItemTextBox textBox; + private Container textBoxPaddingContainer = null!; + private ItemTextBox textBox = null!; - public ItemContent(RealmBeatmapCollection collection) + [Resolved] + private RealmAccess realm { get; set; } = null!; + + public ItemContent(BeatmapCollection collection) { this.collection = collection; @@ -107,9 +107,6 @@ namespace osu.Game.Collections }; } - [Resolved] - private RealmAccess realm { get; set; } - protected override void LoadComplete() { base.LoadComplete(); @@ -156,20 +153,20 @@ namespace osu.Game.Collections { public readonly IBindable IsCreated = new Bindable(); - public Func IsTextBoxHovered; - - [Resolved(CanBeNull = true)] - private IDialogOverlay dialogOverlay { get; set; } + public Func IsTextBoxHovered = null!; [Resolved] - private RealmAccess realmAccess { get; set; } + private IDialogOverlay? dialogOverlay { get; set; } - private readonly RealmBeatmapCollection collection; + [Resolved] + private RealmAccess realmAccess { get; set; } = null!; - private Drawable fadeContainer; - private Drawable background; + private readonly BeatmapCollection collection; - public DeleteButton(RealmBeatmapCollection collection) + private Drawable fadeContainer = null!; + private Drawable background = null!; + + public DeleteButton(BeatmapCollection collection) { this.collection = collection; RelativeSizeAxes = Axes.Y; diff --git a/osu.Game/Database/LegacyCollectionImporter.cs b/osu.Game/Database/LegacyCollectionImporter.cs index aa98c491b1..bd32b8c446 100644 --- a/osu.Game/Database/LegacyCollectionImporter.cs +++ b/osu.Game/Database/LegacyCollectionImporter.cs @@ -7,7 +7,7 @@ using System.IO; using System.Linq; using System.Threading.Tasks; using osu.Framework.Logging; -using osu.Game.Beatmaps; +using osu.Game.Collections; using osu.Game.IO; using osu.Game.IO.Legacy; using osu.Game.Overlays.Notifications; @@ -75,7 +75,7 @@ namespace osu.Game.Database notification.State = ProgressNotificationState.Completed; } - private Task importCollections(List newCollections) + private Task importCollections(List newCollections) { var tcs = new TaskCompletionSource(); @@ -85,7 +85,7 @@ namespace osu.Game.Database { foreach (var collection in newCollections) { - var existing = r.All().FirstOrDefault(c => c.Name == collection.Name); + var existing = r.All().FirstOrDefault(c => c.Name == collection.Name); if (existing != null) { @@ -111,7 +111,7 @@ namespace osu.Game.Database return tcs.Task; } - private List readCollections(Stream stream, ProgressNotification? notification = null) + private List readCollections(Stream stream, ProgressNotification? notification = null) { if (notification != null) { @@ -119,7 +119,7 @@ namespace osu.Game.Database notification.Progress = 0; } - var result = new List(); + var result = new List(); try { @@ -135,7 +135,7 @@ namespace osu.Game.Database if (notification?.CancellationToken.IsCancellationRequested == true) return result; - var collection = new RealmBeatmapCollection(sr.ReadString()); + var collection = new BeatmapCollection(sr.ReadString()); int mapCount = sr.ReadInt32(); for (int j = 0; j < mapCount; j++) diff --git a/osu.Game/Overlays/Music/Playlist.cs b/osu.Game/Overlays/Music/Playlist.cs index 954c4de493..19b1b3f84e 100644 --- a/osu.Game/Overlays/Music/Playlist.cs +++ b/osu.Game/Overlays/Music/Playlist.cs @@ -38,7 +38,7 @@ namespace osu.Game.Overlays.Music else { item.InSelectedCollection = item.Model.Value.Beatmaps.Select(b => b.MD5Hash) - .Any(criteria.Collection.BeatmapHashes.Contains); + .Any(criteria.Collection.BeatmapMD5Hashes.Contains); } } diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/CollectionsSettings.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/CollectionsSettings.cs index 0b17ab9c6c..498859db46 100644 --- a/osu.Game/Overlays/Settings/Sections/Maintenance/CollectionsSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Maintenance/CollectionsSettings.cs @@ -3,7 +3,7 @@ using osu.Framework.Allocation; using osu.Framework.Localisation; -using osu.Game.Beatmaps; +using osu.Game.Collections; using osu.Game.Database; using osu.Game.Localisation; using osu.Game.Overlays.Notifications; @@ -50,7 +50,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance private void deleteAllCollections() { - realm.Write(r => r.RemoveAll()); + realm.Write(r => r.RemoveAll()); notificationOverlay.Post(new ProgressCompletionNotification { Text = "Deleted all collections!" }); } } diff --git a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs index b17c4934cd..0826c4144b 100644 --- a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs +++ b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs @@ -499,7 +499,7 @@ namespace osu.Game.Screens.OnlinePlay { if (beatmaps.QueryBeatmap(b => b.OnlineID == beatmap.OnlineID) is BeatmapInfo local && !local.BeatmapSet.AsNonNull().DeletePending) { - var collectionItems = realm.Realm.All().Select(c => new CollectionToggleMenuItem(c, beatmap)).Cast().ToList(); + var collectionItems = realm.Realm.All().Select(c => new CollectionToggleMenuItem(c, beatmap)).Cast().ToList(); if (manageCollectionsDialog != null) collectionItems.Add(new OsuMenuItem("Manage...", MenuItemType.Standard, manageCollectionsDialog.Show)); diff --git a/osu.Game/Screens/Select/Carousel/CarouselBeatmap.cs b/osu.Game/Screens/Select/Carousel/CarouselBeatmap.cs index 81734745c4..9267434a66 100644 --- a/osu.Game/Screens/Select/Carousel/CarouselBeatmap.cs +++ b/osu.Game/Screens/Select/Carousel/CarouselBeatmap.cs @@ -76,7 +76,7 @@ namespace osu.Game.Screens.Select.Carousel } if (match) - match &= criteria.Collection?.BeatmapHashes.Contains(BeatmapInfo.MD5Hash) ?? true; + match &= criteria.Collection?.BeatmapMD5Hashes.Contains(BeatmapInfo.MD5Hash) ?? true; if (match && criteria.RulesetCriteria != null) match &= criteria.RulesetCriteria.Matches(BeatmapInfo); diff --git a/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs b/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs index bfc93b34e2..a1c433b440 100644 --- a/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs +++ b/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs @@ -238,7 +238,7 @@ namespace osu.Game.Screens.Select.Carousel if (beatmapInfo.OnlineID > 0 && beatmapOverlay != null) items.Add(new OsuMenuItem("Details...", MenuItemType.Standard, () => beatmapOverlay.FetchAndShowBeatmap(beatmapInfo.OnlineID))); - var collectionItems = realm.Realm.All().Select(c => new CollectionToggleMenuItem(c, beatmapInfo)).Cast().ToList(); + var collectionItems = realm.Realm.All().AsEnumerable().Select(c => new CollectionToggleMenuItem(c, beatmapInfo)).Cast().ToList(); if (manageCollectionsDialog != null) collectionItems.Add(new OsuMenuItem("Manage...", MenuItemType.Standard, manageCollectionsDialog.Show)); diff --git a/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmapSet.cs b/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmapSet.cs index 3726d955bd..75c9daf1b1 100644 --- a/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmapSet.cs +++ b/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmapSet.cs @@ -224,7 +224,7 @@ namespace osu.Game.Screens.Select.Carousel if (beatmapSet.OnlineID > 0 && viewDetails != null) items.Add(new OsuMenuItem("Details...", MenuItemType.Standard, () => viewDetails(beatmapSet.OnlineID))); - var collectionItems = realm.Realm.All().AsEnumerable().Select(createCollectionMenuItem).ToList(); + var collectionItems = realm.Realm.All().AsEnumerable().Select(createCollectionMenuItem).ToList(); if (manageCollectionsDialog != null) collectionItems.Add(new OsuMenuItem("Manage...", MenuItemType.Standard, manageCollectionsDialog.Show)); @@ -239,7 +239,7 @@ namespace osu.Game.Screens.Select.Carousel } } - private MenuItem createCollectionMenuItem(RealmBeatmapCollection collection) + private MenuItem createCollectionMenuItem(BeatmapCollection collection) { Debug.Assert(beatmapSet != null); From 438067a18b4748501c49a57db0201212eb22829c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 27 Jul 2022 17:17:43 +0900 Subject: [PATCH 107/278] Convert realm data propagation to more correctly use `Live` wip --- .../SongSelect/TestSceneFilterControl.cs | 8 +++--- .../Collections/CollectionFilterDropdown.cs | 13 ++++----- .../Collections/CollectionFilterMenuItem.cs | 7 ++--- .../Collections/CollectionToggleMenuItem.cs | 18 ++++++++----- osu.Game/Overlays/Music/FilterCriteria.cs | 3 ++- osu.Game/Overlays/Music/Playlist.cs | 6 +++-- .../OnlinePlay/DrawableRoomPlaylistItem.cs | 2 +- .../Select/Carousel/CarouselBeatmap.cs | 2 +- .../Carousel/DrawableCarouselBeatmap.cs | 2 +- .../Carousel/DrawableCarouselBeatmapSet.cs | 27 +++++++++++-------- osu.Game/Screens/Select/FilterControl.cs | 2 +- osu.Game/Screens/Select/FilterCriteria.cs | 4 +-- 12 files changed, 54 insertions(+), 40 deletions(-) diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs index 2a4613c37b..aaaa0aec95 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs @@ -147,10 +147,10 @@ namespace osu.Game.Tests.Visual.SongSelect AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "1")))); AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusSquare)); - AddStep("add beatmap to collection", () => getFirstCollection().BeatmapMD5Hashes.Add(Beatmap.Value.BeatmapInfo.MD5Hash)); + AddStep("add beatmap to collection", () => Realm.Write(r => getFirstCollection().BeatmapMD5Hashes.Add(Beatmap.Value.BeatmapInfo.MD5Hash))); AddAssert("button is minus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.MinusSquare)); - AddStep("remove beatmap from collection", () => getFirstCollection().BeatmapMD5Hashes.Clear()); + AddStep("remove beatmap from collection", () => Realm.Write(r => getFirstCollection().BeatmapMD5Hashes.Clear())); AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusSquare)); } @@ -178,7 +178,7 @@ namespace osu.Game.Tests.Visual.SongSelect { addExpandHeaderStep(); - AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "1")))); + AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "1", new List { "abc" })))); AddStep("select collection", () => { InputManager.MoveMouseTo(getCollectionDropdownItems().ElementAt(1)); @@ -193,7 +193,7 @@ namespace osu.Game.Tests.Visual.SongSelect InputManager.Click(MouseButton.Left); }); - AddAssert("collection filter still selected", () => control.CreateCriteria().Collection?.Name == "1"); + AddAssert("collection filter still selected", () => control.CreateCriteria().CollectionBeatmapMD5Hashes.Any()); } private BeatmapCollection getFirstCollection() => Realm.Run(r => r.All().First()); diff --git a/osu.Game/Collections/CollectionFilterDropdown.cs b/osu.Game/Collections/CollectionFilterDropdown.cs index 1315cebc8b..c04f617eb9 100644 --- a/osu.Game/Collections/CollectionFilterDropdown.cs +++ b/osu.Game/Collections/CollectionFilterDropdown.cs @@ -38,7 +38,7 @@ namespace osu.Game.Collections set => current.Current = value; } - private readonly IBindableList collections = new BindableList(); + private readonly IBindableList> collections = new BindableList>(); private readonly IBindableList beatmaps = new BindableList(); private readonly BindableList filters = new BindableList(); @@ -114,6 +114,7 @@ namespace osu.Game.Collections /// private void filterBeatmapsChanged(object sender, NotifyCollectionChangedEventArgs e) { + // TODO: fuck this shit right off // The filtered beatmaps have changed, without the filter having changed itself. So a change in filter must be notified. // Note that this does NOT propagate to bound bindables, so the FilterControl must bind directly to the value change event of this bindable. Current.TriggerChange(); @@ -200,7 +201,7 @@ namespace osu.Game.Collections private IDisposable? realmSubscription; - private BeatmapCollection? collection => Item.Collection; + private Live? collection => Item.Collection; public CollectionDropdownMenuItem(MenuItem item) : base(item) @@ -257,7 +258,7 @@ namespace osu.Game.Collections { Debug.Assert(collection != null); - beatmapInCollection = collection.BeatmapMD5Hashes.Contains(beatmap.Value.BeatmapInfo.MD5Hash); + beatmapInCollection = collection.PerformRead(c => c.BeatmapMD5Hashes.Contains(beatmap.Value.BeatmapInfo.MD5Hash)); addOrRemoveButton.Enabled.Value = !beatmap.IsDefault; addOrRemoveButton.Icon = beatmapInCollection ? FontAwesome.Solid.MinusSquare : FontAwesome.Solid.PlusSquare; @@ -284,10 +285,10 @@ namespace osu.Game.Collections { Debug.Assert(collection != null); - realm.Write(r => + collection.PerformWrite(c => { - if (!collection.BeatmapMD5Hashes.Remove(beatmap.Value.BeatmapInfo.MD5Hash)) - collection.BeatmapMD5Hashes.Add(beatmap.Value.BeatmapInfo.MD5Hash); + if (!c.BeatmapMD5Hashes.Remove(beatmap.Value.BeatmapInfo.MD5Hash)) + c.BeatmapMD5Hashes.Add(beatmap.Value.BeatmapInfo.MD5Hash); }); } diff --git a/osu.Game/Collections/CollectionFilterMenuItem.cs b/osu.Game/Collections/CollectionFilterMenuItem.cs index 4c132ba7b7..fd9e333915 100644 --- a/osu.Game/Collections/CollectionFilterMenuItem.cs +++ b/osu.Game/Collections/CollectionFilterMenuItem.cs @@ -3,6 +3,7 @@ using System; using osu.Framework.Bindables; +using osu.Game.Database; namespace osu.Game.Collections { @@ -15,7 +16,7 @@ namespace osu.Game.Collections /// The collection to filter beatmaps from. /// May be null to not filter by collection (include all beatmaps). /// - public readonly BeatmapCollection? Collection; + public readonly Live? Collection; /// /// The name of the collection. @@ -26,10 +27,10 @@ namespace osu.Game.Collections /// Creates a new . /// /// The collection to filter beatmaps from. - public CollectionFilterMenuItem(BeatmapCollection? collection) + public CollectionFilterMenuItem(Live? collection) { Collection = collection; - CollectionName = new Bindable(collection?.Name ?? "All beatmaps"); + CollectionName = new Bindable(collection?.PerformRead(c => c.Name) ?? "All beatmaps"); } // TODO: track name changes i guess? diff --git a/osu.Game/Collections/CollectionToggleMenuItem.cs b/osu.Game/Collections/CollectionToggleMenuItem.cs index 8c0e3c587b..5ad06a72c0 100644 --- a/osu.Game/Collections/CollectionToggleMenuItem.cs +++ b/osu.Game/Collections/CollectionToggleMenuItem.cs @@ -2,22 +2,26 @@ // See the LICENCE file in the repository root for full licence text. using osu.Game.Beatmaps; +using osu.Game.Database; using osu.Game.Graphics.UserInterface; namespace osu.Game.Collections { public class CollectionToggleMenuItem : ToggleMenuItem { - public CollectionToggleMenuItem(BeatmapCollection collection, IBeatmapInfo beatmap) - : base(collection.Name, MenuItemType.Standard, state => + public CollectionToggleMenuItem(Live collection, IBeatmapInfo beatmap) + : base(collection.PerformRead(c => c.Name), MenuItemType.Standard, state => { - if (state) - collection.BeatmapMD5Hashes.Add(beatmap.MD5Hash); - else - collection.BeatmapMD5Hashes.Remove(beatmap.MD5Hash); + collection.PerformWrite(c => + { + if (state) + c.BeatmapMD5Hashes.Add(beatmap.MD5Hash); + else + c.BeatmapMD5Hashes.Remove(beatmap.MD5Hash); + }); }) { - State.Value = collection.BeatmapMD5Hashes.Contains(beatmap.MD5Hash); + State.Value = collection.PerformRead(c => c.BeatmapMD5Hashes.Contains(beatmap.MD5Hash)); } } } diff --git a/osu.Game/Overlays/Music/FilterCriteria.cs b/osu.Game/Overlays/Music/FilterCriteria.cs index f435c4e6e4..ad491be845 100644 --- a/osu.Game/Overlays/Music/FilterCriteria.cs +++ b/osu.Game/Overlays/Music/FilterCriteria.cs @@ -5,6 +5,7 @@ using JetBrains.Annotations; using osu.Game.Collections; +using osu.Game.Database; namespace osu.Game.Overlays.Music { @@ -19,6 +20,6 @@ namespace osu.Game.Overlays.Music /// The collection to filter beatmaps from. /// [CanBeNull] - public BeatmapCollection Collection; + public Live Collection; } } diff --git a/osu.Game/Overlays/Music/Playlist.cs b/osu.Game/Overlays/Music/Playlist.cs index 19b1b3f84e..2bb0ff1085 100644 --- a/osu.Game/Overlays/Music/Playlist.cs +++ b/osu.Game/Overlays/Music/Playlist.cs @@ -31,14 +31,16 @@ namespace osu.Game.Overlays.Music { var items = (SearchContainer>>)ListContainer; + string[] currentCollectionHashes = criteria.Collection?.PerformRead(c => c.BeatmapMD5Hashes.ToArray()); + foreach (var item in items.OfType()) { - if (criteria.Collection == null) + if (currentCollectionHashes == null) item.InSelectedCollection = true; else { item.InSelectedCollection = item.Model.Value.Beatmaps.Select(b => b.MD5Hash) - .Any(criteria.Collection.BeatmapMD5Hashes.Contains); + .Any(currentCollectionHashes.Contains); } } diff --git a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs index 0826c4144b..492bb8ada5 100644 --- a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs +++ b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs @@ -499,7 +499,7 @@ namespace osu.Game.Screens.OnlinePlay { if (beatmaps.QueryBeatmap(b => b.OnlineID == beatmap.OnlineID) is BeatmapInfo local && !local.BeatmapSet.AsNonNull().DeletePending) { - var collectionItems = realm.Realm.All().Select(c => new CollectionToggleMenuItem(c, beatmap)).Cast().ToList(); + var collectionItems = realm.Realm.All().Select(c => new CollectionToggleMenuItem(c.ToLive(realm), beatmap)).Cast().ToList(); if (manageCollectionsDialog != null) collectionItems.Add(new OsuMenuItem("Manage...", MenuItemType.Standard, manageCollectionsDialog.Show)); diff --git a/osu.Game/Screens/Select/Carousel/CarouselBeatmap.cs b/osu.Game/Screens/Select/Carousel/CarouselBeatmap.cs index 9267434a66..5b17b412ae 100644 --- a/osu.Game/Screens/Select/Carousel/CarouselBeatmap.cs +++ b/osu.Game/Screens/Select/Carousel/CarouselBeatmap.cs @@ -76,7 +76,7 @@ namespace osu.Game.Screens.Select.Carousel } if (match) - match &= criteria.Collection?.BeatmapMD5Hashes.Contains(BeatmapInfo.MD5Hash) ?? true; + match &= criteria.CollectionBeatmapMD5Hashes?.Contains(BeatmapInfo.MD5Hash) ?? true; if (match && criteria.RulesetCriteria != null) match &= criteria.RulesetCriteria.Matches(BeatmapInfo); diff --git a/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs b/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs index a1c433b440..c3cb04680b 100644 --- a/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs +++ b/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs @@ -238,7 +238,7 @@ namespace osu.Game.Screens.Select.Carousel if (beatmapInfo.OnlineID > 0 && beatmapOverlay != null) items.Add(new OsuMenuItem("Details...", MenuItemType.Standard, () => beatmapOverlay.FetchAndShowBeatmap(beatmapInfo.OnlineID))); - var collectionItems = realm.Realm.All().AsEnumerable().Select(c => new CollectionToggleMenuItem(c, beatmapInfo)).Cast().ToList(); + var collectionItems = realm.Realm.All().AsEnumerable().Select(c => new CollectionToggleMenuItem(c.ToLive(realm), beatmapInfo)).Cast().ToList(); if (manageCollectionsDialog != null) collectionItems.Add(new OsuMenuItem("Manage...", MenuItemType.Standard, manageCollectionsDialog.Show)); diff --git a/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmapSet.cs b/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmapSet.cs index 75c9daf1b1..040f954bba 100644 --- a/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmapSet.cs +++ b/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmapSet.cs @@ -254,24 +254,29 @@ namespace osu.Game.Screens.Select.Carousel else state = TernaryState.False; + var liveCollection = collection.ToLive(realm); + return new TernaryStateToggleMenuItem(collection.Name, MenuItemType.Standard, s => { - foreach (var b in beatmapSet.Beatmaps) + liveCollection.PerformWrite(c => { - switch (s) + foreach (var b in beatmapSet.Beatmaps) { - case TernaryState.True: - if (collection.BeatmapMD5Hashes.Contains(b.MD5Hash)) - continue; + switch (s) + { + case TernaryState.True: + if (c.BeatmapMD5Hashes.Contains(b.MD5Hash)) + continue; - collection.BeatmapMD5Hashes.Add(b.MD5Hash); - break; + c.BeatmapMD5Hashes.Add(b.MD5Hash); + break; - case TernaryState.False: - collection.BeatmapMD5Hashes.Remove(b.MD5Hash); - break; + case TernaryState.False: + c.BeatmapMD5Hashes.Remove(b.MD5Hash); + break; + } } - } + }); }) { State = { Value = state } diff --git a/osu.Game/Screens/Select/FilterControl.cs b/osu.Game/Screens/Select/FilterControl.cs index d39862b65f..5f5344a338 100644 --- a/osu.Game/Screens/Select/FilterControl.cs +++ b/osu.Game/Screens/Select/FilterControl.cs @@ -49,7 +49,7 @@ namespace osu.Game.Screens.Select Sort = sortMode.Value, AllowConvertedBeatmaps = showConverted.Value, Ruleset = ruleset.Value, - Collection = collectionDropdown?.Current.Value?.Collection + CollectionBeatmapMD5Hashes = collectionDropdown?.Current.Value?.Collection?.PerformRead(c => c.BeatmapMD5Hashes) }; if (!minimumStars.IsDefault) diff --git a/osu.Game/Screens/Select/FilterCriteria.cs b/osu.Game/Screens/Select/FilterCriteria.cs index c7e6e8496a..320bfb1b45 100644 --- a/osu.Game/Screens/Select/FilterCriteria.cs +++ b/osu.Game/Screens/Select/FilterCriteria.cs @@ -68,10 +68,10 @@ namespace osu.Game.Screens.Select } /// - /// The collection to filter beatmaps from. + /// Hashes from the to filter to. /// [CanBeNull] - public BeatmapCollection Collection; + public IEnumerable CollectionBeatmapMD5Hashes { get; set; } [CanBeNull] public IRulesetFilterCriteria RulesetCriteria { get; set; } From 804bb33aedbc4f44a8aed6fc7c90d7528106b1df Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 27 Jul 2022 18:24:37 +0900 Subject: [PATCH 108/278] Hook up remaining data flows --- .../Collections/CollectionFilterDropdown.cs | 147 +++++------------- .../Collections/CollectionFilterMenuItem.cs | 21 +-- 2 files changed, 54 insertions(+), 114 deletions(-) diff --git a/osu.Game/Collections/CollectionFilterDropdown.cs b/osu.Game/Collections/CollectionFilterDropdown.cs index c04f617eb9..ec409df4d6 100644 --- a/osu.Game/Collections/CollectionFilterDropdown.cs +++ b/osu.Game/Collections/CollectionFilterDropdown.cs @@ -2,7 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Collections.Specialized; using System.Diagnostics; using System.Linq; using osu.Framework.Allocation; @@ -17,6 +16,7 @@ using osu.Game.Database; using osu.Game.Graphics.Containers; using osu.Game.Graphics.UserInterface; using osuTK; +using Realms; namespace osu.Game.Collections { @@ -38,13 +38,15 @@ namespace osu.Game.Collections set => current.Current = value; } - private readonly IBindableList> collections = new BindableList>(); private readonly IBindableList beatmaps = new BindableList(); private readonly BindableList filters = new BindableList(); [Resolved] private ManageCollectionsDialog? manageCollectionsDialog { get; set; } + [Resolved] + private RealmAccess realm { get; set; } = null!; + public CollectionFilterDropdown() { ItemSource = filters; @@ -55,51 +57,49 @@ namespace osu.Game.Collections { base.LoadComplete(); - // TODO: bind to realm data + realm.RegisterForNotifications(r => r.All(), collectionsChanged); // Dropdown has logic which triggers a change on the bindable with every change to the contained items. // This is not desirable here, as it leads to multiple filter operations running even though nothing has changed. // An extra bindable is enough to subvert this behaviour. base.Current = Current; - collections.BindCollectionChanged((_, _) => collectionsChanged(), true); - Current.BindValueChanged(filterChanged, true); + Current.BindValueChanged(currentChanged, true); } /// /// Occurs when a collection has been added or removed. /// - private void collectionsChanged() + private void collectionsChanged(IRealmCollection collections, ChangeSet? changes, Exception error) { var selectedItem = SelectedItem?.Value?.Collection; filters.Clear(); filters.Add(new AllBeatmapsCollectionFilterMenuItem()); - filters.AddRange(collections.Select(c => new CollectionFilterMenuItem(c))); + filters.AddRange(collections.Select(c => new CollectionFilterMenuItem(c.ToLive(realm)))); if (ShowManageCollectionsItem) filters.Add(new ManageCollectionsFilterMenuItem()); Current.Value = filters.SingleOrDefault(f => f.Collection != null && f.Collection.ID == selectedItem?.ID) ?? filters[0]; + + // Trigger a re-filter if the current item was in the changeset. + if (selectedItem != null && changes != null) + { + foreach (int index in changes.ModifiedIndices) + { + if (collections[index].ID == selectedItem.ID) + { + // The filtered beatmaps have changed, without the filter having changed itself. So a change in filter must be notified. + // Note that this does NOT propagate to bound bindables, so the FilterControl must bind directly to the value change event of this bindable. + Current.TriggerChange(); + } + } + } } - /// - /// Occurs when the selection has changed. - /// - private void filterChanged(ValueChangedEvent filter) + private void currentChanged(ValueChangedEvent filter) { - // Binding the beatmaps will trigger a collection change event, which results in an infinite-loop. This is rebound later, when it's safe to do so. - beatmaps.CollectionChanged -= filterBeatmapsChanged; - - // TODO: binding with realm - // if (filter.OldValue?.Collection != null) - // beatmaps.UnbindFrom(filter.OldValue.Collection.BeatmapMD5Hashes); - // - // if (filter.NewValue?.Collection != null) - // beatmaps.BindTo(filter.NewValue.Collection.BeatmapMD5Hashes); - - beatmaps.CollectionChanged += filterBeatmapsChanged; - // Never select the manage collection filter - rollback to the previous filter. // This is done after the above since it is important that bindable is unbound from OldValue, which is lost after forcing it back to the old value. if (filter.NewValue is ManageCollectionsFilterMenuItem) @@ -109,18 +109,7 @@ namespace osu.Game.Collections } } - /// - /// Occurs when the beatmaps contained by a have changed. - /// - private void filterBeatmapsChanged(object sender, NotifyCollectionChangedEventArgs e) - { - // TODO: fuck this shit right off - // The filtered beatmaps have changed, without the filter having changed itself. So a change in filter must be notified. - // Note that this does NOT propagate to bound bindables, so the FilterControl must bind directly to the value change event of this bindable. - Current.TriggerChange(); - } - - protected override LocalisableString GenerateItemText(CollectionFilterMenuItem item) => item.CollectionName.Value; + protected override LocalisableString GenerateItemText(CollectionFilterMenuItem item) => item.CollectionName; protected sealed override DropdownHeader CreateHeader() => CreateCollectionHeader().With(d => { @@ -136,13 +125,6 @@ namespace osu.Game.Collections public class CollectionDropdownHeader : OsuDropdownHeader { public readonly Bindable SelectedItem = new Bindable(); - private readonly Bindable collectionName = new Bindable(); - - protected override LocalisableString Label - { - get => base.Label; - set { } // See updateText(). - } public CollectionDropdownHeader() { @@ -150,26 +132,6 @@ namespace osu.Game.Collections Icon.Size = new Vector2(16); Foreground.Padding = new MarginPadding { Top = 4, Bottom = 4, Left = 8, Right = 4 }; } - - protected override void LoadComplete() - { - base.LoadComplete(); - - SelectedItem.BindValueChanged(_ => updateBindable(), true); - } - - private void updateBindable() - { - collectionName.UnbindAll(); - - if (SelectedItem.Value != null) - collectionName.BindTo(SelectedItem.Value.CollectionName); - - collectionName.BindValueChanged(_ => updateText(), true); - } - - // Dropdowns don't bind to value changes, so the real name is copied directly from the selected item here. - private void updateText() => base.Label = collectionName.Value; } protected class CollectionDropdownMenu : OsuDropdownMenu @@ -190,23 +152,16 @@ namespace osu.Game.Collections { protected new CollectionFilterMenuItem Item => ((DropdownMenuItem)base.Item).Value; - [Resolved] - private IBindable beatmap { get; set; } = null!; - - private readonly Bindable collectionName; - private IconButton addOrRemoveButton = null!; - private Content content = null!; + private bool beatmapInCollection; - private IDisposable? realmSubscription; - - private Live? collection => Item.Collection; + [Resolved] + private IBindable beatmap { get; set; } = null!; public CollectionDropdownMenuItem(MenuItem item) : base(item) { - collectionName = Item.CollectionName.GetBoundCopy(); } [BackgroundDependencyLoader] @@ -222,22 +177,25 @@ namespace osu.Game.Collections }); } - [Resolved] - private RealmAccess realm { get; set; } = null!; - protected override void LoadComplete() { base.LoadComplete(); if (Item.Collection != null) { - realmSubscription = realm.SubscribeToPropertyChanged(r => r.Find(Item.Collection.ID), c => c.BeatmapMD5Hashes, _ => hashesChanged()); - beatmap.BindValueChanged(_ => hashesChanged(), true); - } + beatmap.BindValueChanged(_ => + { + Debug.Assert(Item.Collection != null); - // Although the DrawableMenuItem binds to value changes of the item's text, the item is an internal implementation detail of Dropdown that has no knowledge - // of the underlying CollectionFilter value and its accompanying name, so the real name has to be copied here. Without this, the collection name wouldn't update when changed. - collectionName.BindValueChanged(name => content.Text = name.NewValue, true); + beatmapInCollection = Item.Collection.PerformRead(c => c.BeatmapMD5Hashes.Contains(beatmap.Value.BeatmapInfo.MD5Hash)); + + addOrRemoveButton.Enabled.Value = !beatmap.IsDefault; + addOrRemoveButton.Icon = beatmapInCollection ? FontAwesome.Solid.MinusSquare : FontAwesome.Solid.PlusSquare; + addOrRemoveButton.TooltipText = beatmapInCollection ? "Remove selected beatmap" : "Add selected beatmap"; + + updateButtonVisibility(); + }, true); + } updateButtonVisibility(); } @@ -254,19 +212,6 @@ namespace osu.Game.Collections base.OnHoverLost(e); } - private void hashesChanged() - { - Debug.Assert(collection != null); - - beatmapInCollection = collection.PerformRead(c => c.BeatmapMD5Hashes.Contains(beatmap.Value.BeatmapInfo.MD5Hash)); - - addOrRemoveButton.Enabled.Value = !beatmap.IsDefault; - addOrRemoveButton.Icon = beatmapInCollection ? FontAwesome.Solid.MinusSquare : FontAwesome.Solid.PlusSquare; - addOrRemoveButton.TooltipText = beatmapInCollection ? "Remove selected beatmap" : "Add selected beatmap"; - - updateButtonVisibility(); - } - protected override void OnSelectChange() { base.OnSelectChange(); @@ -275,7 +220,7 @@ namespace osu.Game.Collections private void updateButtonVisibility() { - if (collection == null) + if (Item.Collection == null) addOrRemoveButton.Alpha = 0; else addOrRemoveButton.Alpha = IsHovered || IsPreSelected || beatmapInCollection ? 1 : 0; @@ -283,22 +228,16 @@ namespace osu.Game.Collections private void addOrRemove() { - Debug.Assert(collection != null); + Debug.Assert(Item.Collection != null); - collection.PerformWrite(c => + Item.Collection.PerformWrite(c => { if (!c.BeatmapMD5Hashes.Remove(beatmap.Value.BeatmapInfo.MD5Hash)) c.BeatmapMD5Hashes.Add(beatmap.Value.BeatmapInfo.MD5Hash); }); } - protected override Drawable CreateContent() => content = (Content)base.CreateContent(); - - protected override void Dispose(bool isDisposing) - { - base.Dispose(isDisposing); - realmSubscription?.Dispose(); - } + protected override Drawable CreateContent() => (Content)base.CreateContent(); } } } diff --git a/osu.Game/Collections/CollectionFilterMenuItem.cs b/osu.Game/Collections/CollectionFilterMenuItem.cs index fd9e333915..2ac5784f09 100644 --- a/osu.Game/Collections/CollectionFilterMenuItem.cs +++ b/osu.Game/Collections/CollectionFilterMenuItem.cs @@ -2,7 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using System; -using osu.Framework.Bindables; using osu.Game.Database; namespace osu.Game.Collections @@ -21,19 +20,22 @@ namespace osu.Game.Collections /// /// The name of the collection. /// - public readonly Bindable CollectionName; + public string CollectionName { get; } /// /// Creates a new . /// /// The collection to filter beatmaps from. - public CollectionFilterMenuItem(Live? collection) + public CollectionFilterMenuItem(Live collection) + : this(collection.PerformRead(c => c.Name)) { Collection = collection; - CollectionName = new Bindable(collection?.PerformRead(c => c.Name) ?? "All beatmaps"); } - // TODO: track name changes i guess? + protected CollectionFilterMenuItem(string name) + { + CollectionName = name; + } public bool Equals(CollectionFilterMenuItem? other) { @@ -47,16 +49,16 @@ namespace osu.Game.Collections // fallback to name-based comparison. // this is required for special dropdown items which don't have a collection (all beatmaps / manage collections items below). - return CollectionName.Value == other.CollectionName.Value; + return CollectionName == other.CollectionName; } - public override int GetHashCode() => CollectionName.Value.GetHashCode(); + public override int GetHashCode() => CollectionName.GetHashCode(); } public class AllBeatmapsCollectionFilterMenuItem : CollectionFilterMenuItem { public AllBeatmapsCollectionFilterMenuItem() - : base(null) + : base("All beatmaps") { } } @@ -64,9 +66,8 @@ namespace osu.Game.Collections public class ManageCollectionsFilterMenuItem : CollectionFilterMenuItem { public ManageCollectionsFilterMenuItem() - : base(null) + : base("Manage collections...") { - CollectionName.Value = "Manage collections..."; } } } From 537f64c75ecd9608b7f8f2b0e184dc18ba4bfa58 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 27 Jul 2022 22:12:52 +0800 Subject: [PATCH 109/278] Make original hit objects and random properties as local variable. --- osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs | 37 ++++++++-------------- 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs b/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs index 36f21ba291..9e5d997353 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs @@ -98,10 +98,6 @@ namespace osu.Game.Rulesets.Osu.Mods private ControlPointInfo? controlPointInfo; - private List? originalHitObjects; - - private Random? rng; - #endregion #region Sudden Death (IApplicableFailOverride) @@ -171,16 +167,16 @@ namespace osu.Game.Rulesets.Osu.Mods public override void ApplyToBeatmap(IBeatmap beatmap) { Seed.Value ??= RNG.Next(); - rng = new Random(Seed.Value.Value); + var rng = new Random(Seed.Value.Value); var osuBeatmap = (OsuBeatmap)beatmap; if (osuBeatmap.HitObjects.Count == 0) return; controlPointInfo = osuBeatmap.ControlPointInfo; - originalHitObjects = osuBeatmap.HitObjects.OrderBy(x => x.StartTime).ToList(); - var hitObjects = generateBeats(osuBeatmap) + var originalHitObjects = osuBeatmap.HitObjects.OrderBy(x => x.StartTime).ToList(); + var hitObjects = generateBeats(osuBeatmap, originalHitObjects) .Select(beat => { var newCircle = new HitCircle(); @@ -189,21 +185,19 @@ namespace osu.Game.Rulesets.Osu.Mods return (OsuHitObject)newCircle; }).ToList(); - addHitSamples(hitObjects); + addHitSamples(originalHitObjects, hitObjects); - fixComboInfo(hitObjects); + fixComboInfo(originalHitObjects, hitObjects); - randomizeCirclePos(hitObjects); + randomizeCirclePos(rng, hitObjects); osuBeatmap.HitObjects = hitObjects; base.ApplyToBeatmap(beatmap); } - private IEnumerable generateBeats(IBeatmap beatmap) + private IEnumerable generateBeats(IBeatmap beatmap, IReadOnlyCollection originalHitObjects) { - Debug.Assert(originalHitObjects != null); - double startTime = originalHitObjects.First().StartTime; double endTime = originalHitObjects.Last().GetEndTime(); @@ -215,7 +209,7 @@ namespace osu.Game.Rulesets.Osu.Mods // Remove beats before startTime .Where(beat => almostBigger(beat, startTime)) // Remove beats during breaks - .Where(beat => !isInsideBreakPeriod(beatmap.Breaks, beat)) + .Where(beat => !isInsideBreakPeriod(originalHitObjects, beatmap.Breaks, beat)) .ToList(); // Remove beats that are too close to the next one (e.g. due to timing point changes) @@ -230,10 +224,8 @@ namespace osu.Game.Rulesets.Osu.Mods return beats; } - private void addHitSamples(IEnumerable hitObjects) + private void addHitSamples(List originalHitObjects, IEnumerable hitObjects) { - Debug.Assert(originalHitObjects != null); - foreach (var obj in hitObjects) { var samples = getSamplesAtTime(originalHitObjects, obj.StartTime); @@ -244,10 +236,8 @@ namespace osu.Game.Rulesets.Osu.Mods } } - private void fixComboInfo(List hitObjects) + private void fixComboInfo(List originalHitObjects, List hitObjects) { - Debug.Assert(originalHitObjects != null); - // Copy combo indices from an original object at the same time or from the closest preceding object // (Objects lying between two combos are assumed to belong to the preceding combo) hitObjects.ForEach(newObj => @@ -280,7 +270,7 @@ namespace osu.Game.Rulesets.Osu.Mods } } - private void randomizeCirclePos(IReadOnlyList hitObjects) + private void randomizeCirclePos(Random rng, IReadOnlyList hitObjects) { if (hitObjects.Count == 0) return; @@ -361,12 +351,11 @@ namespace osu.Game.Rulesets.Osu.Mods /// The given time is also considered to be inside a break if it is earlier than the /// start time of the first original hit object after the break. /// + /// Hit objects order by time. /// The breaks of the beatmap. /// The time to be checked.= - private bool isInsideBreakPeriod(IEnumerable breaks, double time) + private bool isInsideBreakPeriod(IReadOnlyCollection originalHitObjects, IEnumerable breaks, double time) { - Debug.Assert(originalHitObjects != null); - return breaks.Any(breakPeriod => { var firstObjAfterBreak = originalHitObjects.First(obj => almostBigger(obj.StartTime, breakPeriod.EndTime)); From 4120c20968b157fe1d8a2ab2bfba823986e8d7b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=82=BA=E4=BB=80=E9=BA=BC?= Date: Sun, 10 Jul 2022 23:43:15 +0800 Subject: [PATCH 110/278] Remove the nullable disable annotation in the Mania ruleset. --- osu.Game.Rulesets.Mania/Mods/IPlayfieldTypeMod.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaKeyMod.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModAutoplay.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModCinema.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModClassic.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModConstantSpeed.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModDaycore.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModDifficultyAdjust.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModDoubleTime.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModDualStages.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModEasy.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModFadeIn.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModFlashlight.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModHalfTime.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModHardRock.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModHidden.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModHoldOff.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModInvert.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModKey1.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModKey10.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModKey2.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModKey3.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModKey4.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModKey5.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModKey6.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModKey7.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModKey8.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModKey9.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModMirror.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModMuted.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModNightcore.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModNoFail.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModPerfect.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModPlayfieldCover.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModRandom.cs | 2 -- osu.Game.Rulesets.Mania/Mods/ManiaModSuddenDeath.cs | 2 -- 36 files changed, 72 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Mods/IPlayfieldTypeMod.cs b/osu.Game.Rulesets.Mania/Mods/IPlayfieldTypeMod.cs index 0bae893810..410386c9d5 100644 --- a/osu.Game.Rulesets.Mania/Mods/IPlayfieldTypeMod.cs +++ b/osu.Game.Rulesets.Mania/Mods/IPlayfieldTypeMod.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Mania.Mods diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaKeyMod.cs b/osu.Game.Rulesets.Mania/Mods/ManiaKeyMod.cs index 8f8b7cb091..050b302bd8 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaKeyMod.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaKeyMod.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Linq; using osu.Game.Beatmaps; diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModAutoplay.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModAutoplay.cs index f9c51bf6a2..d444c9b634 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModAutoplay.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModAutoplay.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Collections.Generic; using osu.Game.Beatmaps; using osu.Game.Rulesets.Mania.Beatmaps; diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModCinema.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModCinema.cs index 8d54923e7b..f0db742eac 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModCinema.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModCinema.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Collections.Generic; using osu.Game.Beatmaps; using osu.Game.Rulesets.Mania.Beatmaps; diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModClassic.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModClassic.cs index 603d096ed7..073dda9de8 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModClassic.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModClassic.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Mania.Mods diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModConstantSpeed.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModConstantSpeed.cs index 20dfc14f09..614ef76a3b 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModConstantSpeed.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModConstantSpeed.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Graphics.Sprites; using osu.Game.Configuration; using osu.Game.Rulesets.Mania.Objects; diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModDaycore.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModDaycore.cs index b166f3ebc3..bec0a6a1d3 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModDaycore.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModDaycore.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Mania.Mods diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModDifficultyAdjust.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModDifficultyAdjust.cs index d053e64315..0817f8f9fc 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModDifficultyAdjust.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModDifficultyAdjust.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Mania.Mods diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModDoubleTime.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModDoubleTime.cs index 66627e6ed3..a302f95966 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModDoubleTime.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModDoubleTime.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Mania.Mods diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModDualStages.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModDualStages.cs index f25a77278b..c78bf72979 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModDualStages.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModDualStages.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Beatmaps; using osu.Game.Rulesets.Mania.Beatmaps; using osu.Game.Rulesets.Mods; diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModEasy.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModEasy.cs index ff236d33bf..4093aeb2a7 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModEasy.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModEasy.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Mania.Mods diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModFadeIn.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModFadeIn.cs index ddbd7c5d6a..f80c9e1f7c 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModFadeIn.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModFadeIn.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Linq; using osu.Game.Rulesets.Mania.UI; diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModFlashlight.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModFlashlight.cs index 58005df561..8ef5bfd94c 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModFlashlight.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModFlashlight.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using osu.Framework.Bindables; using osu.Framework.Graphics; diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModHalfTime.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModHalfTime.cs index 87c81c2866..014954dd60 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModHalfTime.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModHalfTime.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Mania.Mods diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModHardRock.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModHardRock.cs index 380edca515..d9de06a811 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModHardRock.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModHardRock.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Mania.Mods diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModHidden.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModHidden.cs index 698555ddc4..e3ac624a6e 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModHidden.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModHidden.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Linq; using osu.Game.Rulesets.Mania.UI; diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModHoldOff.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModHoldOff.cs index 8c4fd0a8fc..a65938184c 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModHoldOff.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModHoldOff.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Linq; using osu.Game.Beatmaps; diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModInvert.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModInvert.cs index f202b859b1..4cbdaee323 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModInvert.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModInvert.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModKey1.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModKey1.cs index 9ce4fb6a48..948979505c 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModKey1.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModKey1.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - namespace osu.Game.Rulesets.Mania.Mods { public class ManiaModKey1 : ManiaKeyMod diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModKey10.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModKey10.cs index f378ce3435..684370fc3d 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModKey10.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModKey10.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - namespace osu.Game.Rulesets.Mania.Mods { public class ManiaModKey10 : ManiaKeyMod diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModKey2.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModKey2.cs index 5812df80f5..de91902ca8 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModKey2.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModKey2.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - namespace osu.Game.Rulesets.Mania.Mods { public class ManiaModKey2 : ManiaKeyMod diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModKey3.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModKey3.cs index 4116ed5ceb..8575a96bde 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModKey3.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModKey3.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - namespace osu.Game.Rulesets.Mania.Mods { public class ManiaModKey3 : ManiaKeyMod diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModKey4.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModKey4.cs index 9879fec686..54ea3afa07 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModKey4.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModKey4.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - namespace osu.Game.Rulesets.Mania.Mods { public class ManiaModKey4 : ManiaKeyMod diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModKey5.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModKey5.cs index 646386b0d8..e9a9bba5bd 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModKey5.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModKey5.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - namespace osu.Game.Rulesets.Mania.Mods { public class ManiaModKey5 : ManiaKeyMod diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModKey6.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModKey6.cs index 56af9ed589..b9606d1cb5 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModKey6.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModKey6.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - namespace osu.Game.Rulesets.Mania.Mods { public class ManiaModKey6 : ManiaKeyMod diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModKey7.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModKey7.cs index a0a7116ed7..b80d794085 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModKey7.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModKey7.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - namespace osu.Game.Rulesets.Mania.Mods { public class ManiaModKey7 : ManiaKeyMod diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModKey8.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModKey8.cs index fc8ecdb9ea..3462d634a4 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModKey8.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModKey8.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - namespace osu.Game.Rulesets.Mania.Mods { public class ManiaModKey8 : ManiaKeyMod diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModKey9.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModKey9.cs index c495a6c82f..83c505c048 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModKey9.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModKey9.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - namespace osu.Game.Rulesets.Mania.Mods { public class ManiaModKey9 : ManiaKeyMod diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModMirror.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModMirror.cs index 6e56981fc8..9c3744ea98 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModMirror.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModMirror.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Extensions.IEnumerableExtensions; using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mods; diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModMuted.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModMuted.cs index 076f634968..33ebcf303a 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModMuted.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModMuted.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mods; diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModNightcore.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModNightcore.cs index 9ae664e1f6..4cc712060c 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModNightcore.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModNightcore.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mods; diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModNoFail.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModNoFail.cs index 487f32dc26..e8988be548 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModNoFail.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModNoFail.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Mania.Mods diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModPerfect.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModPerfect.cs index 2789a2a06e..2e22e23dbd 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModPerfect.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModPerfect.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Mania.Mods diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModPlayfieldCover.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModPlayfieldCover.cs index 5da29e5a1d..3c24e91d54 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModPlayfieldCover.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModPlayfieldCover.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Linq; using osu.Framework.Graphics; diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModRandom.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModRandom.cs index 22347d21b8..dfb02408d2 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModRandom.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModRandom.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Linq; using osu.Framework.Extensions.IEnumerableExtensions; diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModSuddenDeath.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModSuddenDeath.cs index 17759d718e..ecc343ecaa 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModSuddenDeath.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModSuddenDeath.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Mania.Mods From 9f79e80d8b23159db0cbfe5a1541d1536498124b Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 20 Jul 2022 20:31:04 +0800 Subject: [PATCH 111/278] Remove nullable disable annotation in the Mania test case. --- .../Mods/TestSceneManiaModConstantSpeed.cs | 2 -- osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModHoldOff.cs | 2 -- osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModInvert.cs | 2 -- osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModPerfect.cs | 2 -- 4 files changed, 8 deletions(-) diff --git a/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModConstantSpeed.cs b/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModConstantSpeed.cs index 538c8b13d1..60363aaeef 100644 --- a/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModConstantSpeed.cs +++ b/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModConstantSpeed.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; diff --git a/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModHoldOff.cs b/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModHoldOff.cs index 4222be0359..7970d5b594 100644 --- a/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModHoldOff.cs +++ b/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModHoldOff.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Linq; using NUnit.Framework; using osu.Game.Beatmaps; diff --git a/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModInvert.cs b/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModInvert.cs index 4c97f65b07..f2cc254e38 100644 --- a/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModInvert.cs +++ b/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModInvert.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using NUnit.Framework; using osu.Game.Rulesets.Mania.Mods; using osu.Game.Tests.Visual; diff --git a/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModPerfect.cs b/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModPerfect.cs index 9612543483..2e3b21aed7 100644 --- a/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModPerfect.cs +++ b/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModPerfect.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using NUnit.Framework; using osu.Game.Rulesets.Mania.Mods; using osu.Game.Rulesets.Mania.Objects; From d766052be4872917bb75b6db821ea72be8e8c70e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=82=BA=E4=BB=80=E9=BA=BC?= Date: Sun, 10 Jul 2022 23:59:14 +0800 Subject: [PATCH 112/278] Remove nullable disable annotation in the Taiko ruleset. --- osu.Game.Rulesets.Taiko/Mods/TaikoModAutoplay.cs | 2 -- osu.Game.Rulesets.Taiko/Mods/TaikoModCinema.cs | 2 -- osu.Game.Rulesets.Taiko/Mods/TaikoModClassic.cs | 2 -- osu.Game.Rulesets.Taiko/Mods/TaikoModDaycore.cs | 2 -- osu.Game.Rulesets.Taiko/Mods/TaikoModDifficultyAdjust.cs | 2 -- osu.Game.Rulesets.Taiko/Mods/TaikoModDoubleTime.cs | 2 -- osu.Game.Rulesets.Taiko/Mods/TaikoModEasy.cs | 2 -- osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs | 2 -- osu.Game.Rulesets.Taiko/Mods/TaikoModHalfTime.cs | 2 -- osu.Game.Rulesets.Taiko/Mods/TaikoModHardRock.cs | 2 -- osu.Game.Rulesets.Taiko/Mods/TaikoModHidden.cs | 2 -- osu.Game.Rulesets.Taiko/Mods/TaikoModMuted.cs | 2 -- osu.Game.Rulesets.Taiko/Mods/TaikoModNightcore.cs | 2 -- osu.Game.Rulesets.Taiko/Mods/TaikoModNoFail.cs | 2 -- osu.Game.Rulesets.Taiko/Mods/TaikoModPerfect.cs | 2 -- osu.Game.Rulesets.Taiko/Mods/TaikoModRandom.cs | 2 -- osu.Game.Rulesets.Taiko/Mods/TaikoModRelax.cs | 2 -- osu.Game.Rulesets.Taiko/Mods/TaikoModSuddenDeath.cs | 2 -- osu.Game.Rulesets.Taiko/Mods/TaikoModSwap.cs | 2 -- 19 files changed, 38 deletions(-) diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModAutoplay.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModAutoplay.cs index 6c01bae027..4b74b4991e 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModAutoplay.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModAutoplay.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Collections.Generic; using osu.Game.Beatmaps; using osu.Game.Rulesets.Mods; diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModCinema.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModCinema.cs index d1c192f7fa..fee0cb2744 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModCinema.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModCinema.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Collections.Generic; using osu.Game.Beatmaps; using osu.Game.Rulesets.Mods; diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModClassic.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModClassic.cs index 233179c9ec..d18b88761d 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModClassic.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModClassic.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Taiko.Objects; using osu.Game.Rulesets.Taiko.UI; diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModDaycore.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModDaycore.cs index 873aa7f992..84aa5e6bba 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModDaycore.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModDaycore.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Taiko.Mods diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModDifficultyAdjust.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModDifficultyAdjust.cs index 564d023c5a..99a064d35f 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModDifficultyAdjust.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModDifficultyAdjust.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Linq; using osu.Game.Beatmaps; using osu.Game.Configuration; diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModDoubleTime.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModDoubleTime.cs index b19c2eaccf..89581c57bd 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModDoubleTime.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModDoubleTime.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Taiko.Mods diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModEasy.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModEasy.cs index a37e1c6f5c..ad6fdf59e2 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModEasy.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModEasy.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Beatmaps; using osu.Game.Rulesets.Mods; diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs index fe02a6caf9..43230bc035 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Layout; diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModHalfTime.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModHalfTime.cs index ddfc2d1174..68d6305fbf 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModHalfTime.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModHalfTime.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Taiko.Mods diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModHardRock.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModHardRock.cs index 7780936e7d..ba41175461 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModHardRock.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModHardRock.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Beatmaps; using osu.Game.Rulesets.Mods; diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModHidden.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModHidden.cs index fe3e5ca11c..538d0a9d7a 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModHidden.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModHidden.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Graphics; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Objects; diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModMuted.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModMuted.cs index 874e15406d..0f1e0b2885 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModMuted.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModMuted.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Taiko.Objects; diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModNightcore.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModNightcore.cs index e02a16f62f..7cb14635ff 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModNightcore.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModNightcore.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Taiko.Objects; diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModNoFail.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModNoFail.cs index 57ecf0224f..bf1006f1aa 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModNoFail.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModNoFail.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Taiko.Mods diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModPerfect.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModPerfect.cs index c65dba243b..b107b14a03 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModPerfect.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModPerfect.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Taiko.Mods diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModRandom.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModRandom.cs index f58f59aaf2..307a37bf2e 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModRandom.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModRandom.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Linq; using osu.Framework.Utils; diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModRelax.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModRelax.cs index a3a644ab99..7be70d9ac3 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModRelax.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModRelax.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Taiko.Mods diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModSuddenDeath.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModSuddenDeath.cs index 037e376ad2..7a0f6c7cd1 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModSuddenDeath.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModSuddenDeath.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Taiko.Mods diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModSwap.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModSwap.cs index c9cba59760..3cb337c41d 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModSwap.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModSwap.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Linq; using osu.Game.Beatmaps; From 860e9d42ff2236841d309facc8c29284f9c6fc93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=82=BA=E4=BB=80=E9=BA=BC?= Date: Mon, 11 Jul 2022 00:00:48 +0800 Subject: [PATCH 113/278] Mark the property as nullable and add some assert check. --- osu.Game.Rulesets.Taiko/Mods/TaikoModClassic.cs | 5 ++++- osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs | 5 +++-- osu.Game.Rulesets.Taiko/Mods/TaikoModHidden.cs | 5 ++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModClassic.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModClassic.cs index d18b88761d..f7fdd447d6 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModClassic.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModClassic.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Diagnostics; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Taiko.Objects; using osu.Game.Rulesets.Taiko.UI; @@ -10,7 +11,7 @@ namespace osu.Game.Rulesets.Taiko.Mods { public class TaikoModClassic : ModClassic, IApplicableToDrawableRuleset, IUpdatableByPlayfield { - private DrawableTaikoRuleset drawableTaikoRuleset; + private DrawableTaikoRuleset? drawableTaikoRuleset; public void ApplyToDrawableRuleset(DrawableRuleset drawableRuleset) { @@ -23,6 +24,8 @@ namespace osu.Game.Rulesets.Taiko.Mods public void Update(Playfield playfield) { + Debug.Assert(drawableTaikoRuleset != null); + // Classic taiko scrolls at a constant 100px per 1000ms. More notes become visible as the playfield is lengthened. const float scroll_rate = 10; diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs index 43230bc035..3820e55e75 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using osu.Framework.Bindables; +using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Framework.Layout; using osu.Game.Configuration; @@ -36,9 +37,9 @@ namespace osu.Game.Rulesets.Taiko.Mods public override float DefaultFlashlightSize => 250; - protected override Flashlight CreateFlashlight() => new TaikoFlashlight(this, playfield); + protected override Flashlight CreateFlashlight() => new TaikoFlashlight(this, playfield.AsNonNull()); - private TaikoPlayfield playfield; + private TaikoPlayfield? playfield; public override void ApplyToDrawableRuleset(DrawableRuleset drawableRuleset) { diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModHidden.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModHidden.cs index 538d0a9d7a..dab2279351 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModHidden.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModHidden.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Diagnostics; using osu.Framework.Graphics; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Objects; @@ -30,7 +31,7 @@ namespace osu.Game.Rulesets.Taiko.Mods /// private const float fade_out_duration = 0.375f; - private DrawableTaikoRuleset drawableRuleset; + private DrawableTaikoRuleset? drawableRuleset; public void ApplyToDrawableRuleset(DrawableRuleset drawableRuleset) { @@ -44,6 +45,8 @@ namespace osu.Game.Rulesets.Taiko.Mods protected override void ApplyNormalVisibilityState(DrawableHitObject hitObject, ArmedState state) { + Debug.Assert(drawableRuleset != null); + switch (hitObject) { case DrawableDrumRollTick: From 3510c1656672962aa026b7a0bcbd4123408941a5 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 20 Jul 2022 20:38:02 +0800 Subject: [PATCH 114/278] Remove nullable disable annotation in the Taiko test case. --- osu.Game.Rulesets.Taiko.Tests/Mods/TaikoModTestScene.cs | 2 -- osu.Game.Rulesets.Taiko.Tests/Mods/TestSceneTaikoModHidden.cs | 2 -- osu.Game.Rulesets.Taiko.Tests/Mods/TestSceneTaikoModPerfect.cs | 2 -- 3 files changed, 6 deletions(-) diff --git a/osu.Game.Rulesets.Taiko.Tests/Mods/TaikoModTestScene.cs b/osu.Game.Rulesets.Taiko.Tests/Mods/TaikoModTestScene.cs index ca2f8102b7..3090facf8c 100644 --- a/osu.Game.Rulesets.Taiko.Tests/Mods/TaikoModTestScene.cs +++ b/osu.Game.Rulesets.Taiko.Tests/Mods/TaikoModTestScene.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Tests.Visual; namespace osu.Game.Rulesets.Taiko.Tests.Mods diff --git a/osu.Game.Rulesets.Taiko.Tests/Mods/TestSceneTaikoModHidden.cs b/osu.Game.Rulesets.Taiko.Tests/Mods/TestSceneTaikoModHidden.cs index 0b28bfee2e..7abbb9d186 100644 --- a/osu.Game.Rulesets.Taiko.Tests/Mods/TestSceneTaikoModHidden.cs +++ b/osu.Game.Rulesets.Taiko.Tests/Mods/TestSceneTaikoModHidden.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Linq; using NUnit.Framework; using osu.Game.Rulesets.Taiko.Mods; diff --git a/osu.Game.Rulesets.Taiko.Tests/Mods/TestSceneTaikoModPerfect.cs b/osu.Game.Rulesets.Taiko.Tests/Mods/TestSceneTaikoModPerfect.cs index 917462c128..a83cc16413 100644 --- a/osu.Game.Rulesets.Taiko.Tests/Mods/TestSceneTaikoModPerfect.cs +++ b/osu.Game.Rulesets.Taiko.Tests/Mods/TestSceneTaikoModPerfect.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using NUnit.Framework; using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Taiko.Mods; From 45c11f2b7b2765c42d19069949fa5b3a14c35c6c Mon Sep 17 00:00:00 2001 From: Nitrous Date: Thu, 28 Jul 2022 08:01:38 +0800 Subject: [PATCH 115/278] account for gameplay start time --- osu.Game/Screens/Play/HUD/SongProgress.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/Play/HUD/SongProgress.cs b/osu.Game/Screens/Play/HUD/SongProgress.cs index c245a47554..5c7c7d28c6 100644 --- a/osu.Game/Screens/Play/HUD/SongProgress.cs +++ b/osu.Game/Screens/Play/HUD/SongProgress.cs @@ -3,6 +3,7 @@ #nullable disable +using System; using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; @@ -20,9 +21,12 @@ namespace osu.Game.Screens.Play.HUD { public bool UsesFixedAnchor { get; set; } - [Resolved] + [Resolved(canBeNull: true)] private GameplayClock gameplayClock { get; set; } + [Resolved(canBeNull: true)] + private GameplayClockContainer gameplayClockContainer { get; set; } + [Resolved(canBeNull: true)] private DrawableRuleset drawableRuleset { get; set; } @@ -69,12 +73,13 @@ namespace osu.Game.Screens.Play.HUD if (objects == null) return; - double gameplayTime = gameplayClock?.CurrentTime ?? Time.Current; + double gameplayTime = gameplayClockContainer?.GameplayClock.CurrentTime ?? gameplayClock?.CurrentTime ?? Time.Current; double frameStableTime = referenceClock?.CurrentTime ?? gameplayTime; if (frameStableTime < FirstHitTime) { - UpdateProgress((frameStableTime - FirstEventTime) / (FirstHitTime - FirstEventTime), gameplayTime, true); + double earliest = Math.Min(FirstEventTime, gameplayClockContainer?.StartTime ?? 0); + UpdateProgress((frameStableTime - earliest) / (FirstHitTime - earliest), gameplayTime, true); } else { From 9088caa377247a7c5ace117d24d12b1af707b0ee Mon Sep 17 00:00:00 2001 From: Nitrous Date: Thu, 28 Jul 2022 08:36:26 +0800 Subject: [PATCH 116/278] move `LegacyComboCounter` to `osu.Game.Skinning` --- .../TestSceneCatchPlayerLegacySkin.cs | 1 - .../Skinning/Legacy/CatchLegacySkinTransformer.cs | 1 - .../Visual/Gameplay/TestSceneSkinnableComboCounter.cs | 1 + osu.Game/{Screens/Play/HUD => Skinning}/LegacyComboCounter.cs | 4 ++-- 4 files changed, 3 insertions(+), 4 deletions(-) rename osu.Game/{Screens/Play/HUD => Skinning}/LegacyComboCounter.cs (99%) diff --git a/osu.Game.Rulesets.Catch.Tests/TestSceneCatchPlayerLegacySkin.cs b/osu.Game.Rulesets.Catch.Tests/TestSceneCatchPlayerLegacySkin.cs index 8dd6f82c57..2078e1453f 100644 --- a/osu.Game.Rulesets.Catch.Tests/TestSceneCatchPlayerLegacySkin.cs +++ b/osu.Game.Rulesets.Catch.Tests/TestSceneCatchPlayerLegacySkin.cs @@ -9,7 +9,6 @@ using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics.Containers; using osu.Framework.Screens; using osu.Framework.Testing; -using osu.Game.Screens.Play.HUD; using osu.Game.Skinning; using osu.Game.Tests.Visual; using osuTK; diff --git a/osu.Game.Rulesets.Catch/Skinning/Legacy/CatchLegacySkinTransformer.cs b/osu.Game.Rulesets.Catch/Skinning/Legacy/CatchLegacySkinTransformer.cs index c5e5e59dd2..c06d9f520f 100644 --- a/osu.Game.Rulesets.Catch/Skinning/Legacy/CatchLegacySkinTransformer.cs +++ b/osu.Game.Rulesets.Catch/Skinning/Legacy/CatchLegacySkinTransformer.cs @@ -6,7 +6,6 @@ using System.Linq; using osu.Framework.Bindables; using osu.Framework.Graphics; -using osu.Game.Screens.Play.HUD; using osu.Game.Skinning; using osuTK.Graphics; diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSkinnableComboCounter.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSkinnableComboCounter.cs index eacab6d34f..ef56f456ea 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSkinnableComboCounter.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSkinnableComboCounter.cs @@ -10,6 +10,7 @@ using osu.Framework.Testing; using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Scoring; using osu.Game.Screens.Play.HUD; +using osu.Game.Skinning; namespace osu.Game.Tests.Visual.Gameplay { diff --git a/osu.Game/Screens/Play/HUD/LegacyComboCounter.cs b/osu.Game/Skinning/LegacyComboCounter.cs similarity index 99% rename from osu.Game/Screens/Play/HUD/LegacyComboCounter.cs rename to osu.Game/Skinning/LegacyComboCounter.cs index 6e36ffb54e..bfa6d5a255 100644 --- a/osu.Game/Screens/Play/HUD/LegacyComboCounter.cs +++ b/osu.Game/Skinning/LegacyComboCounter.cs @@ -9,10 +9,10 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Game.Rulesets.Scoring; -using osu.Game.Skinning; +using osu.Game.Screens.Play.HUD; using osuTK; -namespace osu.Game.Screens.Play.HUD +namespace osu.Game.Skinning { /// /// Uses the 'x' symbol and has a pop-out effect while rolling over. From ac39d3a1424470e41ea107ed7246088d51d20cbc Mon Sep 17 00:00:00 2001 From: Andrew Hong Date: Wed, 27 Jul 2022 21:52:28 -0400 Subject: [PATCH 117/278] "Copied URL" -> "URL copied" --- osu.Game/Graphics/UserInterface/ExternalLinkButton.cs | 2 +- osu.Game/Localisation/ToastStrings.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs b/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs index 810cd6ef58..87d67939bf 100644 --- a/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs +++ b/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs @@ -76,7 +76,7 @@ namespace osu.Game.Graphics.UserInterface if (Link != null) { items.Add(new OsuMenuItem("Open", MenuItemType.Standard, () => host.OpenUrlExternally(Link))); - items.Add(new OsuMenuItem("Copy URL", MenuItemType.Standard, () => copyUrl())); + items.Add(new OsuMenuItem("Copy URL", MenuItemType.Standard, copyUrl)); } return items.ToArray(); diff --git a/osu.Game/Localisation/ToastStrings.cs b/osu.Game/Localisation/ToastStrings.cs index d6771fcd96..da798a3937 100644 --- a/osu.Game/Localisation/ToastStrings.cs +++ b/osu.Game/Localisation/ToastStrings.cs @@ -45,9 +45,9 @@ namespace osu.Game.Localisation public static LocalisableString SkinSaved => new TranslatableString(getKey(@"skin_saved"), @"Skin saved"); /// - /// "Copied URL" + /// "URL copied" /// - public static LocalisableString CopiedUrl => new TranslatableString(getKey(@"copied_url"), @"Copied URL"); + public static LocalisableString UrlCopied => new TranslatableString(getKey(@"url_copied"), @"URL copied"); private static string getKey(string key) => $@"{prefix}:{key}"; } From f097064eea6ab93cc6ca8702317ab783e0bc5c70 Mon Sep 17 00:00:00 2001 From: Andrew Hong Date: Wed, 27 Jul 2022 21:52:38 -0400 Subject: [PATCH 118/278] Adjust to reviews --- .../UserInterface/ExternalLinkButton.cs | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs b/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs index 87d67939bf..762b4bd90d 100644 --- a/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs +++ b/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs @@ -50,21 +50,10 @@ namespace osu.Game.Graphics.UserInterface }; } - private class CopyUrlToast : Toast - { - public CopyUrlToast(LocalisableString value) - : base(UserInterfaceStrings.GeneralHeader, value, "") - { - } - } - private void copyUrl() { - if (Link != null) - { - host.GetClipboard()?.SetText(Link); - onScreenDisplay?.Display(new CopyUrlToast(ToastStrings.CopiedUrl)); - } + host.GetClipboard()?.SetText(Link); + onScreenDisplay?.Display(new CopyUrlToast(ToastStrings.UrlCopied)); } public MenuItem[] ContextMenuItems @@ -109,5 +98,13 @@ namespace osu.Game.Graphics.UserInterface } public LocalisableString TooltipText => "view in browser"; + + private class CopyUrlToast : Toast + { + public CopyUrlToast(LocalisableString value) + : base(UserInterfaceStrings.GeneralHeader, value, "") + { + } + } } } From f01c3972207ca20b26a7e6361e2b492e3d44eeb4 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 12:12:46 +0900 Subject: [PATCH 119/278] Apply nullability --- .../Graphics/UserInterface/ExternalLinkButton.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs b/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs index 762b4bd90d..7b9abf6781 100644 --- a/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs +++ b/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Collections.Generic; using osu.Framework.Allocation; using osu.Framework.Graphics; @@ -23,19 +21,19 @@ namespace osu.Game.Graphics.UserInterface { public class ExternalLinkButton : CompositeDrawable, IHasTooltip, IHasContextMenu { - public string Link { get; set; } + public string? Link { get; set; } private Color4 hoverColour; [Resolved] - private GameHost host { get; set; } + private GameHost host { get; set; } = null!; - [Resolved(canBeNull: true)] - private OnScreenDisplay onScreenDisplay { get; set; } + [Resolved] + private OnScreenDisplay? onScreenDisplay { get; set; } private readonly SpriteIcon linkIcon; - public ExternalLinkButton(string link = null) + public ExternalLinkButton(string? link = null) { Link = link; Size = new Vector2(12); From f44a4c865293ae77f6b0bf2255f7b976c6a6ea6e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 12:13:45 +0900 Subject: [PATCH 120/278] Reorder file content to match expectations --- .../UserInterface/ExternalLinkButton.cs | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs b/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs index 7b9abf6781..7f86a060ad 100644 --- a/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs +++ b/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs @@ -48,28 +48,6 @@ namespace osu.Game.Graphics.UserInterface }; } - private void copyUrl() - { - host.GetClipboard()?.SetText(Link); - onScreenDisplay?.Display(new CopyUrlToast(ToastStrings.UrlCopied)); - } - - public MenuItem[] ContextMenuItems - { - get - { - List items = new List(); - - if (Link != null) - { - items.Add(new OsuMenuItem("Open", MenuItemType.Standard, () => host.OpenUrlExternally(Link))); - items.Add(new OsuMenuItem("Copy URL", MenuItemType.Standard, copyUrl)); - } - - return items.ToArray(); - } - } - [BackgroundDependencyLoader] private void load(OsuColour colours) { @@ -97,6 +75,28 @@ namespace osu.Game.Graphics.UserInterface public LocalisableString TooltipText => "view in browser"; + public MenuItem[] ContextMenuItems + { + get + { + List items = new List(); + + if (Link != null) + { + items.Add(new OsuMenuItem("Open", MenuItemType.Standard, () => host.OpenUrlExternally(Link))); + items.Add(new OsuMenuItem("Copy URL", MenuItemType.Standard, copyUrl)); + } + + return items.ToArray(); + } + } + + private void copyUrl() + { + host.GetClipboard()?.SetText(Link); + onScreenDisplay?.Display(new CopyUrlToast(ToastStrings.UrlCopied)); + } + private class CopyUrlToast : Toast { public CopyUrlToast(LocalisableString value) From 8da499fb0fc1b1e0febcac88cccda792707a5da6 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 12:16:21 +0900 Subject: [PATCH 121/278] Add proper test coverage --- .../Visual/Online/TestSceneExternalLinkButton.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneExternalLinkButton.cs b/osu.Game.Tests/Visual/Online/TestSceneExternalLinkButton.cs index fdcde0f2a5..4185d56833 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneExternalLinkButton.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneExternalLinkButton.cs @@ -3,6 +3,8 @@ #nullable disable +using osu.Framework.Graphics; +using osu.Game.Graphics.Cursor; using osu.Game.Graphics.UserInterface; using osuTK; @@ -12,9 +14,15 @@ namespace osu.Game.Tests.Visual.Online { public TestSceneExternalLinkButton() { - Child = new ExternalLinkButton("https://osu.ppy.sh/home") + Child = new OsuContextMenuContainer { - Size = new Vector2(50) + RelativeSizeAxes = Axes.Both, + Child = new ExternalLinkButton("https://osu.ppy.sh/home") + { + Size = new Vector2(50), + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + } }; } } From 0913cf013cbe8555a5450924a7ebfd3c2a8d8820 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 13:24:14 +0900 Subject: [PATCH 122/278] Split out tests and fix variable conflict --- .../Visual/Gameplay/TestSceneSongProgress.cs | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs index f32a7e7cab..897284ed80 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs @@ -19,7 +19,8 @@ namespace osu.Game.Tests.Visual.Gameplay [TestFixture] public class TestSceneSongProgress : SkinnableHUDComponentTestScene { - private DefaultSongProgress progress; + private DefaultSongProgress defaultProgress; + private readonly List progresses = new List(); private readonly StopwatchClock clock; @@ -45,14 +46,19 @@ namespace osu.Game.Tests.Visual.Gameplay { AddStep("display max values", displayMaxValues); AddStep("start", clock.Start); - AddStep("allow seeking", () => progress.AllowSeeking.Value = true); - AddStep("hide graph", () => progress.ShowGraph.Value = false); - AddStep("disallow seeking", () => progress.AllowSeeking.Value = false); - AddStep("allow seeking", () => progress.AllowSeeking.Value = true); - AddStep("show graph", () => progress.ShowGraph.Value = true); AddStep("stop", clock.Stop); } + [Test] + public void TestToggleSeeking() + { + AddStep("allow seeking", () => defaultProgress.AllowSeeking.Value = true); + AddStep("hide graph", () => defaultProgress.ShowGraph.Value = false); + AddStep("disallow seeking", () => defaultProgress.AllowSeeking.Value = false); + AddStep("allow seeking", () => defaultProgress.AllowSeeking.Value = true); + AddStep("show graph", () => defaultProgress.ShowGraph.Value = true); + } + private void displayMaxValues() { var objects = new List(); @@ -64,11 +70,11 @@ namespace osu.Game.Tests.Visual.Gameplay private void replaceObjects(List objects) { - progress.RequestSeek = pos => clock.Seek(pos); + defaultProgress.RequestSeek = pos => clock.Seek(pos); - foreach (var progress in progresses) + foreach (var p in progresses) { - progress.Objects = objects; + p.Objects = objects; } } @@ -80,15 +86,15 @@ namespace osu.Game.Tests.Visual.Gameplay protected override Drawable CreateDefaultImplementation() { - progress = new DefaultSongProgress + defaultProgress = new DefaultSongProgress { RelativeSizeAxes = Axes.X, Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, }; - progresses.Add(progress); - return progress; + progresses.Add(defaultProgress); + return defaultProgress; } protected override Drawable CreateLegacyImplementation() From 67c7f324ee899d652e127903a82917c980896e95 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 27 Jul 2022 19:02:43 +0900 Subject: [PATCH 123/278] Simplify `CollectionFilterDropdown` filter flow weirdness --- .../SongSelect/TestSceneFilterControl.cs | 10 +++++ .../Collections/CollectionFilterDropdown.cs | 43 +++++++------------ osu.Game/Screens/Select/FilterControl.cs | 20 +++------ 3 files changed, 32 insertions(+), 41 deletions(-) diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs index aaaa0aec95..feb71def5d 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs @@ -176,6 +176,8 @@ namespace osu.Game.Tests.Visual.SongSelect [Test] public void TestManageCollectionsFilterIsNotSelected() { + bool received = false; + addExpandHeaderStep(); AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "1", new List { "abc" })))); @@ -187,6 +189,12 @@ namespace osu.Game.Tests.Visual.SongSelect addExpandHeaderStep(); + AddStep("watch for filter requests", () => + { + received = false; + control.ChildrenOfType().First().RequestFilter = () => received = true; + }); + AddStep("click manage collections filter", () => { InputManager.MoveMouseTo(getCollectionDropdownItems().Last()); @@ -194,6 +202,8 @@ namespace osu.Game.Tests.Visual.SongSelect }); AddAssert("collection filter still selected", () => control.CreateCriteria().CollectionBeatmapMD5Hashes.Any()); + + AddAssert("filter request not fired", () => !received); } private BeatmapCollection getFirstCollection() => Realm.Run(r => r.All().First()); diff --git a/osu.Game/Collections/CollectionFilterDropdown.cs b/osu.Game/Collections/CollectionFilterDropdown.cs index ec409df4d6..fa15e2b56f 100644 --- a/osu.Game/Collections/CollectionFilterDropdown.cs +++ b/osu.Game/Collections/CollectionFilterDropdown.cs @@ -30,15 +30,8 @@ namespace osu.Game.Collections /// protected virtual bool ShowManageCollectionsItem => true; - private readonly BindableWithCurrent current = new BindableWithCurrent(); + public Action? RequestFilter { private get; set; } - public new Bindable Current - { - get => current.Current; - set => current.Current = value; - } - - private readonly IBindableList beatmaps = new BindableList(); private readonly BindableList filters = new BindableList(); [Resolved] @@ -50,6 +43,7 @@ namespace osu.Game.Collections public CollectionFilterDropdown() { ItemSource = filters; + Current.Value = new AllBeatmapsCollectionFilterMenuItem(); } @@ -59,17 +53,9 @@ namespace osu.Game.Collections realm.RegisterForNotifications(r => r.All(), collectionsChanged); - // Dropdown has logic which triggers a change on the bindable with every change to the contained items. - // This is not desirable here, as it leads to multiple filter operations running even though nothing has changed. - // An extra bindable is enough to subvert this behaviour. - base.Current = Current; - - Current.BindValueChanged(currentChanged, true); + Current.BindValueChanged(currentChanged); } - /// - /// Occurs when a collection has been added or removed. - /// private void collectionsChanged(IRealmCollection collections, ChangeSet? changes, Exception error) { var selectedItem = SelectedItem?.Value?.Collection; @@ -83,38 +69,41 @@ namespace osu.Game.Collections Current.Value = filters.SingleOrDefault(f => f.Collection != null && f.Collection.ID == selectedItem?.ID) ?? filters[0]; - // Trigger a re-filter if the current item was in the changeset. + // Trigger a re-filter if the current item was in the change set. if (selectedItem != null && changes != null) { foreach (int index in changes.ModifiedIndices) { if (collections[index].ID == selectedItem.ID) - { - // The filtered beatmaps have changed, without the filter having changed itself. So a change in filter must be notified. - // Note that this does NOT propagate to bound bindables, so the FilterControl must bind directly to the value change event of this bindable. - Current.TriggerChange(); - } + RequestFilter?.Invoke(); } } } private void currentChanged(ValueChangedEvent filter) { + // May be null during .Clear(). + if (filter.NewValue == null) + return; + // Never select the manage collection filter - rollback to the previous filter. // This is done after the above since it is important that bindable is unbound from OldValue, which is lost after forcing it back to the old value. if (filter.NewValue is ManageCollectionsFilterMenuItem) { Current.Value = filter.OldValue; manageCollectionsDialog?.Show(); + return; } + + // This dropdown be weird. + // We only care about filtering if the actual collection has changed. + if (filter.OldValue?.Collection != null || filter.NewValue?.Collection != null) + RequestFilter?.Invoke(); } protected override LocalisableString GenerateItemText(CollectionFilterMenuItem item) => item.CollectionName; - protected sealed override DropdownHeader CreateHeader() => CreateCollectionHeader().With(d => - { - d.SelectedItem.BindTarget = Current; - }); + protected sealed override DropdownHeader CreateHeader() => CreateCollectionHeader().With(d => d.SelectedItem.BindTarget = Current); protected sealed override DropdownMenu CreateMenu() => CreateCollectionMenu(); diff --git a/osu.Game/Screens/Select/FilterControl.cs b/osu.Game/Screens/Select/FilterControl.cs index 5f5344a338..f07817d5dc 100644 --- a/osu.Game/Screens/Select/FilterControl.cs +++ b/osu.Game/Screens/Select/FilterControl.cs @@ -39,6 +39,10 @@ namespace osu.Game.Screens.Select private Bindable groupMode; + private SeekLimitedSearchTextBox searchTextBox; + + private CollectionFilterDropdown collectionDropdown; + public FilterCriteria CreateCriteria() { string query = searchTextBox.Text; @@ -49,7 +53,7 @@ namespace osu.Game.Screens.Select Sort = sortMode.Value, AllowConvertedBeatmaps = showConverted.Value, Ruleset = ruleset.Value, - CollectionBeatmapMD5Hashes = collectionDropdown?.Current.Value?.Collection?.PerformRead(c => c.BeatmapMD5Hashes) + CollectionBeatmapMD5Hashes = collectionDropdown.Current.Value?.Collection?.PerformRead(c => c.BeatmapMD5Hashes) }; if (!minimumStars.IsDefault) @@ -64,10 +68,6 @@ namespace osu.Game.Screens.Select return criteria; } - private SeekLimitedSearchTextBox searchTextBox; - - private CollectionFilterDropdown collectionDropdown; - public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => base.ReceivePositionalInputAt(screenSpacePos) || sortTabs.ReceivePositionalInputAt(screenSpacePos); @@ -183,6 +183,7 @@ namespace osu.Game.Screens.Select { Anchor = Anchor.TopRight, Origin = Anchor.TopRight, + RequestFilter = updateCriteria, RelativeSizeAxes = Axes.X, Y = 4, Width = 0.5f, @@ -209,15 +210,6 @@ namespace osu.Game.Screens.Select groupMode.BindValueChanged(_ => updateCriteria()); sortMode.BindValueChanged(_ => updateCriteria()); - collectionDropdown.Current.ValueChanged += val => - { - if (val.NewValue == null) - // may be null briefly while menu is repopulated. - return; - - updateCriteria(); - }; - searchTextBox.Current.ValueChanged += _ => updateCriteria(); updateCriteria(); From 34a2d1a6e1921baa76a8521ffbfa7d3b4d30f7fa Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 27 Jul 2022 19:35:25 +0900 Subject: [PATCH 124/278] Fix `ManageCollectionsDialog` and remove weird placeholder logic --- .../TestSceneManageCollectionsDialog.cs | 27 +++++- .../Collections/CollectionFilterDropdown.cs | 33 ++++--- .../Collections/DeleteCollectionDialog.cs | 5 +- .../Collections/DrawableCollectionList.cs | 30 ++++-- .../Collections/DrawableCollectionListItem.cs | 97 ++++++------------- .../Collections/ManageCollectionsDialog.cs | 4 +- 6 files changed, 103 insertions(+), 93 deletions(-) diff --git a/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs b/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs index 8de38eb4e7..afcb511a6a 100644 --- a/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs +++ b/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs @@ -109,10 +109,15 @@ namespace osu.Game.Tests.Visual.Collections InputManager.Click(MouseButton.Left); }); - // Done directly via the collection since InputManager methods cannot add text to textbox... - AddStep("change collection name", () => placeholderItem.Model.PerformWrite(c => c.Name = "a")); + assertCollectionCount(0); + + AddStep("change collection name", () => + { + placeholderItem.ChildrenOfType().First().Text = "test text"; + InputManager.Key(Key.Enter); + }); + assertCollectionCount(1); - AddAssert("collection now exists", () => placeholderItem.Model.IsManaged); AddAssert("last item is placeholder", () => !dialog.ChildrenOfType().Last().Model.IsManaged); } @@ -257,6 +262,7 @@ namespace osu.Game.Tests.Visual.Collections public void TestCollectionRenamedOnTextChange() { BeatmapCollection first = null!; + DrawableCollectionListItem firstItem = null!; AddStep("add two collections", () => { @@ -272,12 +278,23 @@ namespace osu.Game.Tests.Visual.Collections assertCollectionCount(2); - AddStep("change first collection name", () => dialog.ChildrenOfType().First().Text = "First"); + AddStep("focus first collection", () => + { + InputManager.MoveMouseTo(firstItem = dialog.ChildrenOfType().First()); + InputManager.Click(MouseButton.Left); + }); + + AddStep("change first collection name", () => + { + firstItem.ChildrenOfType().First().Text = "First"; + InputManager.Key(Key.Enter); + }); + AddUntilStep("collection has new name", () => first.Name == "First"); } private void assertCollectionCount(int count) - => AddUntilStep($"{count} collections shown", () => dialog.ChildrenOfType().Count(i => i.IsCreated.Value) == count); + => AddUntilStep($"{count} collections shown", () => dialog.ChildrenOfType().Count() == count + 1); // +1 for placeholder private void assertCollectionName(int index, string name) => AddUntilStep($"item {index + 1} has correct name", () => dialog.ChildrenOfType().ElementAt(index).ChildrenOfType().First().Text == name); diff --git a/osu.Game/Collections/CollectionFilterDropdown.cs b/osu.Game/Collections/CollectionFilterDropdown.cs index fa15e2b56f..790a23d2e5 100644 --- a/osu.Game/Collections/CollectionFilterDropdown.cs +++ b/osu.Game/Collections/CollectionFilterDropdown.cs @@ -53,21 +53,27 @@ namespace osu.Game.Collections realm.RegisterForNotifications(r => r.All(), collectionsChanged); - Current.BindValueChanged(currentChanged); + Current.BindValueChanged(selectionChanged); } private void collectionsChanged(IRealmCollection collections, ChangeSet? changes, Exception error) { var selectedItem = SelectedItem?.Value?.Collection; + var allBeatmaps = new AllBeatmapsCollectionFilterMenuItem(); + filters.Clear(); - filters.Add(new AllBeatmapsCollectionFilterMenuItem()); + filters.Add(allBeatmaps); filters.AddRange(collections.Select(c => new CollectionFilterMenuItem(c.ToLive(realm)))); if (ShowManageCollectionsItem) filters.Add(new ManageCollectionsFilterMenuItem()); - Current.Value = filters.SingleOrDefault(f => f.Collection != null && f.Collection.ID == selectedItem?.ID) ?? filters[0]; + // This current update and schedule is required to work around dropdown headers not updating text even when the selected item + // changes. It's not great but honestly the whole dropdown menu structure isn't great. This needs to be fixed, but I'll issue + // a warning that it's going to be a frustrating journey. + Current.Value = allBeatmaps; + Schedule(() => Current.Value = filters.SingleOrDefault(f => f.Collection != null && f.Collection.ID == selectedItem?.ID) ?? filters[0]); // Trigger a re-filter if the current item was in the change set. if (selectedItem != null && changes != null) @@ -80,7 +86,9 @@ namespace osu.Game.Collections } } - private void currentChanged(ValueChangedEvent filter) + private Live? lastFiltered; + + private void selectionChanged(ValueChangedEvent filter) { // May be null during .Clear(). if (filter.NewValue == null) @@ -95,15 +103,20 @@ namespace osu.Game.Collections return; } + var newCollection = filter.NewValue?.Collection; + // This dropdown be weird. // We only care about filtering if the actual collection has changed. - if (filter.OldValue?.Collection != null || filter.NewValue?.Collection != null) + if (newCollection != lastFiltered) + { RequestFilter?.Invoke(); + lastFiltered = newCollection; + } } protected override LocalisableString GenerateItemText(CollectionFilterMenuItem item) => item.CollectionName; - protected sealed override DropdownHeader CreateHeader() => CreateCollectionHeader().With(d => d.SelectedItem.BindTarget = Current); + protected sealed override DropdownHeader CreateHeader() => CreateCollectionHeader(); protected sealed override DropdownMenu CreateMenu() => CreateCollectionMenu(); @@ -113,8 +126,6 @@ namespace osu.Game.Collections public class CollectionDropdownHeader : OsuDropdownHeader { - public readonly Bindable SelectedItem = new Bindable(); - public CollectionDropdownHeader() { Height = 25; @@ -130,14 +141,14 @@ namespace osu.Game.Collections MaxHeight = 200; } - protected override DrawableDropdownMenuItem CreateDrawableDropdownMenuItem(MenuItem item) => new CollectionDropdownMenuItem(item) + protected override DrawableDropdownMenuItem CreateDrawableDropdownMenuItem(MenuItem item) => new CollectionDropdownDrawableMenuItem(item) { BackgroundColourHover = HoverColour, BackgroundColourSelected = SelectionColour }; } - protected class CollectionDropdownMenuItem : OsuDropdownMenu.DrawableOsuDropdownMenuItem + protected class CollectionDropdownDrawableMenuItem : OsuDropdownMenu.DrawableOsuDropdownMenuItem { protected new CollectionFilterMenuItem Item => ((DropdownMenuItem)base.Item).Value; @@ -148,7 +159,7 @@ namespace osu.Game.Collections [Resolved] private IBindable beatmap { get; set; } = null!; - public CollectionDropdownMenuItem(MenuItem item) + public CollectionDropdownDrawableMenuItem(MenuItem item) : base(item) { } diff --git a/osu.Game/Collections/DeleteCollectionDialog.cs b/osu.Game/Collections/DeleteCollectionDialog.cs index 7594978870..f3f038a7f0 100644 --- a/osu.Game/Collections/DeleteCollectionDialog.cs +++ b/osu.Game/Collections/DeleteCollectionDialog.cs @@ -4,16 +4,17 @@ using System; using Humanizer; using osu.Framework.Graphics.Sprites; +using osu.Game.Database; using osu.Game.Overlays.Dialog; namespace osu.Game.Collections { public class DeleteCollectionDialog : PopupDialog { - public DeleteCollectionDialog(BeatmapCollection collection, Action deleteAction) + public DeleteCollectionDialog(Live collection, Action deleteAction) { HeaderText = "Confirm deletion of"; - BodyText = $"{collection.Name} ({"beatmap".ToQuantity(collection.BeatmapMD5Hashes.Count)})"; + BodyText = collection.PerformRead(c => $"{c.Name} ({"beatmap".ToQuantity(c.BeatmapMD5Hashes.Count)})"); Icon = FontAwesome.Regular.TrashAlt; diff --git a/osu.Game/Collections/DrawableCollectionList.cs b/osu.Game/Collections/DrawableCollectionList.cs index f376d18224..1639afd362 100644 --- a/osu.Game/Collections/DrawableCollectionList.cs +++ b/osu.Game/Collections/DrawableCollectionList.cs @@ -1,33 +1,51 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Diagnostics; using System.Linq; +using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Game.Database; using osu.Game.Graphics.Containers; using osuTK; +using Realms; namespace osu.Game.Collections { /// /// Visualises a list of s. /// - public class DrawableCollectionList : OsuRearrangeableListContainer + public class DrawableCollectionList : OsuRearrangeableListContainer> { private Scroll scroll = null!; protected override ScrollContainer CreateScrollContainer() => scroll = new Scroll(); - protected override FillFlowContainer> CreateListFillFlowContainer() => new Flow + [Resolved] + private RealmAccess realm { get; set; } = null!; + + protected override FillFlowContainer>> CreateListFillFlowContainer() => new Flow { DragActive = { BindTarget = DragActive } }; - // TODO: source from realm + protected override void LoadComplete() + { + base.LoadComplete(); - protected override OsuRearrangeableListItem CreateOsuDrawable(BeatmapCollection item) + realm.RegisterForNotifications(r => r.All(), collectionsChanged); + } + + private void collectionsChanged(IRealmCollection collections, ChangeSet? changes, Exception error) + { + Items.Clear(); + Items.AddRange(collections.AsEnumerable().Select(c => c.ToLive(realm))); + } + + protected override OsuRearrangeableListItem> CreateOsuDrawable(Live item) { if (item.ID == scroll.PlaceholderItem.Model.ID) return scroll.ReplacePlaceholder(); @@ -97,7 +115,7 @@ namespace osu.Game.Collections var previous = PlaceholderItem; placeholderContainer.Clear(false); - placeholderContainer.Add(PlaceholderItem = new DrawableCollectionListItem(new BeatmapCollection(), false)); + placeholderContainer.Add(PlaceholderItem = new DrawableCollectionListItem(new BeatmapCollection().ToLiveUnmanaged(), false)); return previous; } @@ -106,7 +124,7 @@ namespace osu.Game.Collections /// /// The flow of . Disables layout easing unless a drag is in progress. /// - private class Flow : FillFlowContainer> + private class Flow : FillFlowContainer>> { public readonly IBindable DragActive = new Bindable(); diff --git a/osu.Game/Collections/DrawableCollectionListItem.cs b/osu.Game/Collections/DrawableCollectionListItem.cs index 6093e69deb..d1e40f6262 100644 --- a/osu.Game/Collections/DrawableCollectionListItem.cs +++ b/osu.Game/Collections/DrawableCollectionListItem.cs @@ -3,12 +3,12 @@ using System; using osu.Framework.Allocation; -using osu.Framework.Bindables; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.UserInterface; using osu.Framework.Input.Events; using osu.Game.Database; using osu.Game.Graphics; @@ -23,52 +23,37 @@ namespace osu.Game.Collections /// /// Visualises a inside a . /// - public class DrawableCollectionListItem : OsuRearrangeableListItem + public class DrawableCollectionListItem : OsuRearrangeableListItem> { private const float item_height = 35; private const float button_width = item_height * 0.75f; - /// - /// Whether the currently exists inside realm. - /// - public IBindable IsCreated => isCreated; - - private readonly Bindable isCreated = new Bindable(); - /// /// Creates a new . /// /// The . /// Whether currently exists inside realm. - public DrawableCollectionListItem(BeatmapCollection item, bool isCreated) + public DrawableCollectionListItem(Live item, bool isCreated) : base(item) { - this.isCreated.Value = isCreated; - - ShowDragHandle.BindTo(this.isCreated); + ShowDragHandle.Value = item.IsManaged; } - protected override Drawable CreateContent() => new ItemContent(Model) - { - IsCreated = { BindTarget = isCreated } - }; + protected override Drawable CreateContent() => new ItemContent(Model); /// /// The main content of the . /// private class ItemContent : CircularContainer { - public readonly Bindable IsCreated = new Bindable(); + private readonly Live collection; - private readonly BeatmapCollection collection; - - private Container textBoxPaddingContainer = null!; private ItemTextBox textBox = null!; [Resolved] private RealmAccess realm { get; set; } = null!; - public ItemContent(BeatmapCollection collection) + public ItemContent(Live collection) { this.collection = collection; @@ -80,19 +65,20 @@ namespace osu.Game.Collections [BackgroundDependencyLoader] private void load() { - Children = new Drawable[] + Children = new[] { - new DeleteButton(collection) - { - Anchor = Anchor.CentreRight, - Origin = Anchor.CentreRight, - IsCreated = { BindTarget = IsCreated }, - IsTextBoxHovered = v => textBox.ReceivePositionalInputAt(v) - }, - textBoxPaddingContainer = new Container + collection.IsManaged + ? new DeleteButton(collection) + { + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreRight, + IsTextBoxHovered = v => textBox.ReceivePositionalInputAt(v) + } + : Empty(), + new Container { RelativeSizeAxes = Axes.Both, - Padding = new MarginPadding { Right = button_width }, + Padding = new MarginPadding { Right = collection.IsManaged ? button_width : 0 }, Children = new Drawable[] { textBox = new ItemTextBox @@ -100,7 +86,7 @@ namespace osu.Game.Collections RelativeSizeAxes = Axes.Both, Size = Vector2.One, CornerRadius = item_height / 2, - PlaceholderText = IsCreated.Value ? string.Empty : "Create a new collection" + PlaceholderText = collection.IsManaged ? string.Empty : "Create a new collection" }, } }, @@ -112,28 +98,18 @@ namespace osu.Game.Collections base.LoadComplete(); // Bind late, as the collection name may change externally while still loading. - textBox.Current.Value = collection.Name; - textBox.Current.BindValueChanged(_ => createNewCollection(), true); - - IsCreated.BindValueChanged(created => textBoxPaddingContainer.Padding = new MarginPadding { Right = created.NewValue ? button_width : 0 }, true); + textBox.Current.Value = collection.PerformRead(c => c.IsValid ? c.Name : string.Empty); + textBox.OnCommit += onCommit; } - private void createNewCollection() + private void onCommit(TextBox sender, bool newText) { - if (IsCreated.Value) - return; + if (collection.IsManaged) + collection.PerformWrite(c => c.Name = textBox.Current.Value); + else if (!string.IsNullOrEmpty(textBox.Current.Value)) + realm.Write(r => r.Add(new BeatmapCollection(textBox.Current.Value))); - if (string.IsNullOrEmpty(textBox.Current.Value)) - return; - - // Add the new collection and disable our placeholder. If all text is removed, the placeholder should not show back again. - realm.Write(r => r.Add(collection)); - textBox.PlaceholderText = string.Empty; - - // When this item changes from placeholder to non-placeholder (via changing containers), its textbox will lose focus, so it needs to be re-focused. - Schedule(() => GetContainingInputManager().ChangeFocus(textBox)); - - IsCreated.Value = true; + textBox.Text = string.Empty; } } @@ -151,22 +127,17 @@ namespace osu.Game.Collections public class DeleteButton : CompositeDrawable { - public readonly IBindable IsCreated = new Bindable(); - public Func IsTextBoxHovered = null!; [Resolved] private IDialogOverlay? dialogOverlay { get; set; } - [Resolved] - private RealmAccess realmAccess { get; set; } = null!; - - private readonly BeatmapCollection collection; + private readonly Live collection; private Drawable fadeContainer = null!; private Drawable background = null!; - public DeleteButton(BeatmapCollection collection) + public DeleteButton(Live collection) { this.collection = collection; RelativeSizeAxes = Axes.Y; @@ -200,12 +171,6 @@ namespace osu.Game.Collections }; } - protected override void LoadComplete() - { - base.LoadComplete(); - IsCreated.BindValueChanged(created => Alpha = created.NewValue ? 1 : 0, true); - } - public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => base.ReceivePositionalInputAt(screenSpacePos) && !IsTextBoxHovered(screenSpacePos); protected override bool OnHover(HoverEvent e) @@ -223,7 +188,7 @@ namespace osu.Game.Collections { background.FlashColour(Color4.White, 150); - if (collection.BeatmapMD5Hashes.Count == 0) + if (collection.PerformRead(c => c.BeatmapMD5Hashes.Count) == 0) deleteCollection(); else dialogOverlay?.Push(new DeleteCollectionDialog(collection, deleteCollection)); @@ -231,7 +196,7 @@ namespace osu.Game.Collections return true; } - private void deleteCollection() => realmAccess.Write(r => r.Remove(collection)); + private void deleteCollection() => collection.PerformWrite(c => c.Realm.Remove(c)); } } } diff --git a/osu.Game/Collections/ManageCollectionsDialog.cs b/osu.Game/Collections/ManageCollectionsDialog.cs index 721e0d632e..13737dbd78 100644 --- a/osu.Game/Collections/ManageCollectionsDialog.cs +++ b/osu.Game/Collections/ManageCollectionsDialog.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Graphics; @@ -23,7 +21,7 @@ namespace osu.Game.Collections private const double enter_duration = 500; private const double exit_duration = 200; - private AudioFilter lowPassFilter; + private AudioFilter lowPassFilter = null!; public ManageCollectionsDialog() { From 1669208a54a232dc2e097bc129b3839209be3b2a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 27 Jul 2022 23:19:00 +0900 Subject: [PATCH 125/278] Add migration of existing collections database --- osu.Game/Database/LegacyCollectionImporter.cs | 14 +++++------ osu.Game/Database/LegacyImportManager.cs | 2 +- osu.Game/Database/RealmAccess.cs | 25 ++++++++++++++++++- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/osu.Game/Database/LegacyCollectionImporter.cs b/osu.Game/Database/LegacyCollectionImporter.cs index bd32b8c446..4bb28bf731 100644 --- a/osu.Game/Database/LegacyCollectionImporter.cs +++ b/osu.Game/Database/LegacyCollectionImporter.cs @@ -7,8 +7,8 @@ using System.IO; using System.Linq; using System.Threading.Tasks; using osu.Framework.Logging; +using osu.Framework.Platform; using osu.Game.Collections; -using osu.Game.IO; using osu.Game.IO.Legacy; using osu.Game.Overlays.Notifications; @@ -27,14 +27,14 @@ namespace osu.Game.Database this.realm = realm; } - public Task GetAvailableCount(StableStorage stableStorage) + public Task GetAvailableCount(Storage storage) { - if (!stableStorage.Exists(database_name)) + if (!storage.Exists(database_name)) return Task.FromResult(0); return Task.Run(() => { - using (var stream = stableStorage.GetStream(database_name)) + using (var stream = storage.GetStream(database_name)) return readCollections(stream).Count; }); } @@ -42,9 +42,9 @@ namespace osu.Game.Database /// /// This is a temporary method and will likely be replaced by a full-fledged (and more correctly placed) migration process in the future. /// - public Task ImportFromStableAsync(StableStorage stableStorage) + public Task ImportFromStorage(Storage storage) { - if (!stableStorage.Exists(database_name)) + if (!storage.Exists(database_name)) { // This handles situations like when the user does not have a collections.db file Logger.Log($"No {database_name} available in osu!stable installation", LoggingTarget.Information, LogLevel.Error); @@ -53,7 +53,7 @@ namespace osu.Game.Database return Task.Run(async () => { - using (var stream = stableStorage.GetStream(database_name)) + using (var stream = storage.GetStream(database_name)) await Import(stream).ConfigureAwait(false); }); } diff --git a/osu.Game/Database/LegacyImportManager.cs b/osu.Game/Database/LegacyImportManager.cs index baa117fe07..96f4aaf67c 100644 --- a/osu.Game/Database/LegacyImportManager.cs +++ b/osu.Game/Database/LegacyImportManager.cs @@ -108,7 +108,7 @@ namespace osu.Game.Database importTasks.Add(new LegacySkinImporter(skins).ImportFromStableAsync(stableStorage)); if (content.HasFlagFast(StableContent.Collections)) - importTasks.Add(beatmapImportTask.ContinueWith(_ => new LegacyCollectionImporter(realmAccess).ImportFromStableAsync(stableStorage), TaskContinuationOptions.OnlyOnRanToCompletion)); + importTasks.Add(beatmapImportTask.ContinueWith(_ => new LegacyCollectionImporter(realmAccess).ImportFromStorage(stableStorage), TaskContinuationOptions.OnlyOnRanToCompletion)); if (content.HasFlagFast(StableContent.Scores)) importTasks.Add(beatmapImportTask.ContinueWith(_ => new LegacyScoreImporter(scores).ImportFromStableAsync(stableStorage), TaskContinuationOptions.OnlyOnRanToCompletion)); diff --git a/osu.Game/Database/RealmAccess.cs b/osu.Game/Database/RealmAccess.cs index a93fdea35b..6a0d4d34db 100644 --- a/osu.Game/Database/RealmAccess.cs +++ b/osu.Game/Database/RealmAccess.cs @@ -14,6 +14,7 @@ using System.Threading.Tasks; using osu.Framework; using osu.Framework.Allocation; using osu.Framework.Development; +using osu.Framework.Extensions; using osu.Framework.Input.Bindings; using osu.Framework.Logging; using osu.Framework.Platform; @@ -64,8 +65,9 @@ namespace osu.Game.Database /// 18 2022-07-19 Added OnlineMD5Hash and LastOnlineUpdate to BeatmapInfo. /// 19 2022-07-19 Added DateSubmitted and DateRanked to BeatmapSetInfo. /// 20 2022-07-21 Added LastAppliedDifficultyVersion to RulesetInfo, changed default value of BeatmapInfo.StarRating to -1. + /// 21 2022-07-27 Migrate collections to realm (BeatmapCollection). /// - private const int schema_version = 20; + private const int schema_version = 21; /// /// Lock object which is held during sections, blocking realm retrieval during blocking periods. @@ -790,6 +792,27 @@ namespace osu.Game.Database beatmap.StarRating = -1; break; + + case 21: + try + { + // Migrate collections from external file to inside realm. + // We use the "legacy" importer because that is how things were actually being saved out until now. + var legacyCollectionImporter = new LegacyCollectionImporter(this); + + if (legacyCollectionImporter.GetAvailableCount(storage).GetResultSafely() > 0) + { + legacyCollectionImporter.ImportFromStorage(storage); + storage.Delete("collection.db"); + } + } + catch (Exception e) + { + // can be removed 20221027 (just for initial safety). + Logger.Error(e, "Collections could not be migrated to realm. Please provide your \"collection.db\" to the dev team."); + } + + break; } } From 226eefcc5c0a87d26962b4c22b68b2e53211535e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 13:37:01 +0900 Subject: [PATCH 126/278] Add note about hash storage --- osu.Game/Collections/BeatmapCollection.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/osu.Game/Collections/BeatmapCollection.cs b/osu.Game/Collections/BeatmapCollection.cs index 2ffe17d9e6..ca5f8dbe53 100644 --- a/osu.Game/Collections/BeatmapCollection.cs +++ b/osu.Game/Collections/BeatmapCollection.cs @@ -26,6 +26,13 @@ namespace osu.Game.Collections /// /// The es of beatmaps contained by the collection. /// + /// + /// We store as hashes rather than references to s to allow collections to maintain + /// references to beatmaps even if they are removed. This helps with cases like importing collections before + /// importing the beatmaps they contain, or when sharing collections between users. + /// + /// This can probably change in the future as we build the system up. + /// public IList BeatmapMD5Hashes { get; } = null!; /// From ad482b8afcb23dedba8939b0ebaf7c960c4f5c25 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 13:48:15 +0900 Subject: [PATCH 127/278] Tidy up naming of collection dropdowns --- .../TestSceneManageCollectionsDialog.cs | 2 +- .../Navigation/TestSceneScreenNavigation.cs | 4 +-- .../SongSelect/TestSceneFilterControl.cs | 8 ++--- ...ilterDropdown.cs => CollectionDropdown.cs} | 33 +++++++++++-------- osu.Game/Overlays/Music/FilterControl.cs | 4 +-- ...own.cs => NowPlayingCollectionDropdown.cs} | 4 +-- osu.Game/Screens/Select/FilterControl.cs | 4 +-- 7 files changed, 33 insertions(+), 26 deletions(-) rename osu.Game/Collections/{CollectionFilterDropdown.cs => CollectionDropdown.cs} (89%) rename osu.Game/Overlays/Music/{CollectionDropdown.cs => NowPlayingCollectionDropdown.cs} (93%) diff --git a/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs b/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs index afcb511a6a..6a88ce1ba6 100644 --- a/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs +++ b/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs @@ -149,7 +149,7 @@ namespace osu.Game.Tests.Visual.Collections { AddStep("add dropdown", () => { - Add(new CollectionFilterDropdown + Add(new CollectionDropdown { Anchor = Anchor.TopRight, Origin = Anchor.TopRight, diff --git a/osu.Game.Tests/Visual/Navigation/TestSceneScreenNavigation.cs b/osu.Game.Tests/Visual/Navigation/TestSceneScreenNavigation.cs index a61352f954..58898d8386 100644 --- a/osu.Game.Tests/Visual/Navigation/TestSceneScreenNavigation.cs +++ b/osu.Game.Tests/Visual/Navigation/TestSceneScreenNavigation.cs @@ -74,14 +74,14 @@ namespace osu.Game.Tests.Visual.Navigation AddStep("set filter again", () => songSelect.ChildrenOfType().Single().Current.Value = "test"); AddStep("open collections dropdown", () => { - InputManager.MoveMouseTo(songSelect.ChildrenOfType().Single()); + InputManager.MoveMouseTo(songSelect.ChildrenOfType().Single()); InputManager.Click(MouseButton.Left); }); AddStep("press back once", () => InputManager.Click(MouseButton.Button1)); AddAssert("still at song select", () => Game.ScreenStack.CurrentScreen == songSelect); AddAssert("collections dropdown closed", () => songSelect - .ChildrenOfType().Single() + .ChildrenOfType().Single() .ChildrenOfType.DropdownMenu>().Single().State == MenuState.Closed); AddStep("press back a second time", () => InputManager.Click(MouseButton.Button1)); diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs index feb71def5d..a07bfaee2a 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs @@ -94,7 +94,7 @@ namespace osu.Game.Tests.Visual.SongSelect AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "1")))); AddStep("select collection", () => { - var dropdown = control.ChildrenOfType().Single(); + var dropdown = control.ChildrenOfType().Single(); dropdown.Current.Value = dropdown.ItemSource.ElementAt(1); }); @@ -210,7 +210,7 @@ namespace osu.Game.Tests.Visual.SongSelect private void assertCollectionHeaderDisplays(string collectionName, bool shouldDisplay = true) => AddAssert($"collection dropdown header displays '{collectionName}'", - () => shouldDisplay == (control.ChildrenOfType().Single().ChildrenOfType().First().Text == collectionName)); + () => shouldDisplay == (control.ChildrenOfType().Single().ChildrenOfType().First().Text == collectionName)); private void assertCollectionDropdownContains(string collectionName, bool shouldContain = true) => AddAssert($"collection dropdown {(shouldContain ? "contains" : "does not contain")} '{collectionName}'", @@ -222,7 +222,7 @@ namespace osu.Game.Tests.Visual.SongSelect private void addExpandHeaderStep() => AddStep("expand header", () => { - InputManager.MoveMouseTo(control.ChildrenOfType().Single()); + InputManager.MoveMouseTo(control.ChildrenOfType().Single()); InputManager.Click(MouseButton.Left); }); @@ -233,6 +233,6 @@ namespace osu.Game.Tests.Visual.SongSelect }); private IEnumerable.DropdownMenu.DrawableDropdownMenuItem> getCollectionDropdownItems() - => control.ChildrenOfType().Single().ChildrenOfType.DropdownMenu.DrawableDropdownMenuItem>(); + => control.ChildrenOfType().Single().ChildrenOfType.DropdownMenu.DrawableDropdownMenuItem>(); } } diff --git a/osu.Game/Collections/CollectionFilterDropdown.cs b/osu.Game/Collections/CollectionDropdown.cs similarity index 89% rename from osu.Game/Collections/CollectionFilterDropdown.cs rename to osu.Game/Collections/CollectionDropdown.cs index 790a23d2e5..197e0d1837 100644 --- a/osu.Game/Collections/CollectionFilterDropdown.cs +++ b/osu.Game/Collections/CollectionDropdown.cs @@ -21,9 +21,9 @@ using Realms; namespace osu.Game.Collections { /// - /// A dropdown to select the to filter beatmaps using. + /// A dropdown to select the collection to be used to filter results. /// - public class CollectionFilterDropdown : OsuDropdown + public class CollectionDropdown : OsuDropdown { /// /// Whether to show the "manage collections..." menu item in the dropdown. @@ -40,7 +40,9 @@ namespace osu.Game.Collections [Resolved] private RealmAccess realm { get; set; } = null!; - public CollectionFilterDropdown() + private IDisposable? realmSubscription; + + public CollectionDropdown() { ItemSource = filters; @@ -51,7 +53,7 @@ namespace osu.Game.Collections { base.LoadComplete(); - realm.RegisterForNotifications(r => r.All(), collectionsChanged); + realmSubscription = realm.RegisterForNotifications(r => r.All(), collectionsChanged); Current.BindValueChanged(selectionChanged); } @@ -114,6 +116,12 @@ namespace osu.Game.Collections } } + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + realmSubscription?.Dispose(); + } + protected override LocalisableString GenerateItemText(CollectionFilterMenuItem item) => item.CollectionName; protected sealed override DropdownHeader CreateHeader() => CreateCollectionHeader(); @@ -150,18 +158,19 @@ namespace osu.Game.Collections protected class CollectionDropdownDrawableMenuItem : OsuDropdownMenu.DrawableOsuDropdownMenuItem { - protected new CollectionFilterMenuItem Item => ((DropdownMenuItem)base.Item).Value; - private IconButton addOrRemoveButton = null!; private bool beatmapInCollection; + private readonly Live? collection; + [Resolved] private IBindable beatmap { get; set; } = null!; public CollectionDropdownDrawableMenuItem(MenuItem item) : base(item) { + collection = ((DropdownMenuItem)item).Value.Collection; } [BackgroundDependencyLoader] @@ -181,13 +190,11 @@ namespace osu.Game.Collections { base.LoadComplete(); - if (Item.Collection != null) + if (collection != null) { beatmap.BindValueChanged(_ => { - Debug.Assert(Item.Collection != null); - - beatmapInCollection = Item.Collection.PerformRead(c => c.BeatmapMD5Hashes.Contains(beatmap.Value.BeatmapInfo.MD5Hash)); + beatmapInCollection = collection.PerformRead(c => c.BeatmapMD5Hashes.Contains(beatmap.Value.BeatmapInfo.MD5Hash)); addOrRemoveButton.Enabled.Value = !beatmap.IsDefault; addOrRemoveButton.Icon = beatmapInCollection ? FontAwesome.Solid.MinusSquare : FontAwesome.Solid.PlusSquare; @@ -220,7 +227,7 @@ namespace osu.Game.Collections private void updateButtonVisibility() { - if (Item.Collection == null) + if (collection == null) addOrRemoveButton.Alpha = 0; else addOrRemoveButton.Alpha = IsHovered || IsPreSelected || beatmapInCollection ? 1 : 0; @@ -228,9 +235,9 @@ namespace osu.Game.Collections private void addOrRemove() { - Debug.Assert(Item.Collection != null); + Debug.Assert(collection != null); - Item.Collection.PerformWrite(c => + collection.PerformWrite(c => { if (!c.BeatmapMD5Hashes.Remove(beatmap.Value.BeatmapInfo.MD5Hash)) c.BeatmapMD5Hashes.Add(beatmap.Value.BeatmapInfo.MD5Hash); diff --git a/osu.Game/Overlays/Music/FilterControl.cs b/osu.Game/Overlays/Music/FilterControl.cs index eb12a62864..ffa50c3a35 100644 --- a/osu.Game/Overlays/Music/FilterControl.cs +++ b/osu.Game/Overlays/Music/FilterControl.cs @@ -18,7 +18,7 @@ namespace osu.Game.Overlays.Music public Action FilterChanged; public readonly FilterTextBox Search; - private readonly CollectionDropdown collectionDropdown; + private readonly NowPlayingCollectionDropdown collectionDropdown; public FilterControl() { @@ -36,7 +36,7 @@ namespace osu.Game.Overlays.Music RelativeSizeAxes = Axes.X, Height = 40, }, - collectionDropdown = new CollectionDropdown { RelativeSizeAxes = Axes.X } + collectionDropdown = new NowPlayingCollectionDropdown { RelativeSizeAxes = Axes.X } }, }, }; diff --git a/osu.Game/Overlays/Music/CollectionDropdown.cs b/osu.Game/Overlays/Music/NowPlayingCollectionDropdown.cs similarity index 93% rename from osu.Game/Overlays/Music/CollectionDropdown.cs rename to osu.Game/Overlays/Music/NowPlayingCollectionDropdown.cs index c1ba16788e..635a2e5044 100644 --- a/osu.Game/Overlays/Music/CollectionDropdown.cs +++ b/osu.Game/Overlays/Music/NowPlayingCollectionDropdown.cs @@ -15,9 +15,9 @@ using osu.Game.Graphics; namespace osu.Game.Overlays.Music { /// - /// A for use in the . + /// A for use in the . /// - public class CollectionDropdown : CollectionFilterDropdown + public class NowPlayingCollectionDropdown : CollectionDropdown { protected override bool ShowManageCollectionsItem => false; diff --git a/osu.Game/Screens/Select/FilterControl.cs b/osu.Game/Screens/Select/FilterControl.cs index f07817d5dc..ae82285fba 100644 --- a/osu.Game/Screens/Select/FilterControl.cs +++ b/osu.Game/Screens/Select/FilterControl.cs @@ -41,7 +41,7 @@ namespace osu.Game.Screens.Select private SeekLimitedSearchTextBox searchTextBox; - private CollectionFilterDropdown collectionDropdown; + private CollectionDropdown collectionDropdown; public FilterCriteria CreateCriteria() { @@ -179,7 +179,7 @@ namespace osu.Game.Screens.Select RelativeSizeAxes = Axes.Both, Width = 0.48f, }, - collectionDropdown = new CollectionFilterDropdown + collectionDropdown = new CollectionDropdown { Anchor = Anchor.TopRight, Origin = Anchor.TopRight, From da0646789120f33153946618d0ed2e414171bb17 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 13:50:19 +0900 Subject: [PATCH 128/278] Add missing realm subscription cleanup --- osu.Game/Collections/DrawableCollectionList.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/osu.Game/Collections/DrawableCollectionList.cs b/osu.Game/Collections/DrawableCollectionList.cs index 1639afd362..8546ba53c2 100644 --- a/osu.Game/Collections/DrawableCollectionList.cs +++ b/osu.Game/Collections/DrawableCollectionList.cs @@ -20,13 +20,15 @@ namespace osu.Game.Collections /// public class DrawableCollectionList : OsuRearrangeableListContainer> { - private Scroll scroll = null!; - protected override ScrollContainer CreateScrollContainer() => scroll = new Scroll(); [Resolved] private RealmAccess realm { get; set; } = null!; + private Scroll scroll = null!; + + private IDisposable? realmSubscription; + protected override FillFlowContainer>> CreateListFillFlowContainer() => new Flow { DragActive = { BindTarget = DragActive } @@ -36,7 +38,7 @@ namespace osu.Game.Collections { base.LoadComplete(); - realm.RegisterForNotifications(r => r.All(), collectionsChanged); + realmSubscription = realm.RegisterForNotifications(r => r.All(), collectionsChanged); } private void collectionsChanged(IRealmCollection collections, ChangeSet? changes, Exception error) @@ -53,6 +55,12 @@ namespace osu.Game.Collections return new DrawableCollectionListItem(item, true); } + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + realmSubscription?.Dispose(); + } + /// /// The scroll container for this . /// Contains the main flow of and attaches a placeholder item to the end of the list. From 72961ec3362168e058f16c45f69e1e1f4c7bd5b8 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Thu, 28 Jul 2022 08:04:53 +0300 Subject: [PATCH 129/278] Flip method parameters to make sense See https://github.com/ppy/osu/pull/19407/commits/537f64c75ecd9608b7f8f2b0e184dc18ba4bfa58#r931785228 --- osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs b/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs index 9e5d997353..c793ed4937 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs @@ -167,6 +167,7 @@ namespace osu.Game.Rulesets.Osu.Mods public override void ApplyToBeatmap(IBeatmap beatmap) { Seed.Value ??= RNG.Next(); + var rng = new Random(Seed.Value.Value); var osuBeatmap = (OsuBeatmap)beatmap; @@ -185,11 +186,11 @@ namespace osu.Game.Rulesets.Osu.Mods return (OsuHitObject)newCircle; }).ToList(); - addHitSamples(originalHitObjects, hitObjects); + addHitSamples(hitObjects, originalHitObjects); - fixComboInfo(originalHitObjects, hitObjects); + fixComboInfo(hitObjects, originalHitObjects); - randomizeCirclePos(rng, hitObjects); + randomizeCirclePos(hitObjects, rng); osuBeatmap.HitObjects = hitObjects; @@ -224,7 +225,7 @@ namespace osu.Game.Rulesets.Osu.Mods return beats; } - private void addHitSamples(List originalHitObjects, IEnumerable hitObjects) + private void addHitSamples(IEnumerable hitObjects, List originalHitObjects) { foreach (var obj in hitObjects) { @@ -236,7 +237,7 @@ namespace osu.Game.Rulesets.Osu.Mods } } - private void fixComboInfo(List originalHitObjects, List hitObjects) + private void fixComboInfo(List hitObjects, List originalHitObjects) { // Copy combo indices from an original object at the same time or from the closest preceding object // (Objects lying between two combos are assumed to belong to the preceding combo) @@ -270,7 +271,7 @@ namespace osu.Game.Rulesets.Osu.Mods } } - private void randomizeCirclePos(Random rng, IReadOnlyList hitObjects) + private void randomizeCirclePos(IReadOnlyList hitObjects, Random rng) { if (hitObjects.Count == 0) return; From 392cb352cc71da8b0f82aa0877ea6a7febfc54b1 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 14:07:42 +0900 Subject: [PATCH 130/278] Force alphabetical ordering for now --- osu.Game/Collections/CollectionDropdown.cs | 2 +- osu.Game/Collections/DrawableCollectionList.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Collections/CollectionDropdown.cs b/osu.Game/Collections/CollectionDropdown.cs index 197e0d1837..43a4d90aa8 100644 --- a/osu.Game/Collections/CollectionDropdown.cs +++ b/osu.Game/Collections/CollectionDropdown.cs @@ -53,7 +53,7 @@ namespace osu.Game.Collections { base.LoadComplete(); - realmSubscription = realm.RegisterForNotifications(r => r.All(), collectionsChanged); + realmSubscription = realm.RegisterForNotifications(r => r.All().OrderBy(c => c.Name), collectionsChanged); Current.BindValueChanged(selectionChanged); } diff --git a/osu.Game/Collections/DrawableCollectionList.cs b/osu.Game/Collections/DrawableCollectionList.cs index 8546ba53c2..0f4362fff3 100644 --- a/osu.Game/Collections/DrawableCollectionList.cs +++ b/osu.Game/Collections/DrawableCollectionList.cs @@ -38,7 +38,7 @@ namespace osu.Game.Collections { base.LoadComplete(); - realmSubscription = realm.RegisterForNotifications(r => r.All(), collectionsChanged); + realmSubscription = realm.RegisterForNotifications(r => r.All().OrderBy(c => c.Name), collectionsChanged); } private void collectionsChanged(IRealmCollection collections, ChangeSet? changes, Exception error) From ca6857447345d4dc35aadeba1241f91b63dcc645 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 14:35:27 +0900 Subject: [PATCH 131/278] Make `NotificationOverlay` dependency optional in `CollectionSettings` --- .../Settings/Sections/Maintenance/CollectionsSettings.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/CollectionsSettings.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/CollectionsSettings.cs index 498859db46..5a91213eb8 100644 --- a/osu.Game/Overlays/Settings/Sections/Maintenance/CollectionsSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Maintenance/CollectionsSettings.cs @@ -20,7 +20,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance private RealmAccess realm { get; set; } = null!; [Resolved] - private INotificationOverlay notificationOverlay { get; set; } = null!; + private INotificationOverlay? notificationOverlay { get; set; } [BackgroundDependencyLoader] private void load(LegacyImportManager? legacyImportManager, IDialogOverlay? dialogOverlay) @@ -51,7 +51,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance private void deleteAllCollections() { realm.Write(r => r.RemoveAll()); - notificationOverlay.Post(new ProgressCompletionNotification { Text = "Deleted all collections!" }); + notificationOverlay?.Post(new ProgressCompletionNotification { Text = "Deleted all collections!" }); } } } From 2ae5a34c0e3ca9cca42b2880e5f9c3300a40a2d9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 15:02:58 +0900 Subject: [PATCH 132/278] Add test coverage of beatmap updates transferring collection hashes --- .../Database/BeatmapImporterUpdateTests.cs | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs b/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs index a82386fd51..90648c616e 100644 --- a/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs +++ b/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs @@ -9,6 +9,7 @@ using System.Linq.Expressions; using NUnit.Framework; using osu.Framework.Allocation; using osu.Game.Beatmaps; +using osu.Game.Collections; using osu.Game.Database; using osu.Game.Models; using osu.Game.Overlays.Notifications; @@ -400,6 +401,122 @@ namespace osu.Game.Tests.Database }); } + /// + /// If all difficulties in the original beatmap set are in a collection, presume the user also wants new difficulties added. + /// + [TestCase(false)] + [TestCase(true)] + public void TestCollectionTransferNewBeatmap(bool allOriginalBeatmapsInCollection) + { + RunTestWithRealmAsync(async (realm, storage) => + { + var importer = new BeatmapImporter(storage, realm); + using var rulesets = new RealmRulesetStore(realm, storage); + + using var __ = getBeatmapArchive(out string pathOriginal); + using var _ = getBeatmapArchiveWithModifications(out string pathMissingOneBeatmap, directory => + { + // remove one difficulty before first import + directory.GetFiles("*.osu").First().Delete(); + }); + + var importBeforeUpdate = await importer.Import(new ImportTask(pathMissingOneBeatmap)); + + Assert.That(importBeforeUpdate, Is.Not.Null); + Debug.Assert(importBeforeUpdate != null); + + int beatmapsToAddToCollection = 0; + + importBeforeUpdate.PerformWrite(s => + { + var beatmapCollection = s.Realm.Add(new BeatmapCollection("test collection")); + beatmapsToAddToCollection = s.Beatmaps.Count - (allOriginalBeatmapsInCollection ? 0 : 1); + + for (int i = 0; i < beatmapsToAddToCollection; i++) + beatmapCollection.BeatmapMD5Hashes.Add(s.Beatmaps[i].MD5Hash); + }); + + // Second import matches first but contains one extra .osu file. + var importAfterUpdate = await importer.ImportAsUpdate(new ProgressNotification(), new ImportTask(pathOriginal), importBeforeUpdate.Value); + + Assert.That(importAfterUpdate, Is.Not.Null); + Debug.Assert(importAfterUpdate != null); + + importAfterUpdate.PerformRead(updated => + { + string[] hashes = updated.Realm.All().Single().BeatmapMD5Hashes.ToArray(); + + if (allOriginalBeatmapsInCollection) + { + Assert.That(updated.Beatmaps.Count, Is.EqualTo(beatmapsToAddToCollection + 1)); + Assert.That(hashes, Has.Length.EqualTo(updated.Beatmaps.Count)); + } + else + { + // Collection contains one less than the original beatmap, and two less after update (new difficulty included). + Assert.That(updated.Beatmaps.Count, Is.EqualTo(beatmapsToAddToCollection + 2)); + Assert.That(hashes, Has.Length.EqualTo(beatmapsToAddToCollection)); + } + }); + }); + } + + /// + /// If a difficulty in the original beatmap set is modified, the updated version should remain in any collections it was in. + /// + [Test] + public void TestCollectionTransferModifiedBeatmap() + { + RunTestWithRealmAsync(async (realm, storage) => + { + var importer = new BeatmapImporter(storage, realm); + using var rulesets = new RealmRulesetStore(realm, storage); + + using var __ = getBeatmapArchive(out string pathOriginal); + using var _ = getBeatmapArchiveWithModifications(out string pathModified, directory => + { + // Modify one .osu file with different content. + var firstOsuFile = directory.GetFiles("*[Hard]*.osu").First(); + + string existingContent = File.ReadAllText(firstOsuFile.FullName); + + File.WriteAllText(firstOsuFile.FullName, existingContent + "\n# I am new content"); + }); + + var importBeforeUpdate = await importer.Import(new ImportTask(pathOriginal)); + + Assert.That(importBeforeUpdate, Is.Not.Null); + Debug.Assert(importBeforeUpdate != null); + + string originalHash = string.Empty; + + importBeforeUpdate.PerformWrite(s => + { + var beatmapCollection = s.Realm.Add(new BeatmapCollection("test collection")); + originalHash = s.Beatmaps.Single(b => b.DifficultyName == "Hard").MD5Hash; + + beatmapCollection.BeatmapMD5Hashes.Add(originalHash); + }); + + // Second import matches first but contains one extra .osu file. + var importAfterUpdate = await importer.ImportAsUpdate(new ProgressNotification(), new ImportTask(pathModified), importBeforeUpdate.Value); + + Assert.That(importAfterUpdate, Is.Not.Null); + Debug.Assert(importAfterUpdate != null); + + importAfterUpdate.PerformRead(updated => + { + string[] hashes = updated.Realm.All().Single().BeatmapMD5Hashes.ToArray(); + string updatedHash = updated.Beatmaps.Single(b => b.DifficultyName == "Hard").MD5Hash; + + Assert.That(hashes, Has.Length.EqualTo(1)); + Assert.That(hashes.First(), Is.EqualTo(updatedHash)); + + Assert.That(updatedHash, Is.Not.EqualTo(originalHash)); + }); + }); + } + private static void checkCount(RealmAccess realm, int expected, Expression>? condition = null) where T : RealmObject { var query = realm.Realm.All(); From 2209afd0e8c82405701b8b6807d9a280cbf1aacc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 15:03:08 +0900 Subject: [PATCH 133/278] Mark `Live` methods as `InstantHandleAttribute` --- osu.Game/Database/Live.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/osu.Game/Database/Live.cs b/osu.Game/Database/Live.cs index e9f99e1e44..52e1d420f7 100644 --- a/osu.Game/Database/Live.cs +++ b/osu.Game/Database/Live.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using JetBrains.Annotations; namespace osu.Game.Database { @@ -18,19 +19,19 @@ namespace osu.Game.Database /// Perform a read operation on this live object. /// /// The action to perform. - public abstract void PerformRead(Action perform); + public abstract void PerformRead([InstantHandle] Action perform); /// /// Perform a read operation on this live object. /// /// The action to perform. - public abstract TReturn PerformRead(Func perform); + public abstract TReturn PerformRead([InstantHandle] Func perform); /// /// Perform a write operation on this live object. /// /// The action to perform. - public abstract void PerformWrite(Action perform); + public abstract void PerformWrite([InstantHandle] Action perform); /// /// Whether this instance is tracking data which is managed by the database backing. From 070f56c30ce0ce51b3d30781b36fca5bf64e52a1 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 15:03:23 +0900 Subject: [PATCH 134/278] Add collection transfer logic to beatmap import-as-update flow --- osu.Game/Beatmaps/BeatmapImporter.cs | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/osu.Game/Beatmaps/BeatmapImporter.cs b/osu.Game/Beatmaps/BeatmapImporter.cs index ef0e76234a..d1f7a5c6a8 100644 --- a/osu.Game/Beatmaps/BeatmapImporter.cs +++ b/osu.Game/Beatmaps/BeatmapImporter.cs @@ -14,6 +14,7 @@ using osu.Framework.Logging; using osu.Framework.Platform; using osu.Framework.Testing; using osu.Game.Beatmaps.Formats; +using osu.Game.Collections; using osu.Game.Database; using osu.Game.Extensions; using osu.Game.IO; @@ -71,6 +72,8 @@ namespace osu.Game.Beatmaps // Transfer local values which should be persisted across a beatmap update. updated.DateAdded = original.DateAdded; + transferCollectionReferences(realm, original, updated); + foreach (var beatmap in original.Beatmaps.ToArray()) { var updatedBeatmap = updated.Beatmaps.FirstOrDefault(b => b.Hash == beatmap.Hash); @@ -112,6 +115,40 @@ namespace osu.Game.Beatmaps return first; } + private static void transferCollectionReferences(Realm realm, BeatmapSetInfo original, BeatmapSetInfo updated) + { + // First check if every beatmap in the original set is in any collections. + // In this case, we will assume they also want any newly added difficulties added to the collection. + foreach (var c in realm.All()) + { + if (original.Beatmaps.Select(b => b.MD5Hash).All(c.BeatmapMD5Hashes.Contains)) + { + foreach (var b in original.Beatmaps) + c.BeatmapMD5Hashes.Remove(b.MD5Hash); + + foreach (var b in updated.Beatmaps) + c.BeatmapMD5Hashes.Add(b.MD5Hash); + } + } + + // Handle collections using permissive difficulty name to track difficulties. + foreach (var originalBeatmap in original.Beatmaps) + { + var updatedBeatmap = updated.Beatmaps.FirstOrDefault(b => b.DifficultyName == originalBeatmap.DifficultyName); + + if (updatedBeatmap == null) + continue; + + var collections = realm.All().AsEnumerable().Where(c => c.BeatmapMD5Hashes.Contains(originalBeatmap.MD5Hash)); + + foreach (var c in collections) + { + c.BeatmapMD5Hashes.Remove(originalBeatmap.MD5Hash); + c.BeatmapMD5Hashes.Add(updatedBeatmap.MD5Hash); + } + } + } + protected override bool ShouldDeleteArchive(string path) => Path.GetExtension(path).ToLowerInvariant() == ".osz"; protected override void Populate(BeatmapSetInfo beatmapSet, ArchiveReader? archive, Realm realm, CancellationToken cancellationToken = default) From 485d140a218fa92d5b800be9997104f71c831494 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 15:15:41 +0900 Subject: [PATCH 135/278] Add realm refresh calls to fix intermittent test failures on new update tests --- .../Database/BeatmapImporterUpdateTests.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs b/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs index fdc9f2569d..81baeddbd7 100644 --- a/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs +++ b/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs @@ -51,6 +51,8 @@ namespace osu.Game.Tests.Database Assert.That(importBeforeUpdate, Is.Not.Null); Debug.Assert(importBeforeUpdate != null); + realm.Run(r => r.Refresh()); + checkCount(realm, 1, s => !s.DeletePending); Assert.That(importBeforeUpdate.Value.Beatmaps, Has.Count.EqualTo(count_beatmaps - 1)); @@ -60,6 +62,8 @@ namespace osu.Game.Tests.Database Assert.That(importAfterUpdate, Is.Not.Null); Debug.Assert(importAfterUpdate != null); + realm.Run(r => r.Refresh()); + checkCount(realm, count_beatmaps); checkCount(realm, count_beatmaps); checkCount(realm, 1); @@ -103,6 +107,8 @@ namespace osu.Game.Tests.Database beatmap.ResetOnlineInfo(); }); + realm.Run(r => r.Refresh()); + checkCount(realm, 1, s => !s.DeletePending); Assert.That(importBeforeUpdate.Value.Beatmaps, Has.Count.EqualTo(count_beatmaps - 1)); @@ -112,6 +118,8 @@ namespace osu.Game.Tests.Database Assert.That(importAfterUpdate, Is.Not.Null); Debug.Assert(importAfterUpdate != null); + realm.Run(r => r.Refresh()); + checkCount(realm, count_beatmaps); checkCount(realm, count_beatmaps); checkCount(realm, 1); @@ -148,6 +156,8 @@ namespace osu.Game.Tests.Database Assert.That(importBeforeUpdate, Is.Not.Null); Debug.Assert(importBeforeUpdate != null); + realm.Run(r => r.Refresh()); + checkCount(realm, 1, s => !s.DeletePending); Assert.That(importBeforeUpdate.Value.Beatmaps, Has.Count.EqualTo(count_beatmaps)); @@ -161,6 +171,8 @@ namespace osu.Game.Tests.Database Assert.That(importBeforeUpdate.Value.Beatmaps, Has.Count.EqualTo(1)); Assert.That(importAfterUpdate.Value.Beatmaps, Has.Count.EqualTo(count_beatmaps)); + realm.Run(r => r.Refresh()); + checkCount(realm, count_beatmaps + 1); checkCount(realm, count_beatmaps + 1); @@ -198,6 +210,8 @@ namespace osu.Game.Tests.Database Assert.That(importAfterUpdate, Is.Not.Null); Debug.Assert(importAfterUpdate != null); + realm.Run(r => r.Refresh()); + checkCount(realm, count_beatmaps); checkCount(realm, count_beatmaps); checkCount(realm, 2); @@ -234,6 +248,8 @@ namespace osu.Game.Tests.Database var importAfterUpdate = await importer.ImportAsUpdate(new ProgressNotification(), new ImportTask(pathEmpty), importBeforeUpdate.Value); Assert.That(importAfterUpdate, Is.Null); + realm.Run(r => r.Refresh()); + checkCount(realm, 1); checkCount(realm, count_beatmaps); checkCount(realm, count_beatmaps); @@ -263,6 +279,8 @@ namespace osu.Game.Tests.Database Assert.That(importAfterUpdate, Is.Not.Null); Debug.Assert(importAfterUpdate != null); + realm.Run(r => r.Refresh()); + checkCount(realm, 1); checkCount(realm, count_beatmaps); checkCount(realm, count_beatmaps); @@ -307,6 +325,8 @@ namespace osu.Game.Tests.Database s.Realm.Add(new ScoreInfo(beatmapInfo, s.Realm.All().First(), new RealmUser())); }); + realm.Run(r => r.Refresh()); + checkCount(realm, 1); var importAfterUpdate = await importer.ImportAsUpdate(new ProgressNotification(), new ImportTask(pathMissingOneBeatmap), importBeforeUpdate.Value); @@ -314,6 +334,8 @@ namespace osu.Game.Tests.Database Assert.That(importAfterUpdate, Is.Not.Null); Debug.Assert(importAfterUpdate != null); + realm.Run(r => r.Refresh()); + checkCount(realm, count_beatmaps); checkCount(realm, count_beatmaps); checkCount(realm, 2); @@ -348,6 +370,8 @@ namespace osu.Game.Tests.Database s.Realm.Add(new ScoreInfo(beatmapInfo, s.Realm.All().First(), new RealmUser())); }); + realm.Run(r => r.Refresh()); + checkCount(realm, 1); using var _ = getBeatmapArchiveWithModifications(out string pathModified, directory => @@ -365,6 +389,8 @@ namespace osu.Game.Tests.Database Assert.That(importAfterUpdate, Is.Not.Null); Debug.Assert(importAfterUpdate != null); + realm.Run(r => r.Refresh()); + checkCount(realm, count_beatmaps + 1); checkCount(realm, count_beatmaps + 1); checkCount(realm, 2); From 67c44552cb25f00ae7b46d87fb811956b5e4902b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 15:18:04 +0900 Subject: [PATCH 136/278] Add realm `Refresh` calls to ensure tests are stable --- osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs b/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs index 90648c616e..07bd08d326 100644 --- a/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs +++ b/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs @@ -444,6 +444,8 @@ namespace osu.Game.Tests.Database importAfterUpdate.PerformRead(updated => { + updated.Realm.Refresh(); + string[] hashes = updated.Realm.All().Single().BeatmapMD5Hashes.ToArray(); if (allOriginalBeatmapsInCollection) @@ -506,6 +508,8 @@ namespace osu.Game.Tests.Database importAfterUpdate.PerformRead(updated => { + updated.Realm.Refresh(); + string[] hashes = updated.Realm.All().Single().BeatmapMD5Hashes.ToArray(); string updatedHash = updated.Beatmaps.Single(b => b.DifficultyName == "Hard").MD5Hash; From 8ac886a247c9cb1d25d8eba6c8048b6654561d2f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 15:20:25 +0900 Subject: [PATCH 137/278] Update test to account for sort order --- .../Visual/Collections/TestSceneManageCollectionsDialog.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs b/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs index 6a88ce1ba6..13393254a6 100644 --- a/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs +++ b/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs @@ -253,9 +253,14 @@ namespace osu.Game.Tests.Visual.Collections }); }); + assertCollectionName(0, "1"); + assertCollectionName(1, "1"); + AddStep("change first collection name", () => Realm.Write(_ => first.Name = "First")); - assertCollectionName(0, "First"); + // Item will have moved due to alphabetical sorting. + assertCollectionName(0, "2"); + assertCollectionName(1, "First"); } [Test] From 452d82f29239337af44a287e3b14d4e61730496f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 15:41:28 +0900 Subject: [PATCH 138/278] Add more comprehensive xmldoc for beatmap model classes --- osu.Game/Beatmaps/Beatmap.cs | 3 --- osu.Game/Beatmaps/BeatmapInfo.cs | 6 +++++- osu.Game/Beatmaps/BeatmapMetadata.cs | 11 +++++++++++ osu.Game/Beatmaps/BeatmapSetInfo.cs | 3 +++ osu.Game/Beatmaps/IBeatmap.cs | 7 +++++++ osu.Game/Beatmaps/IWorkingBeatmap.cs | 7 ++++++- 6 files changed, 32 insertions(+), 5 deletions(-) diff --git a/osu.Game/Beatmaps/Beatmap.cs b/osu.Game/Beatmaps/Beatmap.cs index c499bccb68..2d02fb6200 100644 --- a/osu.Game/Beatmaps/Beatmap.cs +++ b/osu.Game/Beatmaps/Beatmap.cs @@ -14,9 +14,6 @@ using osu.Game.IO.Serialization.Converters; namespace osu.Game.Beatmaps { - /// - /// A Beatmap containing converted HitObjects. - /// public class Beatmap : IBeatmap where T : HitObject { diff --git a/osu.Game/Beatmaps/BeatmapInfo.cs b/osu.Game/Beatmaps/BeatmapInfo.cs index 66c1995c8b..f368f369ae 100644 --- a/osu.Game/Beatmaps/BeatmapInfo.cs +++ b/osu.Game/Beatmaps/BeatmapInfo.cs @@ -20,8 +20,12 @@ using Realms; namespace osu.Game.Beatmaps { /// - /// A single beatmap difficulty. + /// A realm model containing metadata for a single beatmap difficulty. + /// This should generally include anything which is required to be filtered on at song select, or anything pertaining to storage of beatmaps in the client. /// + /// + /// There are some legacy fields in this model which are not persisted to realm. These are isolated in a code region within the class and should eventually be migrated to `Beatmap`. + /// [ExcludeFromDynamicCompile] [Serializable] [MapTo("Beatmap")] diff --git a/osu.Game/Beatmaps/BeatmapMetadata.cs b/osu.Game/Beatmaps/BeatmapMetadata.cs index feb9d34f44..f645d914b1 100644 --- a/osu.Game/Beatmaps/BeatmapMetadata.cs +++ b/osu.Game/Beatmaps/BeatmapMetadata.cs @@ -12,6 +12,17 @@ using Realms; namespace osu.Game.Beatmaps { + /// + /// A realm model containing metadata for a beatmap. + /// + /// + /// This is currently stored against each beatmap difficulty, even when it is duplicated. + /// It is also provided via for convenience and historical purposes. + /// A future effort could see this converted to an or potentially de-duped + /// and shared across multiple difficulties in the same set, if required. + /// + /// Note that difficulty name is not stored in this metadata but in . + /// [ExcludeFromDynamicCompile] [Serializable] [MapTo("BeatmapMetadata")] diff --git a/osu.Game/Beatmaps/BeatmapSetInfo.cs b/osu.Game/Beatmaps/BeatmapSetInfo.cs index b404f0b34d..7f65d1291d 100644 --- a/osu.Game/Beatmaps/BeatmapSetInfo.cs +++ b/osu.Game/Beatmaps/BeatmapSetInfo.cs @@ -14,6 +14,9 @@ using Realms; namespace osu.Game.Beatmaps { + /// + /// A realm model containing metadata for a beatmap set (containing multiple ). + /// [ExcludeFromDynamicCompile] [MapTo("BeatmapSet")] public class BeatmapSetInfo : RealmObject, IHasGuidPrimaryKey, IHasRealmFiles, ISoftDelete, IEquatable, IBeatmapSetInfo diff --git a/osu.Game/Beatmaps/IBeatmap.cs b/osu.Game/Beatmaps/IBeatmap.cs index 25b147c267..0e892b6581 100644 --- a/osu.Game/Beatmaps/IBeatmap.cs +++ b/osu.Game/Beatmaps/IBeatmap.cs @@ -11,6 +11,10 @@ using osu.Game.Rulesets.Scoring; namespace osu.Game.Beatmaps { + /// + /// A materialised beatmap. + /// Generally this interface will be implemented alongside , which exposes the ruleset-typed hit objects. + /// public interface IBeatmap { /// @@ -65,6 +69,9 @@ namespace osu.Game.Beatmaps IBeatmap Clone(); } + /// + /// A materialised beatmap containing converted HitObjects. + /// public interface IBeatmap : IBeatmap where T : HitObject { diff --git a/osu.Game/Beatmaps/IWorkingBeatmap.cs b/osu.Game/Beatmaps/IWorkingBeatmap.cs index 2188bd6a2b..548341cc77 100644 --- a/osu.Game/Beatmaps/IWorkingBeatmap.cs +++ b/osu.Game/Beatmaps/IWorkingBeatmap.cs @@ -18,7 +18,12 @@ using osu.Game.Storyboards; namespace osu.Game.Beatmaps { /// - /// Provides access to the multiple resources offered by a beatmap model (textures, skins, playable beatmaps etc.) + /// A more expensive representation of a beatmap which allows access to various associated resources. + /// - Access textures and other resources via . + /// - Access the storyboard via . + /// - Access a local skin via . + /// - Access the track via (and then for subsequent accesses). + /// - Create a playable via . /// public interface IWorkingBeatmap { From 6bf293e130b98c35f7c896d8f5e174b0b436f04b Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Thu, 28 Jul 2022 15:45:32 +0900 Subject: [PATCH 139/278] Fix managed object reused between test runs --- osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs index a07bfaee2a..d3b3238bb0 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs @@ -78,9 +78,9 @@ namespace osu.Game.Tests.Visual.SongSelect [Test] public void TestCollectionRemovedFromDropdown() { - var first = new BeatmapCollection(name: "1"); + BeatmapCollection first = null!; - AddStep("add collection", () => Realm.Write(r => r.Add(first))); + AddStep("add collection", () => Realm.Write(r => r.Add(first = new BeatmapCollection(name: "1")))); AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "2")))); AddStep("remove collection", () => Realm.Write(r => r.Remove(first))); From 525e4a20193a8f5d644595fecddea0f9ef516f97 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 15:51:18 +0900 Subject: [PATCH 140/278] Fix crash in `DrawableRoomPlaylistItem` context menu creation due to incorrect enumeration casting --- osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs index 492bb8ada5..8dccc3d82f 100644 --- a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs +++ b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs @@ -499,7 +499,7 @@ namespace osu.Game.Screens.OnlinePlay { if (beatmaps.QueryBeatmap(b => b.OnlineID == beatmap.OnlineID) is BeatmapInfo local && !local.BeatmapSet.AsNonNull().DeletePending) { - var collectionItems = realm.Realm.All().Select(c => new CollectionToggleMenuItem(c.ToLive(realm), beatmap)).Cast().ToList(); + var collectionItems = realm.Realm.All().AsEnumerable().Select(c => new CollectionToggleMenuItem(c.ToLive(realm), beatmap)).Cast().ToList(); if (manageCollectionsDialog != null) collectionItems.Add(new OsuMenuItem("Manage...", MenuItemType.Standard, manageCollectionsDialog.Show)); From c1aaf27c54bc2d996086c275c19556a7f163f9e5 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Thu, 28 Jul 2022 16:02:19 +0900 Subject: [PATCH 141/278] Link to correct model in xmldoc --- osu.Game/Beatmaps/BeatmapSetInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Beatmaps/BeatmapSetInfo.cs b/osu.Game/Beatmaps/BeatmapSetInfo.cs index 7f65d1291d..d27d9d9192 100644 --- a/osu.Game/Beatmaps/BeatmapSetInfo.cs +++ b/osu.Game/Beatmaps/BeatmapSetInfo.cs @@ -15,7 +15,7 @@ using Realms; namespace osu.Game.Beatmaps { /// - /// A realm model containing metadata for a beatmap set (containing multiple ). + /// A realm model containing metadata for a beatmap set (containing multiple s). /// [ExcludeFromDynamicCompile] [MapTo("BeatmapSet")] From db62d4be3a006d8782de23ad39d50bf93da7cb04 Mon Sep 17 00:00:00 2001 From: Nitrous Date: Thu, 28 Jul 2022 15:12:49 +0800 Subject: [PATCH 142/278] apply suggestions - refactor `SongProgress` - make`UpdateProgress` more readable - enable NRT on new classes - refactor `TestSceneSongProgress` to use `GameplayClockContainer` --- .../Visual/Gameplay/TestSceneSongProgress.cs | 89 +++++++------------ .../Screens/Play/HUD/DefaultSongProgress.cs | 11 ++- osu.Game/Screens/Play/HUD/SongProgress.cs | 47 ++++------ osu.Game/Skinning/LegacySongProgress.cs | 9 +- 4 files changed, 63 insertions(+), 93 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs index 897284ed80..911b9bb7ec 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs @@ -4,11 +4,12 @@ #nullable disable using System.Collections.Generic; +using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; +using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics; using osu.Framework.Testing; -using osu.Framework.Timing; using osu.Game.Rulesets.Objects; using osu.Game.Screens.Play; using osu.Game.Screens.Play.HUD; @@ -19,44 +20,43 @@ namespace osu.Game.Tests.Visual.Gameplay [TestFixture] public class TestSceneSongProgress : SkinnableHUDComponentTestScene { - private DefaultSongProgress defaultProgress; + private DefaultSongProgress progress => this.ChildrenOfType().Single(); + private GameplayClockContainer gameplayClockContainer; + private const double gameplay_start_time = -2000; - private readonly List progresses = new List(); - - private readonly StopwatchClock clock; - private readonly FramedClock framedClock; - - [Cached] - private readonly GameplayClock gameplayClock; - - public TestSceneSongProgress() + [BackgroundDependencyLoader] + private void load() { - clock = new StopwatchClock(); - gameplayClock = new GameplayClock(framedClock = new FramedClock(clock)); + var working = CreateWorkingBeatmap(Ruleset.Value); + working.LoadTrack(); + Add(gameplayClockContainer = new MasterGameplayClockContainer(working, gameplay_start_time)); + Dependencies.CacheAs(gameplayClockContainer); + Dependencies.CacheAs(gameplayClockContainer.GameplayClock); } [SetUpSteps] public void SetupSteps() { - AddStep("reset clock", clock.Reset); + AddStep("reset clock", () => gameplayClockContainer.Reset(false)); } [Test] public void TestDisplay() { AddStep("display max values", displayMaxValues); - AddStep("start", clock.Start); - AddStep("stop", clock.Stop); + AddStep("seek to intro", () => gameplayClockContainer.Seek(gameplay_start_time)); + AddStep("start", gameplayClockContainer.Start); + AddStep("stop", gameplayClockContainer.Stop); } [Test] public void TestToggleSeeking() { - AddStep("allow seeking", () => defaultProgress.AllowSeeking.Value = true); - AddStep("hide graph", () => defaultProgress.ShowGraph.Value = false); - AddStep("disallow seeking", () => defaultProgress.AllowSeeking.Value = false); - AddStep("allow seeking", () => defaultProgress.AllowSeeking.Value = true); - AddStep("show graph", () => defaultProgress.ShowGraph.Value = true); + AddStep("allow seeking", () => progress.AllowSeeking.Value = true); + AddStep("hide graph", () => progress.ShowGraph.Value = false); + AddStep("disallow seeking", () => progress.AllowSeeking.Value = false); + AddStep("allow seeking", () => progress.AllowSeeking.Value = true); + AddStep("show graph", () => progress.ShowGraph.Value = true); } private void displayMaxValues() @@ -65,48 +65,25 @@ namespace osu.Game.Tests.Visual.Gameplay for (double i = 0; i < 5000; i++) objects.Add(new HitObject { StartTime = i }); - replaceObjects(objects); + setObjects(objects); } - private void replaceObjects(List objects) + private void setObjects(List objects) { - defaultProgress.RequestSeek = pos => clock.Seek(pos); - - foreach (var p in progresses) - { - p.Objects = objects; - } + this.ChildrenOfType().ForEach(progress => progress.Objects = objects); } - protected override void Update() + protected override Drawable CreateDefaultImplementation() => new DefaultSongProgress { - base.Update(); - framedClock.ProcessFrame(); - } + RelativeSizeAxes = Axes.X, + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + }; - protected override Drawable CreateDefaultImplementation() + protected override Drawable CreateLegacyImplementation() => new LegacySongProgress { - defaultProgress = new DefaultSongProgress - { - RelativeSizeAxes = Axes.X, - Anchor = Anchor.BottomLeft, - Origin = Anchor.BottomLeft, - }; - - progresses.Add(defaultProgress); - return defaultProgress; - } - - protected override Drawable CreateLegacyImplementation() - { - var progress = new LegacySongProgress - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - }; - - progresses.Add(progress); - return progress; - } + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + }; } } diff --git a/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs b/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs index 7c2d8a9de2..347bd797ac 100644 --- a/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs +++ b/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs @@ -49,6 +49,9 @@ namespace osu.Game.Screens.Play.HUD protected override bool BlockScrollInput => false; + [Resolved(canBeNull: true)] + private GameplayClock gameplayClock { get; set; } + [Resolved(canBeNull: true)] private Player player { get; set; } @@ -178,10 +181,12 @@ namespace osu.Game.Screens.Play.HUD bar.EndTime = LastHitTime; } - protected override void UpdateProgress(double progress, double time, bool isIntro) + protected override void UpdateProgress(double progress, bool isIntro) { - bar.CurrentTime = time; - graph.Progress = (int)(graph.ColumnCount * progress); + bar.CurrentTime = gameplayClock?.CurrentTime ?? Time.Current; + + if (!isIntro) + graph.Progress = (int)(graph.ColumnCount * progress); } protected override void Update() diff --git a/osu.Game/Screens/Play/HUD/SongProgress.cs b/osu.Game/Screens/Play/HUD/SongProgress.cs index 5c7c7d28c6..e0663b42ea 100644 --- a/osu.Game/Screens/Play/HUD/SongProgress.cs +++ b/osu.Game/Screens/Play/HUD/SongProgress.cs @@ -1,16 +1,11 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - -using System; using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; -using osu.Framework.Bindables; using osu.Framework.Graphics.Containers; using osu.Framework.Timing; -using osu.Game.Beatmaps; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.UI; using osu.Game.Skinning; @@ -21,20 +16,14 @@ namespace osu.Game.Screens.Play.HUD { public bool UsesFixedAnchor { get; set; } - [Resolved(canBeNull: true)] - private GameplayClock gameplayClock { get; set; } + [Resolved] + private GameplayClockContainer? gameplayClockContainer { get; set; } [Resolved(canBeNull: true)] - private GameplayClockContainer gameplayClockContainer { get; set; } + private DrawableRuleset? drawableRuleset { get; set; } - [Resolved(canBeNull: true)] - private DrawableRuleset drawableRuleset { get; set; } - - [Resolved(canBeNull: true)] - private IBindable beatmap { get; set; } - - private IClock referenceClock; - private IEnumerable objects; + private IClock? referenceClock; + private IEnumerable? objects; public IEnumerable Objects { @@ -46,9 +35,7 @@ namespace osu.Game.Screens.Play.HUD //TODO: this isn't always correct (consider mania where a non-last object may last for longer than the last in the list). protected double LastHitTime => objects.LastOrDefault()?.GetEndTime() ?? 0; - protected double FirstEventTime { get; private set; } - - protected abstract void UpdateProgress(double progress, double time, bool isIntro); + protected abstract void UpdateProgress(double progress, bool isIntro); protected abstract void UpdateObjects(IEnumerable objects); [BackgroundDependencyLoader] @@ -59,11 +46,6 @@ namespace osu.Game.Screens.Play.HUD Objects = drawableRuleset.Objects; referenceClock = drawableRuleset.FrameStableClock; } - - if (beatmap != null) - { - FirstEventTime = beatmap.Value.Storyboard.EarliestEventTime ?? 0; - } } protected override void Update() @@ -73,17 +55,22 @@ namespace osu.Game.Screens.Play.HUD if (objects == null) return; - double gameplayTime = gameplayClockContainer?.GameplayClock.CurrentTime ?? gameplayClock?.CurrentTime ?? Time.Current; - double frameStableTime = referenceClock?.CurrentTime ?? gameplayTime; + // The reference clock is used to accurately tell the playfield's time. This is obtained from the drawable ruleset. + // However, if no drawable ruleset is available (i.e. used in tests), we fall back to either the gameplay clock container or this drawable's own clock. + double gameplayTime = referenceClock?.CurrentTime ?? gameplayClockContainer?.GameplayClock.CurrentTime ?? Time.Current; - if (frameStableTime < FirstHitTime) + if (gameplayTime < FirstHitTime) { - double earliest = Math.Min(FirstEventTime, gameplayClockContainer?.StartTime ?? 0); - UpdateProgress((frameStableTime - earliest) / (FirstHitTime - earliest), gameplayTime, true); + double earliest = gameplayClockContainer?.StartTime ?? 0; + double introDuration = FirstHitTime - earliest; + double currentIntroTime = gameplayTime - earliest; + UpdateProgress(currentIntroTime / introDuration, true); } else { - UpdateProgress((frameStableTime - FirstHitTime) / (LastHitTime - FirstHitTime), gameplayTime, false); + double duration = LastHitTime - FirstHitTime; + double currentTime = gameplayTime - FirstHitTime; + UpdateProgress(currentTime / duration, false); } } } diff --git a/osu.Game/Skinning/LegacySongProgress.cs b/osu.Game/Skinning/LegacySongProgress.cs index 5f27d73761..ee071ad3ed 100644 --- a/osu.Game/Skinning/LegacySongProgress.cs +++ b/osu.Game/Skinning/LegacySongProgress.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Collections.Generic; using osu.Framework.Allocation; using osu.Framework.Graphics; @@ -17,7 +15,7 @@ namespace osu.Game.Skinning { public class LegacySongProgress : SongProgress { - private CircularProgress pie; + private CircularProgress? pie; [BackgroundDependencyLoader] private void load() @@ -72,8 +70,11 @@ namespace osu.Game.Skinning { } - protected override void UpdateProgress(double progress, double time, bool isIntro) + protected override void UpdateProgress(double progress, bool isIntro) { + if (pie == null) + return; + if (isIntro) { pie.Scale = new Vector2(-1, 1); From 2b9d46d80392579086c0b26d77646d0f0e30cc10 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 16:19:05 +0900 Subject: [PATCH 143/278] Remove unused `RulesetStore` from `BeatmapManager` constructor --- osu.Game.Tests/Beatmaps/WorkingBeatmapManagerTest.cs | 2 +- .../Online/TestSceneOnlinePlayBeatmapAvailabilityTracker.cs | 2 +- .../Visual/Background/TestSceneUserDimBackgrounds.cs | 2 +- .../Visual/Collections/TestSceneManageCollectionsDialog.cs | 5 ++--- .../Visual/Gameplay/TestScenePlayerLocalScoreImport.cs | 2 +- osu.Game.Tests/Visual/Multiplayer/QueueModeTestScene.cs | 5 ++--- .../Visual/Multiplayer/TestSceneDrawableRoomPlaylist.cs | 5 ++--- osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayer.cs | 5 ++--- .../Multiplayer/TestSceneMultiplayerMatchSongSelect.cs | 2 +- .../Multiplayer/TestSceneMultiplayerMatchSubScreen.cs | 5 ++--- .../Visual/Multiplayer/TestSceneMultiplayerPlaylist.cs | 5 ++--- .../Visual/Multiplayer/TestSceneMultiplayerQueueList.cs | 5 ++--- .../Multiplayer/TestSceneMultiplayerSpectateButton.cs | 5 ++--- .../Visual/Multiplayer/TestScenePlaylistsSongSelect.cs | 6 ++---- osu.Game.Tests/Visual/Multiplayer/TestSceneTeamVersus.cs | 5 ++--- .../Visual/Playlists/TestScenePlaylistsRoomCreation.cs | 5 ++--- .../Visual/SongSelect/TestSceneBeatmapLeaderboard.cs | 2 +- osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs | 5 ++--- osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs | 2 +- osu.Game.Tests/Visual/SongSelect/TestSceneTopLocalRank.cs | 2 +- .../Visual/UserInterface/TestSceneDeleteLocalScore.cs | 5 ++--- osu.Game/Beatmaps/BeatmapManager.cs | 2 +- osu.Game/OsuGameBase.cs | 2 +- osu.Game/Tests/Visual/EditorTestScene.cs | 2 +- 24 files changed, 37 insertions(+), 51 deletions(-) diff --git a/osu.Game.Tests/Beatmaps/WorkingBeatmapManagerTest.cs b/osu.Game.Tests/Beatmaps/WorkingBeatmapManagerTest.cs index 0348e47d4a..f14288e7ba 100644 --- a/osu.Game.Tests/Beatmaps/WorkingBeatmapManagerTest.cs +++ b/osu.Game.Tests/Beatmaps/WorkingBeatmapManagerTest.cs @@ -26,7 +26,7 @@ namespace osu.Game.Tests.Beatmaps [BackgroundDependencyLoader] private void load(GameHost host, AudioManager audio, RulesetStore rulesets) { - Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, rulesets, null, audio, Resources, host, Beatmap.Default)); + Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, null, audio, Resources, host, Beatmap.Default)); } [SetUpSteps] diff --git a/osu.Game.Tests/Online/TestSceneOnlinePlayBeatmapAvailabilityTracker.cs b/osu.Game.Tests/Online/TestSceneOnlinePlayBeatmapAvailabilityTracker.cs index 536322805b..3f20f843a7 100644 --- a/osu.Game.Tests/Online/TestSceneOnlinePlayBeatmapAvailabilityTracker.cs +++ b/osu.Game.Tests/Online/TestSceneOnlinePlayBeatmapAvailabilityTracker.cs @@ -208,7 +208,7 @@ namespace osu.Game.Tests.Online public TestBeatmapManager(Storage storage, RealmAccess realm, RulesetStore rulesets, IAPIProvider api, [NotNull] AudioManager audioManager, IResourceStore resources, GameHost host = null, WorkingBeatmap defaultBeatmap = null) - : base(storage, realm, rulesets, api, audioManager, resources, host, defaultBeatmap) + : base(storage, realm, api, audioManager, resources, host, defaultBeatmap) { } diff --git a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs index aaccea09d4..5aadd6f56a 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs @@ -49,7 +49,7 @@ namespace osu.Game.Tests.Visual.Background private void load(GameHost host, AudioManager audio) { Dependencies.Cache(rulesets = new RealmRulesetStore(Realm)); - Dependencies.Cache(manager = new BeatmapManager(LocalStorage, Realm, rulesets, null, audio, Resources, host, Beatmap.Default)); + Dependencies.Cache(manager = new BeatmapManager(LocalStorage, Realm, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(new OsuConfigManager(LocalStorage)); Dependencies.Cache(Realm); diff --git a/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs b/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs index 3f30fa367c..8f2146dac5 100644 --- a/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs +++ b/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs @@ -30,7 +30,6 @@ namespace osu.Game.Tests.Visual.Collections private DialogOverlay dialogOverlay; private CollectionManager manager; - private RulesetStore rulesets; private BeatmapManager beatmapManager; private ManageCollectionsDialog dialog; @@ -38,8 +37,8 @@ namespace osu.Game.Tests.Visual.Collections [BackgroundDependencyLoader] private void load(GameHost host) { - Dependencies.Cache(rulesets = new RealmRulesetStore(Realm)); - Dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, Realm, rulesets, null, Audio, Resources, host, Beatmap.Default)); + Dependencies.Cache(new RealmRulesetStore(Realm)); + Dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, Realm, null, Audio, Resources, host, Beatmap.Default)); Dependencies.Cache(Realm); beatmapManager.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely(); diff --git a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLocalScoreImport.cs b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLocalScoreImport.cs index 6491987abe..ddb585a73c 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLocalScoreImport.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLocalScoreImport.cs @@ -36,7 +36,7 @@ namespace osu.Game.Tests.Visual.Gameplay private void load(GameHost host, AudioManager audio) { Dependencies.Cache(rulesets = new RealmRulesetStore(Realm)); - Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, rulesets, null, audio, Resources, host, Beatmap.Default)); + Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(new ScoreManager(rulesets, () => beatmaps, LocalStorage, Realm, Scheduler, API)); Dependencies.Cache(Realm); } diff --git a/osu.Game.Tests/Visual/Multiplayer/QueueModeTestScene.cs b/osu.Game.Tests/Visual/Multiplayer/QueueModeTestScene.cs index 2b461cf6f6..ca4d926866 100644 --- a/osu.Game.Tests/Visual/Multiplayer/QueueModeTestScene.cs +++ b/osu.Game.Tests/Visual/Multiplayer/QueueModeTestScene.cs @@ -35,7 +35,6 @@ namespace osu.Game.Tests.Visual.Multiplayer protected IScreen CurrentSubScreen => multiplayerComponents.MultiplayerScreen.CurrentSubScreen; private BeatmapManager beatmaps; - private RulesetStore rulesets; private BeatmapSetInfo importedSet; private TestMultiplayerComponents multiplayerComponents; @@ -45,8 +44,8 @@ namespace osu.Game.Tests.Visual.Multiplayer [BackgroundDependencyLoader] private void load(GameHost host, AudioManager audio) { - Dependencies.Cache(rulesets = new RealmRulesetStore(Realm)); - Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, rulesets, null, audio, Resources, host, Beatmap.Default)); + Dependencies.Cache(new RealmRulesetStore(Realm)); + Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(Realm); } diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoomPlaylist.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoomPlaylist.cs index 1797c82fb9..73d1222156 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoomPlaylist.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoomPlaylist.cs @@ -38,13 +38,12 @@ namespace osu.Game.Tests.Visual.Multiplayer private TestPlaylist playlist; private BeatmapManager manager; - private RulesetStore rulesets; [BackgroundDependencyLoader] private void load(GameHost host, AudioManager audio) { - Dependencies.Cache(rulesets = new RealmRulesetStore(Realm)); - Dependencies.Cache(manager = new BeatmapManager(LocalStorage, Realm, rulesets, null, audio, Resources, host, Beatmap.Default)); + Dependencies.Cache(new RealmRulesetStore(Realm)); + Dependencies.Cache(manager = new BeatmapManager(LocalStorage, Realm, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(Realm); } diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayer.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayer.cs index bf9b99e3e2..269867be73 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayer.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayer.cs @@ -49,7 +49,6 @@ namespace osu.Game.Tests.Visual.Multiplayer public class TestSceneMultiplayer : ScreenTestScene { private BeatmapManager beatmaps = null!; - private RulesetStore rulesets = null!; private BeatmapSetInfo importedSet = null!; private TestMultiplayerComponents multiplayerComponents = null!; @@ -63,8 +62,8 @@ namespace osu.Game.Tests.Visual.Multiplayer [BackgroundDependencyLoader] private void load(GameHost host, AudioManager audio) { - Dependencies.Cache(rulesets = new RealmRulesetStore(Realm)); - Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, rulesets, API, audio, Resources, host, Beatmap.Default)); + Dependencies.Cache(new RealmRulesetStore(Realm)); + Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, API, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(Realm); } diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchSongSelect.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchSongSelect.cs index ab4f9c37b2..2281235f25 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchSongSelect.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchSongSelect.cs @@ -47,7 +47,7 @@ namespace osu.Game.Tests.Visual.Multiplayer private void load(GameHost host, AudioManager audio) { Dependencies.Cache(rulesets = new RealmRulesetStore(Realm)); - Dependencies.Cache(manager = new BeatmapManager(LocalStorage, Realm, rulesets, null, audio, Resources, host, Beatmap.Default)); + Dependencies.Cache(manager = new BeatmapManager(LocalStorage, Realm, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(Realm); importedBeatmapSet = manager.Import(TestResources.CreateTestBeatmapSetInfo(8, rulesets.AvailableRulesets.ToArray())); diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchSubScreen.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchSubScreen.cs index 5d6a6c8104..5ebafbaabb 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchSubScreen.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchSubScreen.cs @@ -40,7 +40,6 @@ namespace osu.Game.Tests.Visual.Multiplayer private MultiplayerMatchSubScreen screen; private BeatmapManager beatmaps; - private RulesetStore rulesets; private BeatmapSetInfo importedSet; public TestSceneMultiplayerMatchSubScreen() @@ -51,8 +50,8 @@ namespace osu.Game.Tests.Visual.Multiplayer [BackgroundDependencyLoader] private void load(GameHost host, AudioManager audio) { - Dependencies.Cache(rulesets = new RealmRulesetStore(Realm)); - Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, rulesets, null, audio, Resources, host, Beatmap.Default)); + Dependencies.Cache(new RealmRulesetStore(Realm)); + Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(Realm); beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely(); diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerPlaylist.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerPlaylist.cs index 5ee385810b..75e6088b0d 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerPlaylist.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerPlaylist.cs @@ -31,15 +31,14 @@ namespace osu.Game.Tests.Visual.Multiplayer { private MultiplayerPlaylist list; private BeatmapManager beatmaps; - private RulesetStore rulesets; private BeatmapSetInfo importedSet; private BeatmapInfo importedBeatmap; [BackgroundDependencyLoader] private void load(GameHost host, AudioManager audio) { - Dependencies.Cache(rulesets = new RealmRulesetStore(Realm)); - Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, rulesets, null, audio, Resources, host, Beatmap.Default)); + Dependencies.Cache(new RealmRulesetStore(Realm)); + Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(Realm); } diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerQueueList.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerQueueList.cs index e709a955b3..f31261dc1f 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerQueueList.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerQueueList.cs @@ -29,15 +29,14 @@ namespace osu.Game.Tests.Visual.Multiplayer { private MultiplayerQueueList playlist; private BeatmapManager beatmaps; - private RulesetStore rulesets; private BeatmapSetInfo importedSet; private BeatmapInfo importedBeatmap; [BackgroundDependencyLoader] private void load(GameHost host, AudioManager audio) { - Dependencies.Cache(rulesets = new RealmRulesetStore(Realm)); - Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, rulesets, API, audio, Resources, host, Beatmap.Default)); + Dependencies.Cache(new RealmRulesetStore(Realm)); + Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, API, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(Realm); } diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerSpectateButton.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerSpectateButton.cs index 91c87548c7..e70c414bef 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerSpectateButton.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerSpectateButton.cs @@ -35,13 +35,12 @@ namespace osu.Game.Tests.Visual.Multiplayer private BeatmapSetInfo importedSet; private BeatmapManager beatmaps; - private RulesetStore rulesets; [BackgroundDependencyLoader] private void load(GameHost host, AudioManager audio) { - Dependencies.Cache(rulesets = new RealmRulesetStore(Realm)); - Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, rulesets, null, audio, Resources, host, Beatmap.Default)); + Dependencies.Cache(new RealmRulesetStore(Realm)); + Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(Realm); beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely(); diff --git a/osu.Game.Tests/Visual/Multiplayer/TestScenePlaylistsSongSelect.cs b/osu.Game.Tests/Visual/Multiplayer/TestScenePlaylistsSongSelect.cs index 88afe1ce7c..2eddf1a17e 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestScenePlaylistsSongSelect.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestScenePlaylistsSongSelect.cs @@ -28,15 +28,13 @@ namespace osu.Game.Tests.Visual.Multiplayer { private BeatmapManager manager; - private RulesetStore rulesets; - private TestPlaylistsSongSelect songSelect; [BackgroundDependencyLoader] private void load(GameHost host, AudioManager audio) { - Dependencies.Cache(rulesets = new RealmRulesetStore(Realm)); - Dependencies.Cache(manager = new BeatmapManager(LocalStorage, Realm, rulesets, null, audio, Resources, host, Beatmap.Default)); + Dependencies.Cache(new RealmRulesetStore(Realm)); + Dependencies.Cache(manager = new BeatmapManager(LocalStorage, Realm, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(Realm); var beatmapSet = TestResources.CreateTestBeatmapSetInfo(); diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneTeamVersus.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneTeamVersus.cs index d80537a2e5..ef2a431b8f 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneTeamVersus.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneTeamVersus.cs @@ -30,7 +30,6 @@ namespace osu.Game.Tests.Visual.Multiplayer public class TestSceneTeamVersus : ScreenTestScene { private BeatmapManager beatmaps; - private RulesetStore rulesets; private BeatmapSetInfo importedSet; private TestMultiplayerComponents multiplayerComponents; @@ -40,8 +39,8 @@ namespace osu.Game.Tests.Visual.Multiplayer [BackgroundDependencyLoader] private void load(GameHost host, AudioManager audio) { - Dependencies.Cache(rulesets = new RealmRulesetStore(Realm)); - Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, rulesets, null, audio, Resources, host, Beatmap.Default)); + Dependencies.Cache(new RealmRulesetStore(Realm)); + Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(Realm); } diff --git a/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsRoomCreation.cs b/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsRoomCreation.cs index c0cd2d9157..e798f72891 100644 --- a/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsRoomCreation.cs +++ b/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsRoomCreation.cs @@ -32,7 +32,6 @@ namespace osu.Game.Tests.Visual.Playlists public class TestScenePlaylistsRoomCreation : OnlinePlayTestScene { private BeatmapManager manager; - private RulesetStore rulesets; private TestPlaylistsRoomSubScreen match; @@ -41,8 +40,8 @@ namespace osu.Game.Tests.Visual.Playlists [BackgroundDependencyLoader] private void load(GameHost host, AudioManager audio) { - Dependencies.Cache(rulesets = new RealmRulesetStore(Realm)); - Dependencies.Cache(manager = new BeatmapManager(LocalStorage, Realm, rulesets, API, audio, Resources, host, Beatmap.Default)); + Dependencies.Cache(new RealmRulesetStore(Realm)); + Dependencies.Cache(manager = new BeatmapManager(LocalStorage, Realm, API, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(Realm); } diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapLeaderboard.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapLeaderboard.cs index abcb888cd4..aeb30c94e1 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapLeaderboard.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapLeaderboard.cs @@ -46,7 +46,7 @@ namespace osu.Game.Tests.Visual.SongSelect var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); dependencies.Cache(rulesetStore = new RealmRulesetStore(Realm)); - dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, Realm, rulesetStore, null, dependencies.Get(), Resources, dependencies.Get(), Beatmap.Default)); + dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, Realm, null, dependencies.Get(), Resources, dependencies.Get(), Beatmap.Default)); dependencies.Cache(scoreManager = new ScoreManager(rulesetStore, () => beatmapManager, LocalStorage, Realm, Scheduler, API)); Dependencies.Cache(Realm); diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs index 6807180640..b25e0f2b34 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs @@ -30,7 +30,6 @@ namespace osu.Game.Tests.Visual.SongSelect private CollectionManager collectionManager; - private RulesetStore rulesets; private BeatmapManager beatmapManager; private FilterControl control; @@ -38,8 +37,8 @@ namespace osu.Game.Tests.Visual.SongSelect [BackgroundDependencyLoader] private void load(GameHost host) { - Dependencies.Cache(rulesets = new RealmRulesetStore(Realm)); - Dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, Realm, rulesets, null, Audio, Resources, host, Beatmap.Default)); + Dependencies.Cache(new RealmRulesetStore(Realm)); + Dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, Realm, null, Audio, Resources, host, Beatmap.Default)); Dependencies.Cache(Realm); beatmapManager.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely(); diff --git a/osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs b/osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs index 159a3b1923..12f15b04dc 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs @@ -54,7 +54,7 @@ namespace osu.Game.Tests.Visual.SongSelect // At a point we have isolated interactive test runs enough, this can likely be removed. Dependencies.Cache(rulesets = new RealmRulesetStore(Realm)); Dependencies.Cache(Realm); - Dependencies.Cache(manager = new BeatmapManager(LocalStorage, Realm, rulesets, null, audio, Resources, host, defaultBeatmap = Beatmap.Default)); + Dependencies.Cache(manager = new BeatmapManager(LocalStorage, Realm, null, audio, Resources, host, defaultBeatmap = Beatmap.Default)); Dependencies.Cache(music = new MusicController()); diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneTopLocalRank.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneTopLocalRank.cs index 05b5c5c0cd..72d78ededb 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneTopLocalRank.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneTopLocalRank.cs @@ -31,7 +31,7 @@ namespace osu.Game.Tests.Visual.SongSelect private void load(GameHost host, AudioManager audio) { Dependencies.Cache(rulesets = new RealmRulesetStore(Realm)); - Dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, Realm, rulesets, null, audio, Resources, host, Beatmap.Default)); + Dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, Realm, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(scoreManager = new ScoreManager(rulesets, () => beatmapManager, LocalStorage, Realm, Scheduler, API)); Dependencies.Cache(Realm); diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs index e59914f69a..3beade9d4f 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs @@ -37,7 +37,6 @@ namespace osu.Game.Tests.Visual.UserInterface private readonly ContextMenuContainer contextMenuContainer; private readonly BeatmapLeaderboard leaderboard; - private RulesetStore rulesetStore; private BeatmapManager beatmapManager; private ScoreManager scoreManager; @@ -72,8 +71,8 @@ namespace osu.Game.Tests.Visual.UserInterface { var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); - dependencies.Cache(rulesetStore = new RealmRulesetStore(Realm)); - dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, Realm, rulesetStore, null, dependencies.Get(), Resources, dependencies.Get(), Beatmap.Default)); + dependencies.Cache(new RealmRulesetStore(Realm)); + dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, Realm, null, dependencies.Get(), Resources, dependencies.Get(), Beatmap.Default)); dependencies.Cache(scoreManager = new ScoreManager(dependencies.Get(), () => beatmapManager, LocalStorage, Realm, Scheduler, API)); Dependencies.Cache(Realm); diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index debe4c6829..5db9311e7b 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -44,7 +44,7 @@ namespace osu.Game.Beatmaps public Action? ProcessBeatmap { private get; set; } - public BeatmapManager(Storage storage, RealmAccess realm, RulesetStore rulesets, IAPIProvider? api, AudioManager audioManager, IResourceStore gameResources, GameHost? host = null, + public BeatmapManager(Storage storage, RealmAccess realm, IAPIProvider? api, AudioManager audioManager, IResourceStore gameResources, GameHost? host = null, WorkingBeatmap? defaultBeatmap = null, BeatmapDifficultyCache? difficultyCache = null, bool performOnlineLookups = false) : base(storage, realm) { diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 7b6cda17a2..b399fdc175 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -271,7 +271,7 @@ namespace osu.Game // ordering is important here to ensure foreign keys rules are not broken in ModelStore.Cleanup() dependencies.Cache(ScoreManager = new ScoreManager(RulesetStore, () => BeatmapManager, Storage, realm, Scheduler, API, difficultyCache, LocalConfig)); - dependencies.Cache(BeatmapManager = new BeatmapManager(Storage, realm, RulesetStore, API, Audio, Resources, Host, defaultBeatmap, difficultyCache, performOnlineLookups: true)); + dependencies.Cache(BeatmapManager = new BeatmapManager(Storage, realm, API, Audio, Resources, Host, defaultBeatmap, difficultyCache, performOnlineLookups: true)); dependencies.Cache(BeatmapDownloader = new BeatmapModelDownloader(BeatmapManager, API)); dependencies.Cache(ScoreDownloader = new ScoreModelDownloader(ScoreManager, API)); diff --git a/osu.Game/Tests/Visual/EditorTestScene.cs b/osu.Game/Tests/Visual/EditorTestScene.cs index 31036247ab..ced72aa593 100644 --- a/osu.Game/Tests/Visual/EditorTestScene.cs +++ b/osu.Game/Tests/Visual/EditorTestScene.cs @@ -139,7 +139,7 @@ namespace osu.Game.Tests.Visual public WorkingBeatmap TestBeatmap; public TestBeatmapManager(Storage storage, RealmAccess realm, RulesetStore rulesets, IAPIProvider api, [NotNull] AudioManager audioManager, IResourceStore resources, GameHost host, WorkingBeatmap defaultBeatmap) - : base(storage, realm, rulesets, api, audioManager, resources, host, defaultBeatmap) + : base(storage, realm, api, audioManager, resources, host, defaultBeatmap) { } From 70ed347b0624502761040067fd7e8fe18158bb6a Mon Sep 17 00:00:00 2001 From: Nitrous Date: Thu, 28 Jul 2022 15:19:35 +0800 Subject: [PATCH 144/278] simplify helper methods --- osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs index 911b9bb7ec..4a786f2ebe 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs @@ -38,12 +38,12 @@ namespace osu.Game.Tests.Visual.Gameplay public void SetupSteps() { AddStep("reset clock", () => gameplayClockContainer.Reset(false)); + AddStep("set hit objects", setHitObjects); } [Test] public void TestDisplay() { - AddStep("display max values", displayMaxValues); AddStep("seek to intro", () => gameplayClockContainer.Seek(gameplay_start_time)); AddStep("start", gameplayClockContainer.Start); AddStep("stop", gameplayClockContainer.Stop); @@ -59,17 +59,12 @@ namespace osu.Game.Tests.Visual.Gameplay AddStep("show graph", () => progress.ShowGraph.Value = true); } - private void displayMaxValues() + private void setHitObjects() { var objects = new List(); for (double i = 0; i < 5000; i++) objects.Add(new HitObject { StartTime = i }); - setObjects(objects); - } - - private void setObjects(List objects) - { this.ChildrenOfType().ForEach(progress => progress.Objects = objects); } From bca3994d918a344cf9001dd1637564dfc94ba76f Mon Sep 17 00:00:00 2001 From: Nitrous Date: Thu, 28 Jul 2022 15:25:12 +0800 Subject: [PATCH 145/278] set `FirstHitTime` and `LastHitTime` once --- osu.Game/Screens/Play/HUD/SongProgress.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/Play/HUD/SongProgress.cs b/osu.Game/Screens/Play/HUD/SongProgress.cs index e0663b42ea..55c85a1d91 100644 --- a/osu.Game/Screens/Play/HUD/SongProgress.cs +++ b/osu.Game/Screens/Play/HUD/SongProgress.cs @@ -27,13 +27,19 @@ namespace osu.Game.Screens.Play.HUD public IEnumerable Objects { - set => UpdateObjects(objects = value); + set + { + objects = value; + FirstHitTime = objects.FirstOrDefault()?.StartTime ?? 0; + LastHitTime = objects.LastOrDefault()?.GetEndTime() ?? 0; + UpdateObjects(objects); + } } - protected double FirstHitTime => objects.FirstOrDefault()?.StartTime ?? 0; + protected double FirstHitTime { get; private set; } //TODO: this isn't always correct (consider mania where a non-last object may last for longer than the last in the list). - protected double LastHitTime => objects.LastOrDefault()?.GetEndTime() ?? 0; + protected double LastHitTime { get; private set; } protected abstract void UpdateProgress(double progress, bool isIntro); protected abstract void UpdateObjects(IEnumerable objects); From 0d36907cad09b4d45305c1f2c3e342e570872252 Mon Sep 17 00:00:00 2001 From: Nitrous Date: Thu, 28 Jul 2022 15:30:45 +0800 Subject: [PATCH 146/278] apply code quality fixes --- osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs | 2 +- osu.Game/Screens/Play/HUD/DefaultSongProgress.cs | 4 +++- osu.Game/Screens/Play/HUD/SongProgress.cs | 6 +++--- osu.Game/Skinning/LegacySongProgress.cs | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs index 4a786f2ebe..3f81757fcd 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs @@ -37,7 +37,7 @@ namespace osu.Game.Tests.Visual.Gameplay [SetUpSteps] public void SetupSteps() { - AddStep("reset clock", () => gameplayClockContainer.Reset(false)); + AddStep("reset clock", () => gameplayClockContainer.Reset()); AddStep("set hit objects", setHitObjects); } diff --git a/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs b/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs index 347bd797ac..654884c0d5 100644 --- a/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs +++ b/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs @@ -174,7 +174,9 @@ namespace osu.Game.Screens.Play.HUD protected override void UpdateObjects(IEnumerable objects) { - graph.Objects = objects; + if (objects != null) + graph.Objects = objects; + info.StartTime = FirstHitTime; info.EndTime = LastHitTime; bar.StartTime = FirstHitTime; diff --git a/osu.Game/Screens/Play/HUD/SongProgress.cs b/osu.Game/Screens/Play/HUD/SongProgress.cs index 55c85a1d91..78f0142dba 100644 --- a/osu.Game/Screens/Play/HUD/SongProgress.cs +++ b/osu.Game/Screens/Play/HUD/SongProgress.cs @@ -30,8 +30,8 @@ namespace osu.Game.Screens.Play.HUD set { objects = value; - FirstHitTime = objects.FirstOrDefault()?.StartTime ?? 0; - LastHitTime = objects.LastOrDefault()?.GetEndTime() ?? 0; + FirstHitTime = objects?.FirstOrDefault()?.StartTime ?? 0; + LastHitTime = objects?.LastOrDefault()?.GetEndTime() ?? 0; UpdateObjects(objects); } } @@ -42,7 +42,7 @@ namespace osu.Game.Screens.Play.HUD protected double LastHitTime { get; private set; } protected abstract void UpdateProgress(double progress, bool isIntro); - protected abstract void UpdateObjects(IEnumerable objects); + protected abstract void UpdateObjects(IEnumerable? objects); [BackgroundDependencyLoader] private void load() diff --git a/osu.Game/Skinning/LegacySongProgress.cs b/osu.Game/Skinning/LegacySongProgress.cs index ee071ad3ed..0d1110df47 100644 --- a/osu.Game/Skinning/LegacySongProgress.cs +++ b/osu.Game/Skinning/LegacySongProgress.cs @@ -66,7 +66,7 @@ namespace osu.Game.Skinning { } - protected override void UpdateObjects(IEnumerable objects) + protected override void UpdateObjects(IEnumerable? objects) { } From 17a3fd30fbf535cfb16cc8d22e65b9f16fc4724f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 16:08:27 +0900 Subject: [PATCH 147/278] Move scheduler from `OnlineLookupQueue` to `BeatmapUpdater` --- osu.Game/Beatmaps/BeatmapUpdater.cs | 22 ++++++++++----- ...eue.cs => BeatmapUpdaterMetadataLookup.cs} | 27 ++++--------------- 2 files changed, 21 insertions(+), 28 deletions(-) rename osu.Game/Beatmaps/{BeatmapOnlineLookupQueue.cs => BeatmapUpdaterMetadataLookup.cs} (85%) diff --git a/osu.Game/Beatmaps/BeatmapUpdater.cs b/osu.Game/Beatmaps/BeatmapUpdater.cs index d2c5e5616a..5ffe4ee291 100644 --- a/osu.Game/Beatmaps/BeatmapUpdater.cs +++ b/osu.Game/Beatmaps/BeatmapUpdater.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Logging; using osu.Framework.Platform; +using osu.Framework.Threading; using osu.Game.Database; using osu.Game.Online.API; using osu.Game.Rulesets.Objects; @@ -20,15 +21,21 @@ namespace osu.Game.Beatmaps public class BeatmapUpdater : IDisposable { private readonly IWorkingBeatmapCache workingBeatmapCache; - private readonly BeatmapOnlineLookupQueue onlineLookupQueue; + private readonly BeatmapDifficultyCache difficultyCache; + private readonly BeatmapUpdaterMetadataLookup metadataLookup; + + private const int update_queue_request_concurrency = 4; + + private readonly ThreadedTaskScheduler updateScheduler = new ThreadedTaskScheduler(update_queue_request_concurrency, nameof(BeatmapUpdaterMetadataLookup)); + public BeatmapUpdater(IWorkingBeatmapCache workingBeatmapCache, BeatmapDifficultyCache difficultyCache, IAPIProvider api, Storage storage) { this.workingBeatmapCache = workingBeatmapCache; this.difficultyCache = difficultyCache; - onlineLookupQueue = new BeatmapOnlineLookupQueue(api, storage); + metadataLookup = new BeatmapUpdaterMetadataLookup(api, storage); } /// @@ -37,7 +44,7 @@ namespace osu.Game.Beatmaps public void Queue(Live beatmap) { Logger.Log($"Queueing change for local beatmap {beatmap}"); - Task.Factory.StartNew(() => beatmap.PerformRead(Process)); + Task.Factory.StartNew(() => beatmap.PerformRead(b => Process(b)), default, TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously, updateScheduler); } /// @@ -50,7 +57,7 @@ namespace osu.Game.Beatmaps // TODO: this call currently uses the local `online.db` lookup. // We probably don't want this to happen after initial import (as the data may be stale). - onlineLookupQueue.Update(beatmapSet); + metadataLookup.Update(beatmapSet); foreach (var beatmap in beatmapSet.Beatmaps) { @@ -90,8 +97,11 @@ namespace osu.Game.Beatmaps public void Dispose() { - if (onlineLookupQueue.IsNotNull()) - onlineLookupQueue.Dispose(); + if (metadataLookup.IsNotNull()) + metadataLookup.Dispose(); + + if (updateScheduler.IsNotNull()) + updateScheduler.Dispose(); } #endregion diff --git a/osu.Game/Beatmaps/BeatmapOnlineLookupQueue.cs b/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs similarity index 85% rename from osu.Game/Beatmaps/BeatmapOnlineLookupQueue.cs rename to osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs index 6a3383cc92..94846599e8 100644 --- a/osu.Game/Beatmaps/BeatmapOnlineLookupQueue.cs +++ b/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs @@ -6,8 +6,6 @@ using System; using System.Diagnostics; using System.IO; -using System.Linq; -using System.Threading; using System.Threading.Tasks; using Microsoft.Data.Sqlite; using osu.Framework.Development; @@ -15,7 +13,6 @@ using osu.Framework.IO.Network; using osu.Framework.Logging; using osu.Framework.Platform; using osu.Framework.Testing; -using osu.Framework.Threading; using osu.Game.Database; using osu.Game.Online.API; using osu.Game.Online.API.Requests; @@ -32,20 +29,16 @@ namespace osu.Game.Beatmaps /// This will always be checked before doing a second online query to get required metadata. /// [ExcludeFromDynamicCompile] - public class BeatmapOnlineLookupQueue : IDisposable + public class BeatmapUpdaterMetadataLookup : IDisposable { private readonly IAPIProvider api; private readonly Storage storage; - private const int update_queue_request_concurrency = 4; - - private readonly ThreadedTaskScheduler updateScheduler = new ThreadedTaskScheduler(update_queue_request_concurrency, nameof(BeatmapOnlineLookupQueue)); - private FileWebRequest cacheDownloadRequest; private const string cache_database_name = "online.db"; - public BeatmapOnlineLookupQueue(IAPIProvider api, Storage storage) + public BeatmapUpdaterMetadataLookup(IAPIProvider api, Storage storage) { this.api = api; this.storage = storage; @@ -61,15 +54,6 @@ namespace osu.Game.Beatmaps lookup(beatmapSet, b); } - public Task UpdateAsync(BeatmapSetInfo beatmapSet, CancellationToken cancellationToken) - { - return Task.WhenAll(beatmapSet.Beatmaps.Select(b => UpdateAsync(beatmapSet, b, cancellationToken)).ToArray()); - } - - // todo: expose this when we need to do individual difficulty lookups. - protected Task UpdateAsync(BeatmapSetInfo beatmapSet, BeatmapInfo beatmapInfo, CancellationToken cancellationToken) - => Task.Factory.StartNew(() => lookup(beatmapSet, beatmapInfo), cancellationToken, TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously, updateScheduler); - private void lookup(BeatmapSetInfo set, BeatmapInfo beatmapInfo) { if (checkLocalCache(set, beatmapInfo)) @@ -134,7 +118,7 @@ namespace osu.Game.Beatmaps File.Delete(compressedCacheFilePath); File.Delete(cacheFilePath); - Logger.Log($"{nameof(BeatmapOnlineLookupQueue)}'s online cache download failed: {ex}", LoggingTarget.Database); + Logger.Log($"{nameof(BeatmapUpdaterMetadataLookup)}'s online cache download failed: {ex}", LoggingTarget.Database); }; cacheDownloadRequest.Finished += () => @@ -151,7 +135,7 @@ namespace osu.Game.Beatmaps } catch (Exception ex) { - Logger.Log($"{nameof(BeatmapOnlineLookupQueue)}'s online cache extraction failed: {ex}", LoggingTarget.Database); + Logger.Log($"{nameof(BeatmapUpdaterMetadataLookup)}'s online cache extraction failed: {ex}", LoggingTarget.Database); File.Delete(cacheFilePath); } finally @@ -238,12 +222,11 @@ namespace osu.Game.Beatmaps } private void logForModel(BeatmapSetInfo set, string message) => - RealmArchiveModelImporter.LogForModel(set, $"[{nameof(BeatmapOnlineLookupQueue)}] {message}"); + RealmArchiveModelImporter.LogForModel(set, $"[{nameof(BeatmapUpdaterMetadataLookup)}] {message}"); public void Dispose() { cacheDownloadRequest?.Dispose(); - updateScheduler?.Dispose(); } } } From c35da6222469b366890960a89d4c33d253ebd916 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 16:18:30 +0900 Subject: [PATCH 148/278] Add flow for bypassing local cache lookups when refreshing beatmap metadata --- osu.Game/Beatmaps/BeatmapImporter.cs | 8 ++++---- osu.Game/Beatmaps/BeatmapManager.cs | 6 +++--- osu.Game/Beatmaps/BeatmapOnlineChangeIngest.cs | 2 +- osu.Game/Beatmaps/BeatmapUpdater.cs | 10 ++++------ osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs | 8 ++++---- osu.Game/Database/RealmArchiveModelImporter.cs | 5 +++-- osu.Game/OsuGameBase.cs | 2 +- osu.Game/Scoring/ScoreImporter.cs | 4 ++-- 8 files changed, 22 insertions(+), 23 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapImporter.cs b/osu.Game/Beatmaps/BeatmapImporter.cs index ef0e76234a..df8b18313c 100644 --- a/osu.Game/Beatmaps/BeatmapImporter.cs +++ b/osu.Game/Beatmaps/BeatmapImporter.cs @@ -34,7 +34,7 @@ namespace osu.Game.Beatmaps protected override string[] HashableFileTypes => new[] { ".osu" }; - public Action? ProcessBeatmap { private get; set; } + public Action? ProcessBeatmap { private get; set; } public BeatmapImporter(Storage storage, RealmAccess realm) : base(storage, realm) @@ -168,11 +168,11 @@ namespace osu.Game.Beatmaps } } - protected override void PostImport(BeatmapSetInfo model, Realm realm) + protected override void PostImport(BeatmapSetInfo model, Realm realm, bool batchImport) { - base.PostImport(model, realm); + base.PostImport(model, realm, batchImport); - ProcessBeatmap?.Invoke(model); + ProcessBeatmap?.Invoke(model, batchImport); } private void validateOnlineIds(BeatmapSetInfo beatmapSet, Realm realm) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index debe4c6829..abf3d43d94 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -42,7 +42,7 @@ namespace osu.Game.Beatmaps private readonly WorkingBeatmapCache workingBeatmapCache; - public Action? ProcessBeatmap { private get; set; } + public Action? ProcessBeatmap { private get; set; } public BeatmapManager(Storage storage, RealmAccess realm, RulesetStore rulesets, IAPIProvider? api, AudioManager audioManager, IResourceStore gameResources, GameHost? host = null, WorkingBeatmap? defaultBeatmap = null, BeatmapDifficultyCache? difficultyCache = null, bool performOnlineLookups = false) @@ -62,7 +62,7 @@ namespace osu.Game.Beatmaps BeatmapTrackStore = audioManager.GetTrackStore(userResources); beatmapImporter = CreateBeatmapImporter(storage, realm); - beatmapImporter.ProcessBeatmap = obj => ProcessBeatmap?.Invoke(obj); + beatmapImporter.ProcessBeatmap = (obj, isBatch) => ProcessBeatmap?.Invoke(obj, isBatch); beatmapImporter.PostNotification = obj => PostNotification?.Invoke(obj); workingBeatmapCache = CreateWorkingBeatmapCache(audioManager, gameResources, userResources, defaultBeatmap, host); @@ -323,7 +323,7 @@ namespace osu.Game.Beatmaps setInfo.CopyChangesToRealm(liveBeatmapSet); - ProcessBeatmap?.Invoke(liveBeatmapSet); + ProcessBeatmap?.Invoke(liveBeatmapSet, false); }); } diff --git a/osu.Game/Beatmaps/BeatmapOnlineChangeIngest.cs b/osu.Game/Beatmaps/BeatmapOnlineChangeIngest.cs index b6968f4e06..5d0765641b 100644 --- a/osu.Game/Beatmaps/BeatmapOnlineChangeIngest.cs +++ b/osu.Game/Beatmaps/BeatmapOnlineChangeIngest.cs @@ -36,7 +36,7 @@ namespace osu.Game.Beatmaps var matchingSet = r.All().FirstOrDefault(s => s.OnlineID == id); if (matchingSet != null) - beatmapUpdater.Queue(matchingSet.ToLive(realm)); + beatmapUpdater.Queue(matchingSet.ToLive(realm), true); } }); } diff --git a/osu.Game/Beatmaps/BeatmapUpdater.cs b/osu.Game/Beatmaps/BeatmapUpdater.cs index 5ffe4ee291..a86aab4ac1 100644 --- a/osu.Game/Beatmaps/BeatmapUpdater.cs +++ b/osu.Game/Beatmaps/BeatmapUpdater.cs @@ -41,23 +41,21 @@ namespace osu.Game.Beatmaps /// /// Queue a beatmap for background processing. /// - public void Queue(Live beatmap) + public void Queue(Live beatmap, bool forceOnlineFetch = false) { Logger.Log($"Queueing change for local beatmap {beatmap}"); - Task.Factory.StartNew(() => beatmap.PerformRead(b => Process(b)), default, TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously, updateScheduler); + Task.Factory.StartNew(() => beatmap.PerformRead(b => Process(b, forceOnlineFetch)), default, TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously, updateScheduler); } /// /// Run all processing on a beatmap immediately. /// - public void Process(BeatmapSetInfo beatmapSet) => beatmapSet.Realm.Write(r => + public void Process(BeatmapSetInfo beatmapSet, bool forceOnlineFetch = false) => beatmapSet.Realm.Write(r => { // Before we use below, we want to invalidate. workingBeatmapCache.Invalidate(beatmapSet); - // TODO: this call currently uses the local `online.db` lookup. - // We probably don't want this to happen after initial import (as the data may be stale). - metadataLookup.Update(beatmapSet); + metadataLookup.Update(beatmapSet, forceOnlineFetch); foreach (var beatmap in beatmapSet.Beatmaps) { diff --git a/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs b/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs index 94846599e8..c7c8f0ceb0 100644 --- a/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs +++ b/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs @@ -48,15 +48,15 @@ namespace osu.Game.Beatmaps prepareLocalCache(); } - public void Update(BeatmapSetInfo beatmapSet) + public void Update(BeatmapSetInfo beatmapSet, bool forceOnlineFetch) { foreach (var b in beatmapSet.Beatmaps) - lookup(beatmapSet, b); + lookup(beatmapSet, b, forceOnlineFetch); } - private void lookup(BeatmapSetInfo set, BeatmapInfo beatmapInfo) + private void lookup(BeatmapSetInfo set, BeatmapInfo beatmapInfo, bool forceOnlineFetch) { - if (checkLocalCache(set, beatmapInfo)) + if (!forceOnlineFetch && checkLocalCache(set, beatmapInfo)) return; if (api?.State.Value != APIState.Online) diff --git a/osu.Game/Database/RealmArchiveModelImporter.cs b/osu.Game/Database/RealmArchiveModelImporter.cs index a0cf98b978..b340d0ee4b 100644 --- a/osu.Game/Database/RealmArchiveModelImporter.cs +++ b/osu.Game/Database/RealmArchiveModelImporter.cs @@ -340,7 +340,7 @@ namespace osu.Game.Database // import to store realm.Add(item); - PostImport(item, realm); + PostImport(item, realm, batchImport); transaction.Commit(); } @@ -485,7 +485,8 @@ namespace osu.Game.Database /// /// The model prepared for import. /// The current realm context. - protected virtual void PostImport(TModel model, Realm realm) + /// Whether the import was part of a batch. + protected virtual void PostImport(TModel model, Realm realm, bool batchImport) { } diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 7b6cda17a2..6514fc6aee 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -287,7 +287,7 @@ namespace osu.Game AddInternal(new BeatmapOnlineChangeIngest(beatmapUpdater, realm, metadataClient)); - BeatmapManager.ProcessBeatmap = set => beatmapUpdater.Process(set); + BeatmapManager.ProcessBeatmap = (set, isBatch) => beatmapUpdater.Process(set, forceOnlineFetch: !isBatch); dependencies.Cache(userCache = new UserLookupCache()); AddInternal(userCache); diff --git a/osu.Game/Scoring/ScoreImporter.cs b/osu.Game/Scoring/ScoreImporter.cs index 4107c66dfe..0902f1636b 100644 --- a/osu.Game/Scoring/ScoreImporter.cs +++ b/osu.Game/Scoring/ScoreImporter.cs @@ -75,9 +75,9 @@ namespace osu.Game.Scoring model.StatisticsJson = JsonConvert.SerializeObject(model.Statistics); } - protected override void PostImport(ScoreInfo model, Realm realm) + protected override void PostImport(ScoreInfo model, Realm realm, bool batchImport) { - base.PostImport(model, realm); + base.PostImport(model, realm, batchImport); var userRequest = new GetUserRequest(model.RealmUser.Username); From cd01c5d3acefc5678be6dd6f7e3653acdbce8fc7 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Thu, 28 Jul 2022 16:34:31 +0900 Subject: [PATCH 149/278] Fix assertion --- .../Visual/Collections/TestSceneManageCollectionsDialog.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs b/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs index 13393254a6..4c89fc1ab9 100644 --- a/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs +++ b/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs @@ -254,7 +254,7 @@ namespace osu.Game.Tests.Visual.Collections }); assertCollectionName(0, "1"); - assertCollectionName(1, "1"); + assertCollectionName(1, "2"); AddStep("change first collection name", () => Realm.Write(_ => first.Name = "First")); From 6d4023b933dd97a65b9f3abe977f1671de8b91d0 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Thu, 28 Jul 2022 16:56:11 +0900 Subject: [PATCH 150/278] Adjust comment --- osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs b/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs index 07bd08d326..76339d4a1c 100644 --- a/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs +++ b/osu.Game.Tests/Database/BeatmapImporterUpdateTests.cs @@ -500,7 +500,7 @@ namespace osu.Game.Tests.Database beatmapCollection.BeatmapMD5Hashes.Add(originalHash); }); - // Second import matches first but contains one extra .osu file. + // Second import matches first but contains a modified .osu file. var importAfterUpdate = await importer.ImportAsUpdate(new ProgressNotification(), new ImportTask(pathModified), importBeforeUpdate.Value); Assert.That(importAfterUpdate, Is.Not.Null); From 8cb4fb35e005b414fd5055dd080e6f74313cf957 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 16:55:46 +0900 Subject: [PATCH 151/278] Rename parameter to read better (and still use local cache if no online API is available) --- osu.Game/Beatmaps/BeatmapUpdater.cs | 14 +++++++++----- .../Beatmaps/BeatmapUpdaterMetadataLookup.cs | 19 ++++++++++++++----- osu.Game/OsuGameBase.cs | 2 +- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapUpdater.cs b/osu.Game/Beatmaps/BeatmapUpdater.cs index a86aab4ac1..d7b1fac7b3 100644 --- a/osu.Game/Beatmaps/BeatmapUpdater.cs +++ b/osu.Game/Beatmaps/BeatmapUpdater.cs @@ -41,21 +41,25 @@ namespace osu.Game.Beatmaps /// /// Queue a beatmap for background processing. /// - public void Queue(Live beatmap, bool forceOnlineFetch = false) + /// The managed beatmap set to update. A transaction will be opened to apply changes. + /// Whether metadata from an online source should be preferred. If true, the local cache will be skipped to ensure the freshest data state possible. + public void Queue(Live beatmapSet, bool preferOnlineFetch = false) { - Logger.Log($"Queueing change for local beatmap {beatmap}"); - Task.Factory.StartNew(() => beatmap.PerformRead(b => Process(b, forceOnlineFetch)), default, TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously, updateScheduler); + Logger.Log($"Queueing change for local beatmap {beatmapSet}"); + Task.Factory.StartNew(() => beatmapSet.PerformRead(b => Process(b, preferOnlineFetch)), default, TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously, updateScheduler); } /// /// Run all processing on a beatmap immediately. /// - public void Process(BeatmapSetInfo beatmapSet, bool forceOnlineFetch = false) => beatmapSet.Realm.Write(r => + /// The managed beatmap set to update. A transaction will be opened to apply changes. + /// Whether metadata from an online source should be preferred. If true, the local cache will be skipped to ensure the freshest data state possible. + public void Process(BeatmapSetInfo beatmapSet, bool preferOnlineFetch = false) => beatmapSet.Realm.Write(r => { // Before we use below, we want to invalidate. workingBeatmapCache.Invalidate(beatmapSet); - metadataLookup.Update(beatmapSet, forceOnlineFetch); + metadataLookup.Update(beatmapSet, preferOnlineFetch); foreach (var beatmap in beatmapSet.Beatmaps) { diff --git a/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs b/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs index c7c8f0ceb0..02fb69b8f5 100644 --- a/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs +++ b/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs @@ -48,18 +48,27 @@ namespace osu.Game.Beatmaps prepareLocalCache(); } - public void Update(BeatmapSetInfo beatmapSet, bool forceOnlineFetch) + /// + /// Queue an update for a beatmap set. + /// + /// The beatmap set to update. Updates will be applied directly (so a transaction should be started if this instance is managed). + /// Whether metadata from an online source should be preferred. If true, the local cache will be skipped to ensure the freshest data state possible. + public void Update(BeatmapSetInfo beatmapSet, bool preferOnlineFetch) { foreach (var b in beatmapSet.Beatmaps) - lookup(beatmapSet, b, forceOnlineFetch); + lookup(beatmapSet, b, preferOnlineFetch); } - private void lookup(BeatmapSetInfo set, BeatmapInfo beatmapInfo, bool forceOnlineFetch) + private void lookup(BeatmapSetInfo set, BeatmapInfo beatmapInfo, bool preferOnlineFetch) { - if (!forceOnlineFetch && checkLocalCache(set, beatmapInfo)) + bool apiAvailable = api?.State.Value == APIState.Online; + + bool useLocalCache = !apiAvailable || !preferOnlineFetch; + + if (useLocalCache && checkLocalCache(set, beatmapInfo)) return; - if (api?.State.Value != APIState.Online) + if (!apiAvailable) return; var req = new GetBeatmapRequest(beatmapInfo); diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 6514fc6aee..41eeece76d 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -287,7 +287,7 @@ namespace osu.Game AddInternal(new BeatmapOnlineChangeIngest(beatmapUpdater, realm, metadataClient)); - BeatmapManager.ProcessBeatmap = (set, isBatch) => beatmapUpdater.Process(set, forceOnlineFetch: !isBatch); + BeatmapManager.ProcessBeatmap = (set, isBatch) => beatmapUpdater.Process(set, preferOnlineFetch: !isBatch); dependencies.Cache(userCache = new UserLookupCache()); AddInternal(userCache); From 628a30193ff7b94c10815d1c8d8be7db7b1e4187 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 17:49:17 +0900 Subject: [PATCH 152/278] Remove incorrect `TrackLoaded` override from `TestWorkingBeatmap` --- osu.Game/Tests/Beatmaps/TestWorkingBeatmap.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/osu.Game/Tests/Beatmaps/TestWorkingBeatmap.cs b/osu.Game/Tests/Beatmaps/TestWorkingBeatmap.cs index 2306fd1c3e..3d7ebad831 100644 --- a/osu.Game/Tests/Beatmaps/TestWorkingBeatmap.cs +++ b/osu.Game/Tests/Beatmaps/TestWorkingBeatmap.cs @@ -31,8 +31,6 @@ namespace osu.Game.Tests.Beatmaps this.storyboard = storyboard; } - public override bool TrackLoaded => true; - public override bool BeatmapLoaded => true; protected override IBeatmap GetBeatmap() => beatmap; From 1039338d804dd33faf12ec8bc96b361cad280de4 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Thu, 28 Jul 2022 17:58:07 +0900 Subject: [PATCH 153/278] Fix intermittent HUD tests --- osu.Game.Tests/Visual/Gameplay/TestSceneHUDOverlay.cs | 1 + osu.Game.Tests/Visual/Gameplay/TestSceneSkinEditor.cs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneHUDOverlay.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneHUDOverlay.cs index dd0f965914..fb97f94dbb 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneHUDOverlay.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneHUDOverlay.cs @@ -159,6 +159,7 @@ namespace osu.Game.Tests.Visual.Gameplay AddUntilStep("wait for hud load", () => hudOverlay.IsLoaded); AddUntilStep("wait for components to be hidden", () => hudOverlay.ChildrenOfType().Single().Alpha == 0); + AddUntilStep("wait for hud load", () => hudOverlay.ChildrenOfType().All(c => c.ComponentsLoaded)); AddStep("bind on update", () => { diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSkinEditor.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSkinEditor.cs index f319290441..bd274dfef5 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSkinEditor.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSkinEditor.cs @@ -14,6 +14,7 @@ using osu.Game.Overlays.Settings; using osu.Game.Rulesets; using osu.Game.Rulesets.Osu; using osu.Game.Screens.Play.HUD.HitErrorMeters; +using osu.Game.Skinning; using osu.Game.Skinning.Editor; using osuTK.Input; @@ -33,6 +34,8 @@ namespace osu.Game.Tests.Visual.Gameplay { base.SetUpSteps(); + AddUntilStep("wait for hud load", () => Player.ChildrenOfType().All(c => c.ComponentsLoaded)); + AddStep("reload skin editor", () => { skinEditor?.Expire(); From a21aee4e9cabcbb71fb74e0185c0cc62f3de737d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 17:58:13 +0900 Subject: [PATCH 154/278] Reduce calls to `LoadTrack` by implicitly running on test/dummy classes --- .../Gameplay/TestSceneMasterGameplayClockContainer.cs | 6 ------ osu.Game.Tests/Gameplay/TestSceneStoryboardSamples.cs | 2 -- osu.Game.Tests/Skins/TestSceneBeatmapSkinResources.cs | 7 +++++-- osu.Game.Tests/Visual/Gameplay/TestSceneSkipOverlay.cs | 1 - osu.Game/Beatmaps/DummyWorkingBeatmap.cs | 4 ++++ osu.Game/Overlays/FirstRunSetup/ScreenUIScale.cs | 1 - osu.Game/Tests/Visual/OsuTestScene.cs | 5 +++++ 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/osu.Game.Tests/Gameplay/TestSceneMasterGameplayClockContainer.cs b/osu.Game.Tests/Gameplay/TestSceneMasterGameplayClockContainer.cs index 0395ae9d99..5f403f9487 100644 --- a/osu.Game.Tests/Gameplay/TestSceneMasterGameplayClockContainer.cs +++ b/osu.Game.Tests/Gameplay/TestSceneMasterGameplayClockContainer.cs @@ -41,8 +41,6 @@ namespace osu.Game.Tests.Gameplay AddStep("create container", () => { var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo); - working.LoadTrack(); - Child = gameplayClockContainer = new MasterGameplayClockContainer(working, 0); }); @@ -58,8 +56,6 @@ namespace osu.Game.Tests.Gameplay AddStep("create container", () => { var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo); - working.LoadTrack(); - Child = gameplayClockContainer = new MasterGameplayClockContainer(working, 0); }); @@ -102,8 +98,6 @@ namespace osu.Game.Tests.Gameplay AddStep("create container", () => { working = new ClockBackedTestWorkingBeatmap(new OsuRuleset().RulesetInfo, new FramedClock(new ManualClock()), Audio); - working.LoadTrack(); - Child = gameplayClockContainer = new MasterGameplayClockContainer(working, 0); gameplayClockContainer.Reset(startClock: !whileStopped); diff --git a/osu.Game.Tests/Gameplay/TestSceneStoryboardSamples.cs b/osu.Game.Tests/Gameplay/TestSceneStoryboardSamples.cs index a9c6bacc65..a432cc9648 100644 --- a/osu.Game.Tests/Gameplay/TestSceneStoryboardSamples.cs +++ b/osu.Game.Tests/Gameplay/TestSceneStoryboardSamples.cs @@ -69,7 +69,6 @@ namespace osu.Game.Tests.Gameplay AddStep("create container", () => { var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo); - working.LoadTrack(); Add(gameplayContainer = new MasterGameplayClockContainer(working, 0) { @@ -96,7 +95,6 @@ namespace osu.Game.Tests.Gameplay AddStep("create container", () => { var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo); - working.LoadTrack(); const double start_time = 1000; diff --git a/osu.Game.Tests/Skins/TestSceneBeatmapSkinResources.cs b/osu.Game.Tests/Skins/TestSceneBeatmapSkinResources.cs index f4cea2c8cc..e82a5b57d9 100644 --- a/osu.Game.Tests/Skins/TestSceneBeatmapSkinResources.cs +++ b/osu.Game.Tests/Skins/TestSceneBeatmapSkinResources.cs @@ -32,7 +32,6 @@ namespace osu.Game.Tests.Skins imported?.PerformRead(s => { beatmap = beatmaps.GetWorkingBeatmap(s.Beatmaps[0]); - beatmap.LoadTrack(); }); } @@ -40,6 +39,10 @@ namespace osu.Game.Tests.Skins public void TestRetrieveOggSample() => AddAssert("sample is non-null", () => beatmap.Skin.GetSample(new SampleInfo("sample")) != null); [Test] - public void TestRetrieveOggTrack() => AddAssert("track is non-null", () => !(beatmap.Track is TrackVirtual)); + public void TestRetrieveOggTrack() => AddAssert("track is non-null", () => + { + using (var track = beatmap.LoadTrack()) + return track is not TrackVirtual; + }); } } diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSkipOverlay.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSkipOverlay.cs index e1fc65404d..5c73db15df 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSkipOverlay.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSkipOverlay.cs @@ -33,7 +33,6 @@ namespace osu.Game.Tests.Visual.Gameplay increment = skip_time; var working = CreateWorkingBeatmap(CreateBeatmap(new OsuRuleset().RulesetInfo)); - working.LoadTrack(); Child = gameplayClockContainer = new MasterGameplayClockContainer(working, 0) { diff --git a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs index 9610dbcc78..0b390a2ab5 100644 --- a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs +++ b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs @@ -44,6 +44,10 @@ namespace osu.Game.Beatmaps }, audio) { this.textures = textures; + + // We are guaranteed to have a virtual track. + // To ease usability, ensure the track is available from point of construction. + LoadTrack(); } protected override IBeatmap GetBeatmap() => new Beatmap(); diff --git a/osu.Game/Overlays/FirstRunSetup/ScreenUIScale.cs b/osu.Game/Overlays/FirstRunSetup/ScreenUIScale.cs index 58bfced3ed..0d4496a6a3 100644 --- a/osu.Game/Overlays/FirstRunSetup/ScreenUIScale.cs +++ b/osu.Game/Overlays/FirstRunSetup/ScreenUIScale.cs @@ -161,7 +161,6 @@ namespace osu.Game.Overlays.FirstRunSetup private void load(AudioManager audio, TextureStore textures, RulesetStore rulesets) { Beatmap.Value = new DummyWorkingBeatmap(audio, textures); - Beatmap.Value.LoadTrack(); Ruleset.Value = rulesets.AvailableRulesets.First(); diff --git a/osu.Game/Tests/Visual/OsuTestScene.cs b/osu.Game/Tests/Visual/OsuTestScene.cs index 012c512266..5a297fd109 100644 --- a/osu.Game/Tests/Visual/OsuTestScene.cs +++ b/osu.Game/Tests/Visual/OsuTestScene.cs @@ -365,6 +365,11 @@ namespace osu.Game.Tests.Visual } else track = audio?.Tracks.GetVirtual(trackLength); + + // We are guaranteed to have a virtual track. + // To ease testability, ensure the track is available from point of construction. + // (Usually this would be done by MusicController for us). + LoadTrack(); } ~ClockBackedTestWorkingBeatmap() From 71085538833a34e5eeea9b8087a531008394608a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 18:20:08 +0900 Subject: [PATCH 155/278] Tidy up various things everywhere --- .../Visual/Gameplay/TestSceneSongProgress.cs | 35 ++++++++++--------- .../Screens/Play/HUD/DefaultSongProgress.cs | 2 -- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs index 3f81757fcd..5e9cf8839d 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Collections.Generic; using System.Linq; using NUnit.Framework; @@ -11,6 +9,7 @@ using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics; using osu.Framework.Testing; using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.Osu; using osu.Game.Screens.Play; using osu.Game.Screens.Play.HUD; using osu.Game.Skinning; @@ -20,18 +19,20 @@ namespace osu.Game.Tests.Visual.Gameplay [TestFixture] public class TestSceneSongProgress : SkinnableHUDComponentTestScene { - private DefaultSongProgress progress => this.ChildrenOfType().Single(); - private GameplayClockContainer gameplayClockContainer; - private const double gameplay_start_time = -2000; + private GameplayClockContainer gameplayClockContainer = null!; + + private const double skip_target_time = -2000; [BackgroundDependencyLoader] private void load() { - var working = CreateWorkingBeatmap(Ruleset.Value); - working.LoadTrack(); - Add(gameplayClockContainer = new MasterGameplayClockContainer(working, gameplay_start_time)); - Dependencies.CacheAs(gameplayClockContainer); - Dependencies.CacheAs(gameplayClockContainer.GameplayClock); + Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo); + Beatmap.Value.LoadTrack(); + + Add(gameplayClockContainer = new MasterGameplayClockContainer(Beatmap.Value, skip_target_time)); + + Dependencies.CacheAs(gameplayClockContainer); // required for StartTime + Dependencies.CacheAs(gameplayClockContainer.GameplayClock); // required for everything else } [SetUpSteps] @@ -44,7 +45,7 @@ namespace osu.Game.Tests.Visual.Gameplay [Test] public void TestDisplay() { - AddStep("seek to intro", () => gameplayClockContainer.Seek(gameplay_start_time)); + AddStep("seek to intro", () => gameplayClockContainer.Seek(skip_target_time)); AddStep("start", gameplayClockContainer.Start); AddStep("stop", gameplayClockContainer.Stop); } @@ -52,11 +53,13 @@ namespace osu.Game.Tests.Visual.Gameplay [Test] public void TestToggleSeeking() { - AddStep("allow seeking", () => progress.AllowSeeking.Value = true); - AddStep("hide graph", () => progress.ShowGraph.Value = false); - AddStep("disallow seeking", () => progress.AllowSeeking.Value = false); - AddStep("allow seeking", () => progress.AllowSeeking.Value = true); - AddStep("show graph", () => progress.ShowGraph.Value = true); + DefaultSongProgress getDefaultProgress() => this.ChildrenOfType().Single(); + + AddStep("allow seeking", () => getDefaultProgress().AllowSeeking.Value = true); + AddStep("hide graph", () => getDefaultProgress().ShowGraph.Value = false); + AddStep("disallow seeking", () => getDefaultProgress().AllowSeeking.Value = false); + AddStep("allow seeking", () => getDefaultProgress().AllowSeeking.Value = true); + AddStep("show graph", () => getDefaultProgress().ShowGraph.Value = true); } private void setHitObjects() diff --git a/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs b/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs index 654884c0d5..ac184c6407 100644 --- a/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs +++ b/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs @@ -19,8 +19,6 @@ namespace osu.Game.Screens.Play.HUD { public class DefaultSongProgress : SongProgress { - public const float MAX_HEIGHT = info_height + bottom_bar_height + graph_height + handle_height; - private const float info_height = 20; private const float bottom_bar_height = 5; private const float graph_height = SquareGraph.Column.WIDTH * 6; From d5e5761892138216f2d55ff0e6b6bc6dcaec8a59 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 18:25:24 +0900 Subject: [PATCH 156/278] Fix `DefaultSongProgress` graph not resetting if time is in intro --- osu.Game/Screens/Play/HUD/DefaultSongProgress.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs b/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs index ac184c6407..36b172cb44 100644 --- a/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs +++ b/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs @@ -185,7 +185,9 @@ namespace osu.Game.Screens.Play.HUD { bar.CurrentTime = gameplayClock?.CurrentTime ?? Time.Current; - if (!isIntro) + if (isIntro) + graph.Progress = 0; + else graph.Progress = (int)(graph.ColumnCount * progress); } From bfa026879c342fa1c44c46ac6cae6d5a83551252 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 18:28:03 +0900 Subject: [PATCH 157/278] Remove pointless null check --- osu.Game/Skinning/LegacySongProgress.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/osu.Game/Skinning/LegacySongProgress.cs b/osu.Game/Skinning/LegacySongProgress.cs index 0d1110df47..963209d4ce 100644 --- a/osu.Game/Skinning/LegacySongProgress.cs +++ b/osu.Game/Skinning/LegacySongProgress.cs @@ -15,7 +15,7 @@ namespace osu.Game.Skinning { public class LegacySongProgress : SongProgress { - private CircularProgress? pie; + private CircularProgress pie = null!; [BackgroundDependencyLoader] private void load() @@ -72,9 +72,6 @@ namespace osu.Game.Skinning protected override void UpdateProgress(double progress, bool isIntro) { - if (pie == null) - return; - if (isIntro) { pie.Scale = new Vector2(-1, 1); From ea027eda46ebdb8ed8b13674fcbbdca3b96360c4 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 18:29:49 +0900 Subject: [PATCH 158/278] Move initial show to base implementation and add transition for legacy version --- osu.Game/Screens/Play/HUD/DefaultSongProgress.cs | 2 -- osu.Game/Screens/Play/HUD/SongProgress.cs | 9 ++++++++- osu.Game/Skinning/LegacySongProgress.cs | 8 ++------ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs b/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs index 36b172cb44..b4eade0709 100644 --- a/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs +++ b/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs @@ -104,8 +104,6 @@ namespace osu.Game.Screens.Play.HUD protected override void LoadComplete() { - Show(); - AllowSeeking.BindValueChanged(_ => updateBarVisibility(), true); ShowGraph.BindValueChanged(_ => updateGraphVisibility(), true); diff --git a/osu.Game/Screens/Play/HUD/SongProgress.cs b/osu.Game/Screens/Play/HUD/SongProgress.cs index 78f0142dba..35847b4b16 100644 --- a/osu.Game/Screens/Play/HUD/SongProgress.cs +++ b/osu.Game/Screens/Play/HUD/SongProgress.cs @@ -36,13 +36,20 @@ namespace osu.Game.Screens.Play.HUD } } + protected override void LoadComplete() + { + base.LoadComplete(); + + Show(); + } + protected double FirstHitTime { get; private set; } //TODO: this isn't always correct (consider mania where a non-last object may last for longer than the last in the list). protected double LastHitTime { get; private set; } protected abstract void UpdateProgress(double progress, bool isIntro); - protected abstract void UpdateObjects(IEnumerable? objects); + protected virtual void UpdateObjects(IEnumerable? objects) { } [BackgroundDependencyLoader] private void load() diff --git a/osu.Game/Skinning/LegacySongProgress.cs b/osu.Game/Skinning/LegacySongProgress.cs index 963209d4ce..3fba0e5abe 100644 --- a/osu.Game/Skinning/LegacySongProgress.cs +++ b/osu.Game/Skinning/LegacySongProgress.cs @@ -1,13 +1,11 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Collections.Generic; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.UserInterface; -using osu.Game.Rulesets.Objects; using osu.Game.Screens.Play.HUD; using osuTK; @@ -60,14 +58,12 @@ namespace osu.Game.Skinning protected override void PopIn() { + this.FadeIn(500, Easing.OutQuint); } protected override void PopOut() { - } - - protected override void UpdateObjects(IEnumerable? objects) - { + this.FadeOut(100); } protected override void UpdateProgress(double progress, bool isIntro) From 86c2b7e449ed0dd670480e9826f46b695fa4113d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 18:37:17 +0900 Subject: [PATCH 159/278] Apply nullability to `DefaultSongProgress` and clean up more stuff --- .../Screens/Play/HUD/DefaultSongProgress.cs | 65 ++++++++----------- osu.Game/Screens/Play/HUD/SongProgress.cs | 31 +++++---- 2 files changed, 46 insertions(+), 50 deletions(-) diff --git a/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs b/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs index b4eade0709..7b9453f2ed 100644 --- a/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs +++ b/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs @@ -1,9 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - -using System; using System.Collections.Generic; using osu.Framework.Allocation; using osu.Framework.Bindables; @@ -32,8 +29,6 @@ namespace osu.Game.Screens.Play.HUD private readonly SongProgressGraph graph; private readonly SongProgressInfo info; - public Action RequestSeek; - /// /// Whether seeking is allowed and the progress bar should be shown. /// @@ -47,14 +42,20 @@ namespace osu.Game.Screens.Play.HUD protected override bool BlockScrollInput => false; - [Resolved(canBeNull: true)] - private GameplayClock gameplayClock { get; set; } + [Resolved] + private GameplayClock? gameplayClock { get; set; } - [Resolved(canBeNull: true)] - private Player player { get; set; } + [Resolved] + private Player? player { get; set; } - [Resolved(canBeNull: true)] - private DrawableRuleset drawableRuleset { get; set; } + [Resolved] + private DrawableRuleset? drawableRuleset { get; set; } + + [Resolved] + private OsuConfigManager config { get; set; } = null!; + + [Resolved] + private SkinManager skinManager { get; set; } = null!; public DefaultSongProgress() { @@ -110,12 +111,6 @@ namespace osu.Game.Screens.Play.HUD migrateSettingFromConfig(); } - [Resolved] - private OsuConfigManager config { get; set; } - - [Resolved] - private SkinManager skinManager { get; set; } - /// /// This setting has been migrated to a per-component level. /// Only take the value from the config if it is in a non-default state (then reset it to default so it only applies once). @@ -131,29 +126,26 @@ namespace osu.Game.Screens.Play.HUD ShowGraph.Value = configShowGraph.Value; // This is pretty ugly, but the only way to make this stick... - if (skinManager != null) + var skinnableTarget = this.FindClosestParent(); + + if (skinnableTarget != null) { - var skinnableTarget = this.FindClosestParent(); + // If the skin is not mutable, a mutable instance will be created, causing this migration logic to run again on the correct skin. + // Therefore we want to avoid resetting the config value on this invocation. + if (skinManager.EnsureMutableSkin()) + return; - if (skinnableTarget != null) + // If `EnsureMutableSkin` actually changed the skin, default layout may take a frame to apply. + // See `SkinnableTargetComponentsContainer`'s use of ScheduleAfterChildren. + ScheduleAfterChildren(() => { - // If the skin is not mutable, a mutable instance will be created, causing this migration logic to run again on the correct skin. - // Therefore we want to avoid resetting the config value on this invocation. - if (skinManager.EnsureMutableSkin()) - return; + var skin = skinManager.CurrentSkin.Value; + skin.UpdateDrawableTarget(skinnableTarget); - // If `EnsureMutableSkin` actually changed the skin, default layout may take a frame to apply. - // See `SkinnableTargetComponentsContainer`'s use of ScheduleAfterChildren. - ScheduleAfterChildren(() => - { - var skin = skinManager.CurrentSkin.Value; - skin.UpdateDrawableTarget(skinnableTarget); + skinManager.Save(skin); + }); - skinManager.Save(skin); - }); - - configShowGraph.SetDefault(); - } + configShowGraph.SetDefault(); } } } @@ -170,8 +162,7 @@ namespace osu.Game.Screens.Play.HUD protected override void UpdateObjects(IEnumerable objects) { - if (objects != null) - graph.Objects = objects; + graph.Objects = objects; info.StartTime = FirstHitTime; info.EndTime = LastHitTime; diff --git a/osu.Game/Screens/Play/HUD/SongProgress.cs b/osu.Game/Screens/Play/HUD/SongProgress.cs index 35847b4b16..aaef141349 100644 --- a/osu.Game/Screens/Play/HUD/SongProgress.cs +++ b/osu.Game/Screens/Play/HUD/SongProgress.cs @@ -30,8 +30,9 @@ namespace osu.Game.Screens.Play.HUD set { objects = value; - FirstHitTime = objects?.FirstOrDefault()?.StartTime ?? 0; - LastHitTime = objects?.LastOrDefault()?.GetEndTime() ?? 0; + FirstHitTime = objects.FirstOrDefault()?.StartTime ?? 0; + //TODO: this isn't always correct (consider mania where a non-last object may last for longer than the last in the list). + LastHitTime = objects.LastOrDefault()?.GetEndTime() ?? 0; UpdateObjects(objects); } } @@ -45,11 +46,10 @@ namespace osu.Game.Screens.Play.HUD protected double FirstHitTime { get; private set; } - //TODO: this isn't always correct (consider mania where a non-last object may last for longer than the last in the list). protected double LastHitTime { get; private set; } protected abstract void UpdateProgress(double progress, bool isIntro); - protected virtual void UpdateObjects(IEnumerable? objects) { } + protected virtual void UpdateObjects(IEnumerable objects) { } [BackgroundDependencyLoader] private void load() @@ -70,20 +70,25 @@ namespace osu.Game.Screens.Play.HUD // The reference clock is used to accurately tell the playfield's time. This is obtained from the drawable ruleset. // However, if no drawable ruleset is available (i.e. used in tests), we fall back to either the gameplay clock container or this drawable's own clock. - double gameplayTime = referenceClock?.CurrentTime ?? gameplayClockContainer?.GameplayClock.CurrentTime ?? Time.Current; + double currentTime = referenceClock?.CurrentTime ?? gameplayClockContainer?.GameplayClock.CurrentTime ?? Time.Current; - if (gameplayTime < FirstHitTime) + bool isInIntro = currentTime < FirstHitTime; + + if (isInIntro) { - double earliest = gameplayClockContainer?.StartTime ?? 0; - double introDuration = FirstHitTime - earliest; - double currentIntroTime = gameplayTime - earliest; - UpdateProgress(currentIntroTime / introDuration, true); + double introStartTime = gameplayClockContainer?.StartTime ?? 0; + + double introOffsetCurrent = currentTime - introStartTime; + double introDuration = FirstHitTime - introStartTime; + + UpdateProgress(introOffsetCurrent / introDuration, true); } else { - double duration = LastHitTime - FirstHitTime; - double currentTime = gameplayTime - FirstHitTime; - UpdateProgress(currentTime / duration, false); + double objectOffsetCurrent = currentTime - FirstHitTime; + + double objectDuration = LastHitTime - FirstHitTime; + UpdateProgress(objectOffsetCurrent / objectDuration, false); } } } From 4b140e1f5a3fbcccc816eb91c8a3b51f6219342d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 18:49:37 +0900 Subject: [PATCH 160/278] Adjust metrics --- osu.Game/Skinning/LegacySongProgress.cs | 26 ++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/osu.Game/Skinning/LegacySongProgress.cs b/osu.Game/Skinning/LegacySongProgress.cs index 3fba0e5abe..f828e301f2 100644 --- a/osu.Game/Skinning/LegacySongProgress.cs +++ b/osu.Game/Skinning/LegacySongProgress.cs @@ -13,22 +13,22 @@ namespace osu.Game.Skinning { public class LegacySongProgress : SongProgress { - private CircularProgress pie = null!; + private CircularProgress circularProgress = null!; [BackgroundDependencyLoader] private void load() { - Size = new Vector2(35); + Size = new Vector2(33); InternalChildren = new Drawable[] { new Container { - Size = new Vector2(0.95f), Anchor = Anchor.Centre, Origin = Anchor.Centre, RelativeSizeAxes = Axes.Both, - Child = pie = new CircularProgress + Size = new Vector2(0.92f), + Child = circularProgress = new CircularProgress { RelativeSizeAxes = Axes.Both, }, @@ -51,7 +51,7 @@ namespace osu.Game.Skinning Anchor = Anchor.Centre, Origin = Anchor.Centre, Colour = Colour4.White, - Size = new Vector2(3), + Size = new Vector2(4), } }; } @@ -70,17 +70,17 @@ namespace osu.Game.Skinning { if (isIntro) { - pie.Scale = new Vector2(-1, 1); - pie.Anchor = Anchor.TopRight; - pie.Colour = new Colour4(199, 255, 47, 153); - pie.Current.Value = 1 - progress; + circularProgress.Scale = new Vector2(-1, 1); + circularProgress.Anchor = Anchor.TopRight; + circularProgress.Colour = new Colour4(199, 255, 47, 153); + circularProgress.Current.Value = 1 - progress; } else { - pie.Scale = new Vector2(1); - pie.Anchor = Anchor.TopLeft; - pie.Colour = new Colour4(255, 255, 255, 153); - pie.Current.Value = progress; + circularProgress.Scale = new Vector2(1); + circularProgress.Anchor = Anchor.TopLeft; + circularProgress.Colour = new Colour4(255, 255, 255, 153); + circularProgress.Current.Value = progress; } } } From ce694123ebeb2b0364c149a28e8f290828aed30d Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Thu, 28 Jul 2022 20:44:02 +0900 Subject: [PATCH 161/278] Move spectator begin/end playing to SubmittingPlayer --- .../Gameplay/TestSceneSpectatorPlayback.cs | 59 +++++++++---------- osu.Game/Rulesets/UI/ReplayRecorder.cs | 12 ---- osu.Game/Screens/Play/Player.cs | 9 --- osu.Game/Screens/Play/SubmittingPlayer.cs | 9 +++ 4 files changed, 37 insertions(+), 52 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSpectatorPlayback.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSpectatorPlayback.cs index 5fad661e9b..9c41c70a0e 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSpectatorPlayback.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSpectatorPlayback.cs @@ -27,7 +27,6 @@ using osu.Game.Rulesets.Replays; using osu.Game.Rulesets.Replays.Types; using osu.Game.Rulesets.UI; using osu.Game.Scoring; -using osu.Game.Screens.Play; using osu.Game.Tests.Gameplay; using osu.Game.Tests.Mods; using osu.Game.Tests.Visual.Spectator; @@ -41,16 +40,12 @@ namespace osu.Game.Tests.Visual.Gameplay private TestRulesetInputManager playbackManager; private TestRulesetInputManager recordingManager; - private Replay replay; - + private Score recordingScore; + private Replay playbackReplay; private TestSpectatorClient spectatorClient; - private ManualClock manualClock; - private TestReplayRecorder recorder; - private OsuSpriteText latencyDisplay; - private TestFramedReplayInputHandler replayHandler; [SetUpSteps] @@ -58,7 +53,16 @@ namespace osu.Game.Tests.Visual.Gameplay { AddStep("Setup containers", () => { - replay = new Replay(); + recordingScore = new Score + { + ScoreInfo = + { + BeatmapInfo = new BeatmapInfo(), + Ruleset = new OsuRuleset().RulesetInfo, + } + }; + + playbackReplay = new Replay(); manualClock = new ManualClock(); Child = new DependencyProvidingContainer @@ -67,7 +71,6 @@ namespace osu.Game.Tests.Visual.Gameplay CachedDependencies = new[] { (typeof(SpectatorClient), (object)(spectatorClient = new TestSpectatorClient())), - (typeof(GameplayState), TestGameplayState.Create(new OsuRuleset())) }, Children = new Drawable[] { @@ -81,7 +84,7 @@ namespace osu.Game.Tests.Visual.Gameplay { recordingManager = new TestRulesetInputManager(TestCustomisableModRuleset.CreateTestRulesetInfo(), 0, SimultaneousBindingMode.Unique) { - Recorder = recorder = new TestReplayRecorder + Recorder = recorder = new TestReplayRecorder(recordingScore) { ScreenSpaceToGamefield = pos => recordingManager.ToLocalSpace(pos), }, @@ -112,7 +115,7 @@ namespace osu.Game.Tests.Visual.Gameplay playbackManager = new TestRulesetInputManager(TestCustomisableModRuleset.CreateTestRulesetInfo(), 0, SimultaneousBindingMode.Unique) { Clock = new FramedClock(manualClock), - ReplayInputHandler = replayHandler = new TestFramedReplayInputHandler(replay) + ReplayInputHandler = replayHandler = new TestFramedReplayInputHandler(playbackReplay) { GamefieldToScreenSpace = pos => playbackManager.ToScreenSpace(pos), }, @@ -144,6 +147,7 @@ namespace osu.Game.Tests.Visual.Gameplay } }; + spectatorClient.BeginPlaying(TestGameplayState.Create(new OsuRuleset()), recordingScore); spectatorClient.OnNewFrames += onNewFrames; }); } @@ -151,15 +155,15 @@ namespace osu.Game.Tests.Visual.Gameplay [Test] public void TestBasic() { - AddUntilStep("received frames", () => replay.Frames.Count > 50); + AddUntilStep("received frames", () => playbackReplay.Frames.Count > 50); AddStep("stop sending frames", () => recorder.Expire()); - AddUntilStep("wait for all frames received", () => replay.Frames.Count == recorder.SentFrames.Count); + AddUntilStep("wait for all frames received", () => playbackReplay.Frames.Count == recorder.SentFrames.Count); } [Test] public void TestWithSendFailure() { - AddUntilStep("received frames", () => replay.Frames.Count > 50); + AddUntilStep("received frames", () => playbackReplay.Frames.Count > 50); int framesReceivedSoFar = 0; int frameSendAttemptsSoFar = 0; @@ -172,21 +176,21 @@ namespace osu.Game.Tests.Visual.Gameplay AddUntilStep("wait for next send attempt", () => { - framesReceivedSoFar = replay.Frames.Count; + framesReceivedSoFar = playbackReplay.Frames.Count; return spectatorClient.FrameSendAttempts > frameSendAttemptsSoFar + 1; }); AddUntilStep("wait for more send attempts", () => spectatorClient.FrameSendAttempts > frameSendAttemptsSoFar + 10); - AddAssert("frames did not increase", () => framesReceivedSoFar == replay.Frames.Count); + AddAssert("frames did not increase", () => framesReceivedSoFar == playbackReplay.Frames.Count); AddStep("stop failing sends", () => spectatorClient.ShouldFailSendingFrames = false); - AddUntilStep("wait for next frames", () => framesReceivedSoFar < replay.Frames.Count); + AddUntilStep("wait for next frames", () => framesReceivedSoFar < playbackReplay.Frames.Count); AddStep("stop sending frames", () => recorder.Expire()); - AddUntilStep("wait for all frames received", () => replay.Frames.Count == recorder.SentFrames.Count); - AddAssert("ensure frames were received in the correct sequence", () => replay.Frames.Select(f => f.Time).SequenceEqual(recorder.SentFrames.Select(f => f.Time))); + AddUntilStep("wait for all frames received", () => playbackReplay.Frames.Count == recorder.SentFrames.Count); + AddAssert("ensure frames were received in the correct sequence", () => playbackReplay.Frames.Select(f => f.Time).SequenceEqual(recorder.SentFrames.Select(f => f.Time))); } private void onNewFrames(int userId, FrameDataBundle frames) @@ -195,10 +199,10 @@ namespace osu.Game.Tests.Visual.Gameplay { var frame = new TestReplayFrame(); frame.FromLegacy(legacyFrame, null); - replay.Frames.Add(frame); + playbackReplay.Frames.Add(frame); } - Logger.Log($"Received {frames.Frames.Count} new frames (total {replay.Frames.Count} of {recorder.SentFrames.Count})"); + Logger.Log($"Received {frames.Frames.Count} new frames (total {playbackReplay.Frames.Count} of {recorder.SentFrames.Count})"); } private double latency = SpectatorClient.TIME_BETWEEN_SENDS; @@ -219,7 +223,7 @@ namespace osu.Game.Tests.Visual.Gameplay if (!replayHandler.HasFrames) return; - var lastFrame = replay.Frames.LastOrDefault(); + var lastFrame = playbackReplay.Frames.LastOrDefault(); // this isn't perfect as we basically can't be aware of the rate-of-send here (the streamer is not sending data when not being moved). // in gameplay playback, the case where NextFrame is null would pause gameplay and handle this correctly; it's strictly a test limitation / best effort implementation. @@ -360,15 +364,8 @@ namespace osu.Game.Tests.Visual.Gameplay { public List SentFrames = new List(); - public TestReplayRecorder() - : base(new Score - { - ScoreInfo = - { - BeatmapInfo = new BeatmapInfo(), - Ruleset = new OsuRuleset().RulesetInfo, - } - }) + public TestReplayRecorder(Score score) + : base(score) { } diff --git a/osu.Game/Rulesets/UI/ReplayRecorder.cs b/osu.Game/Rulesets/UI/ReplayRecorder.cs index b04807e475..79da56fc8a 100644 --- a/osu.Game/Rulesets/UI/ReplayRecorder.cs +++ b/osu.Game/Rulesets/UI/ReplayRecorder.cs @@ -14,7 +14,6 @@ using osu.Framework.Input.Events; using osu.Game.Online.Spectator; using osu.Game.Rulesets.Replays; using osu.Game.Scoring; -using osu.Game.Screens.Play; using osuTK; namespace osu.Game.Rulesets.UI @@ -33,9 +32,6 @@ namespace osu.Game.Rulesets.UI [Resolved] private SpectatorClient spectatorClient { get; set; } - [Resolved] - private GameplayState gameplayState { get; set; } - protected ReplayRecorder(Score target) { this.target = target; @@ -48,15 +44,7 @@ namespace osu.Game.Rulesets.UI protected override void LoadComplete() { base.LoadComplete(); - inputManager = GetContainingInputManager(); - spectatorClient.BeginPlaying(gameplayState, target); - } - - protected override void Dispose(bool isDisposing) - { - base.Dispose(isDisposing); - spectatorClient?.EndPlaying(gameplayState); } protected override void Update() diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 9a058e45c5..9c08c77d91 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -26,7 +26,6 @@ using osu.Game.Extensions; using osu.Game.Graphics.Containers; using osu.Game.IO.Archives; using osu.Game.Online.API; -using osu.Game.Online.Spectator; using osu.Game.Overlays; using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; @@ -101,9 +100,6 @@ namespace osu.Game.Screens.Play [Resolved] private MusicController musicController { get; set; } - [Resolved] - private SpectatorClient spectatorClient { get; set; } - public GameplayState GameplayState { get; private set; } private Ruleset ruleset; @@ -1030,11 +1026,6 @@ namespace osu.Game.Screens.Play // if arriving here and the results screen preparation task hasn't run, it's safe to say the user has not completed the beatmap. if (prepareScoreForDisplayTask == null) ScoreProcessor.FailScore(Score.ScoreInfo); - - // EndPlaying() is typically called from ReplayRecorder.Dispose(). Disposal is currently asynchronous. - // To resolve test failures, forcefully end playing synchronously when this screen exits. - // Todo: Replace this with a more permanent solution once osu-framework has a synchronous cleanup method. - spectatorClient.EndPlaying(GameplayState); } // GameplayClockContainer performs seeks / start / stop operations on the beatmap's track. diff --git a/osu.Game/Screens/Play/SubmittingPlayer.cs b/osu.Game/Screens/Play/SubmittingPlayer.cs index ad63925b93..02a95ae9eb 100644 --- a/osu.Game/Screens/Play/SubmittingPlayer.cs +++ b/osu.Game/Screens/Play/SubmittingPlayer.cs @@ -15,6 +15,7 @@ using osu.Game.Beatmaps; using osu.Game.Database; using osu.Game.Online.API; using osu.Game.Online.Rooms; +using osu.Game.Online.Spectator; using osu.Game.Rulesets.Scoring; using osu.Game.Scoring; @@ -33,6 +34,9 @@ namespace osu.Game.Screens.Play [Resolved] private IAPIProvider api { get; set; } + [Resolved] + private SpectatorClient spectatorClient { get; set; } + private TaskCompletionSource scoreSubmissionSource; protected SubmittingPlayer(PlayerConfiguration configuration = null) @@ -134,6 +138,8 @@ namespace osu.Game.Screens.Play if (realmBeatmap != null) realmBeatmap.LastPlayed = DateTimeOffset.Now; }); + + spectatorClient.BeginPlaying(GameplayState, Score); } public override bool OnExiting(ScreenExitEvent e) @@ -141,7 +147,10 @@ namespace osu.Game.Screens.Play bool exiting = base.OnExiting(e); if (LoadedBeatmapSuccessfully) + { submitScore(Score.DeepClone()); + spectatorClient.EndPlaying(GameplayState); + } return exiting; } From e664690fe2051d529861347183784f2e3f2ba550 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jul 2022 22:19:46 +0900 Subject: [PATCH 162/278] Remove unnecessary `LoadTrack` call --- osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs index 5e9cf8839d..428c056fc6 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs @@ -27,7 +27,6 @@ namespace osu.Game.Tests.Visual.Gameplay private void load() { Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo); - Beatmap.Value.LoadTrack(); Add(gameplayClockContainer = new MasterGameplayClockContainer(Beatmap.Value, skip_target_time)); From fd091559909c8d7720d5d91a1455dce23aa054d5 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 29 Jul 2022 12:24:53 +0900 Subject: [PATCH 163/278] Revert blocking call when sending spectator frames There are a lot of these requests, and we don't really care about waiting on them to finish sending. This may have negatively affected send performance for users with very high latency. Reverts part of 0533249d11ac220e223369f774fafcabc3f30c51. Addresses concerns in https://github.com/ppy/osu/discussions/19429#discussioncomment-3276400. --- osu.Game/Online/Spectator/OnlineSpectatorClient.cs | 2 +- osu.Game/Online/Spectator/SpectatorClient.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Online/Spectator/OnlineSpectatorClient.cs b/osu.Game/Online/Spectator/OnlineSpectatorClient.cs index 030ca724c4..a012bf49b6 100644 --- a/osu.Game/Online/Spectator/OnlineSpectatorClient.cs +++ b/osu.Game/Online/Spectator/OnlineSpectatorClient.cs @@ -80,7 +80,7 @@ namespace osu.Game.Online.Spectator Debug.Assert(connection != null); - return connection.InvokeAsync(nameof(ISpectatorServer.SendFrameData), bundle); + return connection.SendAsync(nameof(ISpectatorServer.SendFrameData), bundle); } protected override Task EndPlayingInternal(SpectatorState state) diff --git a/osu.Game/Online/Spectator/SpectatorClient.cs b/osu.Game/Online/Spectator/SpectatorClient.cs index b5e1c8a45f..745c968992 100644 --- a/osu.Game/Online/Spectator/SpectatorClient.cs +++ b/osu.Game/Online/Spectator/SpectatorClient.cs @@ -304,7 +304,7 @@ namespace osu.Game.Online.Spectator SendFramesInternal(bundle).ContinueWith(t => { - // Handle exception outside of `Schedule` to ensure it doesn't go unovserved. + // Handle exception outside of `Schedule` to ensure it doesn't go unobserved. bool wasSuccessful = t.Exception == null; return Schedule(() => From aaa6f963bd782c0630a5f6a5d1201b3ba0833665 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Fri, 29 Jul 2022 15:27:39 +0900 Subject: [PATCH 164/278] Fix potential test failures due to Setup/SetUpSteps ordering --- .../TestSceneDrawableRoomParticipantsList.cs | 44 +++++---- .../TestSceneLoungeRoomsContainer.cs | 32 ++++--- .../TestSceneMatchBeatmapDetailArea.cs | 25 ++--- .../Multiplayer/TestSceneMatchLeaderboard.cs | 95 ++++++++++--------- .../TestSceneMultiSpectatorLeaderboard.cs | 4 +- .../TestSceneMultiSpectatorScreen.cs | 8 +- .../TestSceneMultiplayerMatchFooter.cs | 31 +++--- .../TestSceneMultiplayerMatchSubScreen.cs | 13 ++- .../TestSceneMultiplayerPlaylist.cs | 27 +++--- .../TestSceneMultiplayerSpectateButton.cs | 60 ++++++------ .../TestSceneStarRatingRangeDisplay.cs | 20 ++-- .../TestScenePlaylistsMatchSettingsOverlay.cs | 20 ++-- .../TestScenePlaylistsParticipantsList.cs | 26 ++--- .../Multiplayer/MultiplayerTestScene.cs | 15 ++- .../Visual/OnlinePlay/OnlinePlayTestScene.cs | 59 ++++++------ 15 files changed, 258 insertions(+), 221 deletions(-) diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoomParticipantsList.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoomParticipantsList.cs index 0a59e0e858..b26481387d 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoomParticipantsList.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoomParticipantsList.cs @@ -19,29 +19,33 @@ namespace osu.Game.Tests.Visual.Multiplayer { private DrawableRoomParticipantsList list; - [SetUp] - public new void Setup() => Schedule(() => + public override void SetUpSteps() { - SelectedRoom.Value = new Room - { - Name = { Value = "test room" }, - Host = - { - Value = new APIUser - { - Id = 2, - Username = "peppy", - } - } - }; + base.SetUpSteps(); - Child = list = new DrawableRoomParticipantsList + AddStep("create list", () => { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - NumberOfCircles = 4 - }; - }); + SelectedRoom.Value = new Room + { + Name = { Value = "test room" }, + Host = + { + Value = new APIUser + { + Id = 2, + Username = "peppy", + } + } + }; + + Child = list = new DrawableRoomParticipantsList + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + NumberOfCircles = 4 + }; + }); + } [Test] public void TestCircleCountNearLimit() diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneLoungeRoomsContainer.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneLoungeRoomsContainer.cs index 82e7bf8969..3d6d4f0a90 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneLoungeRoomsContainer.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneLoungeRoomsContainer.cs @@ -25,23 +25,27 @@ namespace osu.Game.Tests.Visual.Multiplayer private RoomsContainer container; - [SetUp] - public new void Setup() => Schedule(() => + public override void SetUpSteps() { - Child = new PopoverContainer - { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Width = 0.5f, + base.SetUpSteps(); - Child = container = new RoomsContainer + AddStep("create container", () => + { + Child = new PopoverContainer { - SelectedRoom = { BindTarget = SelectedRoom } - } - }; - }); + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Width = 0.5f, + + Child = container = new RoomsContainer + { + SelectedRoom = { BindTarget = SelectedRoom } + } + }; + }); + } [Test] public void TestBasicListChanges() diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMatchBeatmapDetailArea.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMatchBeatmapDetailArea.cs index 8cdcdfdfdf..b113352117 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMatchBeatmapDetailArea.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMatchBeatmapDetailArea.cs @@ -3,7 +3,6 @@ #nullable disable -using NUnit.Framework; using osu.Framework.Graphics; using osu.Game.Online.API; using osu.Game.Online.Rooms; @@ -18,19 +17,23 @@ namespace osu.Game.Tests.Visual.Multiplayer { public class TestSceneMatchBeatmapDetailArea : OnlinePlayTestScene { - [SetUp] - public new void Setup() => Schedule(() => + public override void SetUpSteps() { - SelectedRoom.Value = new Room(); + base.SetUpSteps(); - Child = new MatchBeatmapDetailArea + AddStep("create area", () => { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Size = new Vector2(500), - CreateNewItem = createNewItem - }; - }); + SelectedRoom.Value = new Room(); + + Child = new MatchBeatmapDetailArea + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(500), + CreateNewItem = createNewItem + }; + }); + } private void createNewItem() { diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMatchLeaderboard.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMatchLeaderboard.cs index 506d7541a7..d2468ae005 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMatchLeaderboard.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMatchLeaderboard.cs @@ -4,8 +4,6 @@ #nullable disable using System.Collections.Generic; -using NUnit.Framework; -using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Game.Online.API; using osu.Game.Online.API.Requests.Responses; @@ -19,59 +17,62 @@ namespace osu.Game.Tests.Visual.Multiplayer { public class TestSceneMatchLeaderboard : OnlinePlayTestScene { - [BackgroundDependencyLoader] - private void load() + public override void SetUpSteps() { - ((DummyAPIAccess)API).HandleRequest = r => + base.SetUpSteps(); + + AddStep("setup API", () => { - switch (r) + ((DummyAPIAccess)API).HandleRequest = r => { - case GetRoomLeaderboardRequest leaderboardRequest: - leaderboardRequest.TriggerSuccess(new APILeaderboard - { - Leaderboard = new List + switch (r) + { + case GetRoomLeaderboardRequest leaderboardRequest: + leaderboardRequest.TriggerSuccess(new APILeaderboard { - new APIUserScoreAggregate + Leaderboard = new List { - UserID = 2, - User = new APIUser { Id = 2, Username = "peppy" }, - TotalScore = 995533, - RoomID = 3, - CompletedBeatmaps = 1, - TotalAttempts = 6, - Accuracy = 0.9851 - }, - new APIUserScoreAggregate - { - UserID = 1040328, - User = new APIUser { Id = 1040328, Username = "smoogipoo" }, - TotalScore = 981100, - RoomID = 3, - CompletedBeatmaps = 1, - TotalAttempts = 9, - Accuracy = 0.937 + new APIUserScoreAggregate + { + UserID = 2, + User = new APIUser { Id = 2, Username = "peppy" }, + TotalScore = 995533, + RoomID = 3, + CompletedBeatmaps = 1, + TotalAttempts = 6, + Accuracy = 0.9851 + }, + new APIUserScoreAggregate + { + UserID = 1040328, + User = new APIUser { Id = 1040328, Username = "smoogipoo" }, + TotalScore = 981100, + RoomID = 3, + CompletedBeatmaps = 1, + TotalAttempts = 9, + Accuracy = 0.937 + } } - } - }); - return true; - } + }); + return true; + } - return false; - }; - } + return false; + }; + }); - [SetUp] - public new void Setup() => Schedule(() => - { - SelectedRoom.Value = new Room { RoomID = { Value = 3 } }; - - Child = new MatchLeaderboard + AddStep("create leaderboard", () => { - Origin = Anchor.Centre, - Anchor = Anchor.Centre, - Size = new Vector2(550f, 450f), - Scope = MatchLeaderboardScope.Overall, - }; - }); + SelectedRoom.Value = new Room { RoomID = { Value = 3 } }; + + Child = new MatchLeaderboard + { + Origin = Anchor.Centre, + Anchor = Anchor.Centre, + Size = new Vector2(550f, 450f), + Scope = MatchLeaderboardScope.Overall, + }; + }); + } } } diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiSpectatorLeaderboard.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiSpectatorLeaderboard.cs index 80c356ec67..9e6941738a 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiSpectatorLeaderboard.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiSpectatorLeaderboard.cs @@ -22,8 +22,10 @@ namespace osu.Game.Tests.Visual.Multiplayer private MultiSpectatorLeaderboard leaderboard; [SetUpSteps] - public new void SetUpSteps() + public override void SetUpSteps() { + base.SetUpSteps(); + AddStep("reset", () => { leaderboard?.RemoveAndDisposeImmediately(); diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiSpectatorScreen.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiSpectatorScreen.cs index 7df68392cf..d626426e6d 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiSpectatorScreen.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiSpectatorScreen.cs @@ -56,8 +56,12 @@ namespace osu.Game.Tests.Visual.Multiplayer importedBeatmapId = importedBeatmap.OnlineID; } - [SetUp] - public new void Setup() => Schedule(() => playingUsers.Clear()); + public override void SetUpSteps() + { + base.SetUpSteps(); + + AddStep("clear playing users", () => playingUsers.Clear()); + } [Test] public void TestDelayedStart() diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchFooter.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchFooter.cs index a98030e1e3..83e7ef6a81 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchFooter.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchFooter.cs @@ -3,7 +3,6 @@ #nullable disable -using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Cursor; @@ -13,23 +12,27 @@ namespace osu.Game.Tests.Visual.Multiplayer { public class TestSceneMultiplayerMatchFooter : MultiplayerTestScene { - [SetUp] - public new void Setup() => Schedule(() => + public override void SetUpSteps() { - Child = new PopoverContainer + base.SetUpSteps(); + + AddStep("create footer", () => { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - RelativeSizeAxes = Axes.Both, - Child = new Container + Child = new PopoverContainer { Anchor = Anchor.Centre, Origin = Anchor.Centre, - RelativeSizeAxes = Axes.X, - Height = 50, - Child = new MultiplayerMatchFooter() - } - }; - }); + RelativeSizeAxes = Axes.Both, + Child = new Container + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.X, + Height = 50, + Child = new MultiplayerMatchFooter() + } + }; + }); + } } } diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchSubScreen.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchSubScreen.cs index 5ebafbaabb..8d31e9c723 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchSubScreen.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchSubScreen.cs @@ -59,16 +59,15 @@ namespace osu.Game.Tests.Visual.Multiplayer importedSet = beatmaps.GetAllUsableBeatmapSets().First(); } - [SetUp] - public new void Setup() => Schedule(() => - { - SelectedRoom.Value = new Room { Name = { Value = "Test Room" } }; - }); - [SetUpSteps] public void SetupSteps() { - AddStep("load match", () => LoadScreen(screen = new MultiplayerMatchSubScreen(SelectedRoom.Value))); + AddStep("load match", () => + { + SelectedRoom.Value = new Room { Name = { Value = "Test Room" } }; + LoadScreen(screen = new MultiplayerMatchSubScreen(SelectedRoom.Value)); + }); + AddUntilStep("wait for load", () => screen.IsCurrentScreen()); } diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerPlaylist.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerPlaylist.cs index 75e6088b0d..8dbad4e330 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerPlaylist.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerPlaylist.cs @@ -42,21 +42,22 @@ namespace osu.Game.Tests.Visual.Multiplayer Dependencies.Cache(Realm); } - [SetUp] - public new void Setup() => Schedule(() => - { - Child = list = new MultiplayerPlaylist - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - RelativeSizeAxes = Axes.Both, - Size = new Vector2(0.4f, 0.8f) - }; - }); - [SetUpSteps] - public new void SetUpSteps() + public override void SetUpSteps() { + base.SetUpSteps(); + + AddStep("create list", () => + { + Child = list = new MultiplayerPlaylist + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.Both, + Size = new Vector2(0.4f, 0.8f) + }; + }); + AddStep("import beatmap", () => { beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely(); diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerSpectateButton.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerSpectateButton.cs index e70c414bef..9b4cb722f3 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerSpectateButton.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerSpectateButton.cs @@ -46,43 +46,47 @@ namespace osu.Game.Tests.Visual.Multiplayer beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely(); } - [SetUp] - public new void Setup() => Schedule(() => + public override void SetUpSteps() { - AvailabilityTracker.SelectedItem.BindTo(selectedItem); + base.SetUpSteps(); - importedSet = beatmaps.GetAllUsableBeatmapSets().First(); - Beatmap.Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First()); - selectedItem.Value = new PlaylistItem(Beatmap.Value.BeatmapInfo) + AddStep("create button", () => { - RulesetID = Beatmap.Value.BeatmapInfo.Ruleset.OnlineID, - }; + AvailabilityTracker.SelectedItem.BindTo(selectedItem); - Child = new PopoverContainer - { - RelativeSizeAxes = Axes.Both, - Child = new FillFlowContainer + importedSet = beatmaps.GetAllUsableBeatmapSets().First(); + Beatmap.Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First()); + selectedItem.Value = new PlaylistItem(Beatmap.Value.BeatmapInfo) { - AutoSizeAxes = Axes.Both, - Direction = FillDirection.Vertical, - Children = new Drawable[] + RulesetID = Beatmap.Value.BeatmapInfo.Ruleset.OnlineID, + }; + + Child = new PopoverContainer + { + RelativeSizeAxes = Axes.Both, + Child = new FillFlowContainer { - spectateButton = new MultiplayerSpectateButton + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Vertical, + Children = new Drawable[] { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Size = new Vector2(200, 50), - }, - startControl = new MatchStartControl - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Size = new Vector2(200, 50), + spectateButton = new MultiplayerSpectateButton + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(200, 50), + }, + startControl = new MatchStartControl + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(200, 50), + } } } - } - }; - }); + }; + }); + } [TestCase(MultiplayerRoomState.Open)] [TestCase(MultiplayerRoomState.WaitingForLoad)] diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneStarRatingRangeDisplay.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneStarRatingRangeDisplay.cs index 321e0c2c89..5bccabcf2f 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneStarRatingRangeDisplay.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneStarRatingRangeDisplay.cs @@ -14,17 +14,21 @@ namespace osu.Game.Tests.Visual.Multiplayer { public class TestSceneStarRatingRangeDisplay : OnlinePlayTestScene { - [SetUp] - public new void Setup() => Schedule(() => + public override void SetUpSteps() { - SelectedRoom.Value = new Room(); + base.SetUpSteps(); - Child = new StarRatingRangeDisplay + AddStep("create display", () => { - Anchor = Anchor.Centre, - Origin = Anchor.Centre - }; - }); + SelectedRoom.Value = new Room(); + + Child = new StarRatingRangeDisplay + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre + }; + }); + } [Test] public void TestRange([Values(0, 2, 3, 4, 6, 7)] double min, [Values(0, 2, 3, 4, 6, 7)] double max) diff --git a/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsMatchSettingsOverlay.cs b/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsMatchSettingsOverlay.cs index e6882081dd..c71bdb3a06 100644 --- a/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsMatchSettingsOverlay.cs +++ b/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsMatchSettingsOverlay.cs @@ -25,17 +25,21 @@ namespace osu.Game.Tests.Visual.Playlists protected override OnlinePlayTestSceneDependencies CreateOnlinePlayDependencies() => new TestDependencies(); - [SetUp] - public new void Setup() => Schedule(() => + public override void SetUpSteps() { - SelectedRoom.Value = new Room(); + base.SetUpSteps(); - Child = settings = new TestRoomSettings(SelectedRoom.Value) + AddStep("create overlay", () => { - RelativeSizeAxes = Axes.Both, - State = { Value = Visibility.Visible } - }; - }); + SelectedRoom.Value = new Room(); + + Child = settings = new TestRoomSettings(SelectedRoom.Value) + { + RelativeSizeAxes = Axes.Both, + State = { Value = Visibility.Visible } + }; + }); + } [Test] public void TestButtonEnabledOnlyWithNameAndBeatmap() diff --git a/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsParticipantsList.cs b/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsParticipantsList.cs index 5961ed74ad..9a0dda056a 100644 --- a/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsParticipantsList.cs +++ b/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsParticipantsList.cs @@ -15,21 +15,25 @@ namespace osu.Game.Tests.Visual.Playlists { public class TestScenePlaylistsParticipantsList : OnlinePlayTestScene { - [SetUp] - public new void Setup() => Schedule(() => + public override void SetUpSteps() { - SelectedRoom.Value = new Room { RoomID = { Value = 7 } }; + base.SetUpSteps(); - for (int i = 0; i < 50; i++) + AddStep("create list", () => { - SelectedRoom.Value.RecentParticipants.Add(new APIUser + SelectedRoom.Value = new Room { RoomID = { Value = 7 } }; + + for (int i = 0; i < 50; i++) { - Username = "peppy", - Statistics = new UserStatistics { GlobalRank = 1234 }, - Id = 2 - }); - } - }); + SelectedRoom.Value.RecentParticipants.Add(new APIUser + { + Username = "peppy", + Statistics = new UserStatistics { GlobalRank = 1234 }, + Id = 2 + }); + } + }); + } [Test] public void TestHorizontalLayout() diff --git a/osu.Game/Tests/Visual/Multiplayer/MultiplayerTestScene.cs b/osu.Game/Tests/Visual/Multiplayer/MultiplayerTestScene.cs index 5ea98bdbb1..101a347749 100644 --- a/osu.Game/Tests/Visual/Multiplayer/MultiplayerTestScene.cs +++ b/osu.Game/Tests/Visual/Multiplayer/MultiplayerTestScene.cs @@ -3,7 +3,6 @@ #nullable disable -using NUnit.Framework; using osu.Game.Online.Rooms; using osu.Game.Tests.Beatmaps; using osu.Game.Tests.Visual.OnlinePlay; @@ -34,13 +33,6 @@ namespace osu.Game.Tests.Visual.Multiplayer this.joinRoom = joinRoom; } - [SetUp] - public new void Setup() => Schedule(() => - { - if (joinRoom) - SelectedRoom.Value = CreateRoom(); - }); - protected virtual Room CreateRoom() { return new Room @@ -63,7 +55,12 @@ namespace osu.Game.Tests.Visual.Multiplayer if (joinRoom) { - AddStep("join room", () => RoomManager.CreateRoom(SelectedRoom.Value)); + AddStep("join room", () => + { + SelectedRoom.Value = CreateRoom(); + RoomManager.CreateRoom(SelectedRoom.Value); + }); + AddUntilStep("wait for room join", () => RoomJoined); } } diff --git a/osu.Game/Tests/Visual/OnlinePlay/OnlinePlayTestScene.cs b/osu.Game/Tests/Visual/OnlinePlay/OnlinePlayTestScene.cs index 6577057c17..b9c293c3aa 100644 --- a/osu.Game/Tests/Visual/OnlinePlay/OnlinePlayTestScene.cs +++ b/osu.Game/Tests/Visual/OnlinePlay/OnlinePlayTestScene.cs @@ -4,7 +4,6 @@ #nullable disable using System; -using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -56,39 +55,43 @@ namespace osu.Game.Tests.Visual.OnlinePlay return dependencies; } - [SetUp] - public void Setup() => Schedule(() => + public override void SetUpSteps() { - // Reset the room dependencies to a fresh state. - drawableDependenciesContainer.Clear(); - dependencies.OnlinePlayDependencies = CreateOnlinePlayDependencies(); - drawableDependenciesContainer.AddRange(OnlinePlayDependencies.DrawableComponents); + base.SetUpSteps(); - var handler = OnlinePlayDependencies.RequestsHandler; - - // Resolving the BeatmapManager in the test scene will inject the game-wide BeatmapManager, while many test scenes cache their own BeatmapManager instead. - // To get around this, the BeatmapManager is looked up from the dependencies provided to the children of the test scene instead. - var beatmapManager = dependencies.Get(); - - ((DummyAPIAccess)API).HandleRequest = request => + AddStep("setup dependencies", () => { - try + // Reset the room dependencies to a fresh state. + drawableDependenciesContainer.Clear(); + dependencies.OnlinePlayDependencies = CreateOnlinePlayDependencies(); + drawableDependenciesContainer.AddRange(OnlinePlayDependencies.DrawableComponents); + + var handler = OnlinePlayDependencies.RequestsHandler; + + // Resolving the BeatmapManager in the test scene will inject the game-wide BeatmapManager, while many test scenes cache their own BeatmapManager instead. + // To get around this, the BeatmapManager is looked up from the dependencies provided to the children of the test scene instead. + var beatmapManager = dependencies.Get(); + + ((DummyAPIAccess)API).HandleRequest = request => { - return handler.HandleRequest(request, API.LocalUser.Value, beatmapManager); - } - catch (ObjectDisposedException) - { - // These requests can be fired asynchronously, but potentially arrive after game components - // have been disposed (ie. realm in BeatmapManager). - // This only happens in tests and it's easiest to ignore them for now. - Logger.Log($"Handled {nameof(ObjectDisposedException)} in test request handling"); - return true; - } - }; - }); + try + { + return handler.HandleRequest(request, API.LocalUser.Value, beatmapManager); + } + catch (ObjectDisposedException) + { + // These requests can be fired asynchronously, but potentially arrive after game components + // have been disposed (ie. realm in BeatmapManager). + // This only happens in tests and it's easiest to ignore them for now. + Logger.Log($"Handled {nameof(ObjectDisposedException)} in test request handling"); + return true; + } + }; + }); + } /// - /// Creates the room dependencies. Called every . + /// Creates the room dependencies. Called every . /// /// /// Any custom dependencies required for online play sub-classes should be added here. From e07e761c1011cf7202d3baa9360c1f6dc31e46ef Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 29 Jul 2022 15:54:03 +0900 Subject: [PATCH 165/278] Ensure realm is in a good state before asserts in `TestSceneFilterControl` --- .../SongSelect/TestSceneFilterControl.cs | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs index 56f252f47d..82314f9764 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . 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; @@ -19,6 +20,7 @@ using osu.Game.Rulesets; using osu.Game.Screens.Select; using osu.Game.Tests.Resources; using osuTK.Input; +using Realms; namespace osu.Game.Tests.Visual.SongSelect { @@ -47,7 +49,7 @@ namespace osu.Game.Tests.Visual.SongSelect [SetUp] public void SetUp() => Schedule(() => { - Realm.Write(r => r.RemoveAll()); + writeAndRefresh(r => r.RemoveAll()); Child = control = new FilterControl { @@ -68,8 +70,8 @@ namespace osu.Game.Tests.Visual.SongSelect [Test] public void TestCollectionAddedToDropdown() { - AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "1")))); - AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "2")))); + AddStep("add collection", () => writeAndRefresh(r => r.Add(new BeatmapCollection(name: "1")))); + AddStep("add collection", () => writeAndRefresh(r => r.Add(new BeatmapCollection(name: "2")))); assertCollectionDropdownContains("1"); assertCollectionDropdownContains("2"); } @@ -79,9 +81,9 @@ namespace osu.Game.Tests.Visual.SongSelect { BeatmapCollection first = null!; - AddStep("add collection", () => Realm.Write(r => r.Add(first = new BeatmapCollection(name: "1")))); - AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "2")))); - AddStep("remove collection", () => Realm.Write(r => r.Remove(first))); + AddStep("add collection", () => writeAndRefresh(r => r.Add(first = new BeatmapCollection(name: "1")))); + AddStep("add collection", () => writeAndRefresh(r => r.Add(new BeatmapCollection(name: "2")))); + AddStep("remove collection", () => writeAndRefresh(r => r.Remove(first))); assertCollectionDropdownContains("1", false); assertCollectionDropdownContains("2"); @@ -90,7 +92,7 @@ namespace osu.Game.Tests.Visual.SongSelect [Test] public void TestCollectionRenamed() { - AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "1")))); + AddStep("add collection", () => writeAndRefresh(r => r.Add(new BeatmapCollection(name: "1")))); AddStep("select collection", () => { var dropdown = control.ChildrenOfType().Single(); @@ -99,7 +101,7 @@ namespace osu.Game.Tests.Visual.SongSelect addExpandHeaderStep(); - AddStep("change name", () => Realm.Write(_ => getFirstCollection().Name = "First")); + AddStep("change name", () => writeAndRefresh(_ => getFirstCollection().Name = "First")); assertCollectionDropdownContains("First"); assertCollectionHeaderDisplays("First"); @@ -117,7 +119,7 @@ namespace osu.Game.Tests.Visual.SongSelect public void TestCollectionFilterHasAddButton() { addExpandHeaderStep(); - AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "1")))); + AddStep("add collection", () => writeAndRefresh(r => r.Add(new BeatmapCollection(name: "1")))); AddStep("hover collection", () => InputManager.MoveMouseTo(getAddOrRemoveButton(1))); AddAssert("collection has add button", () => getAddOrRemoveButton(1).IsPresent); } @@ -127,7 +129,7 @@ namespace osu.Game.Tests.Visual.SongSelect { addExpandHeaderStep(); - AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "1")))); + AddStep("add collection", () => writeAndRefresh(r => r.Add(new BeatmapCollection(name: "1")))); AddStep("select available beatmap", () => Beatmap.Value = beatmapManager.GetWorkingBeatmap(beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0])); AddAssert("button enabled", () => getAddOrRemoveButton(1).Enabled.Value); @@ -143,13 +145,13 @@ namespace osu.Game.Tests.Visual.SongSelect AddStep("select available beatmap", () => Beatmap.Value = beatmapManager.GetWorkingBeatmap(beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0])); - AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "1")))); + AddStep("add collection", () => writeAndRefresh(r => r.Add(new BeatmapCollection(name: "1")))); AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusSquare)); - AddStep("add beatmap to collection", () => Realm.Write(r => getFirstCollection().BeatmapMD5Hashes.Add(Beatmap.Value.BeatmapInfo.MD5Hash))); + AddStep("add beatmap to collection", () => writeAndRefresh(r => getFirstCollection().BeatmapMD5Hashes.Add(Beatmap.Value.BeatmapInfo.MD5Hash))); AddAssert("button is minus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.MinusSquare)); - AddStep("remove beatmap from collection", () => Realm.Write(r => getFirstCollection().BeatmapMD5Hashes.Clear())); + AddStep("remove beatmap from collection", () => writeAndRefresh(r => getFirstCollection().BeatmapMD5Hashes.Clear())); AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusSquare)); } @@ -160,7 +162,7 @@ namespace osu.Game.Tests.Visual.SongSelect AddStep("select available beatmap", () => Beatmap.Value = beatmapManager.GetWorkingBeatmap(beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0])); - AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "1")))); + AddStep("add collection", () => writeAndRefresh(r => r.Add(new BeatmapCollection(name: "1")))); AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusSquare)); addClickAddOrRemoveButtonStep(1); @@ -179,7 +181,7 @@ namespace osu.Game.Tests.Visual.SongSelect addExpandHeaderStep(); - AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "1", new List { "abc" })))); + AddStep("add collection", () => writeAndRefresh(r => r.Add(new BeatmapCollection(name: "1", new List { "abc" })))); AddStep("select collection", () => { InputManager.MoveMouseTo(getCollectionDropdownItems().ElementAt(1)); @@ -205,14 +207,20 @@ namespace osu.Game.Tests.Visual.SongSelect AddAssert("filter request not fired", () => !received); } + private void writeAndRefresh(Action action) => Realm.Write(r => + { + action(r); + r.Refresh(); + }); + private BeatmapCollection getFirstCollection() => Realm.Run(r => r.All().First()); private void assertCollectionHeaderDisplays(string collectionName, bool shouldDisplay = true) - => AddAssert($"collection dropdown header displays '{collectionName}'", + => AddUntilStep($"collection dropdown header displays '{collectionName}'", () => shouldDisplay == (control.ChildrenOfType().Single().ChildrenOfType().First().Text == collectionName)); private void assertCollectionDropdownContains(string collectionName, bool shouldContain = true) => - AddAssert($"collection dropdown {(shouldContain ? "contains" : "does not contain")} '{collectionName}'", + AddUntilStep($"collection dropdown {(shouldContain ? "contains" : "does not contain")} '{collectionName}'", // A bit of a roundabout way of going about this, see: https://github.com/ppy/osu-framework/issues/3871 + https://github.com/ppy/osu-framework/issues/3872 () => shouldContain == (getCollectionDropdownItems().Any(i => i.ChildrenOfType().OfType().First().Text == collectionName))); From 2ff6ff06d3ed25fce9bd69939b8fcae5c8f9ddb0 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 29 Jul 2022 16:05:41 +0900 Subject: [PATCH 166/278] Use tuple to better explain new `bool` parameter --- osu.Game/Beatmaps/BeatmapImporter.cs | 5 ++--- osu.Game/Beatmaps/BeatmapManager.cs | 6 +++--- osu.Game/OsuGameBase.cs | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapImporter.cs b/osu.Game/Beatmaps/BeatmapImporter.cs index df8b18313c..6e954e0356 100644 --- a/osu.Game/Beatmaps/BeatmapImporter.cs +++ b/osu.Game/Beatmaps/BeatmapImporter.cs @@ -34,7 +34,7 @@ namespace osu.Game.Beatmaps protected override string[] HashableFileTypes => new[] { ".osu" }; - public Action? ProcessBeatmap { private get; set; } + public Action<(BeatmapSetInfo beatmapSet, bool isBatch)>? ProcessBeatmap { private get; set; } public BeatmapImporter(Storage storage, RealmAccess realm) : base(storage, realm) @@ -171,8 +171,7 @@ namespace osu.Game.Beatmaps protected override void PostImport(BeatmapSetInfo model, Realm realm, bool batchImport) { base.PostImport(model, realm, batchImport); - - ProcessBeatmap?.Invoke(model, batchImport); + ProcessBeatmap?.Invoke((model, batchImport)); } private void validateOnlineIds(BeatmapSetInfo beatmapSet, Realm realm) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index abf3d43d94..387daf6906 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -42,7 +42,7 @@ namespace osu.Game.Beatmaps private readonly WorkingBeatmapCache workingBeatmapCache; - public Action? ProcessBeatmap { private get; set; } + public Action<(BeatmapSetInfo beatmapSet, bool isBatch)>? ProcessBeatmap { private get; set; } public BeatmapManager(Storage storage, RealmAccess realm, RulesetStore rulesets, IAPIProvider? api, AudioManager audioManager, IResourceStore gameResources, GameHost? host = null, WorkingBeatmap? defaultBeatmap = null, BeatmapDifficultyCache? difficultyCache = null, bool performOnlineLookups = false) @@ -62,7 +62,7 @@ namespace osu.Game.Beatmaps BeatmapTrackStore = audioManager.GetTrackStore(userResources); beatmapImporter = CreateBeatmapImporter(storage, realm); - beatmapImporter.ProcessBeatmap = (obj, isBatch) => ProcessBeatmap?.Invoke(obj, isBatch); + beatmapImporter.ProcessBeatmap = args => ProcessBeatmap?.Invoke(args); beatmapImporter.PostNotification = obj => PostNotification?.Invoke(obj); workingBeatmapCache = CreateWorkingBeatmapCache(audioManager, gameResources, userResources, defaultBeatmap, host); @@ -323,7 +323,7 @@ namespace osu.Game.Beatmaps setInfo.CopyChangesToRealm(liveBeatmapSet); - ProcessBeatmap?.Invoke(liveBeatmapSet, false); + ProcessBeatmap?.Invoke((liveBeatmapSet, false)); }); } diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 41eeece76d..dc7e2b47cf 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -287,7 +287,7 @@ namespace osu.Game AddInternal(new BeatmapOnlineChangeIngest(beatmapUpdater, realm, metadataClient)); - BeatmapManager.ProcessBeatmap = (set, isBatch) => beatmapUpdater.Process(set, preferOnlineFetch: !isBatch); + BeatmapManager.ProcessBeatmap = args => beatmapUpdater.Process(args.beatmapSet, !args.isBatch); dependencies.Cache(userCache = new UserLookupCache()); AddInternal(userCache); From 9d457535c630d2d1cc8bee08f005e77f42052d0c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 29 Jul 2022 16:22:54 +0900 Subject: [PATCH 167/278] Add confirmation dialog when about to discard a playlist The confirmation will only show if items have been added to the playlist. Closes https://github.com/ppy/osu/issues/19444. --- .../Menu/ConfirmDiscardChangesDialog.cs | 39 +++++++++++++++++++ osu.Game/Screens/Menu/ConfirmExitDialog.cs | 4 +- .../Screens/OnlinePlay/Match/RoomSubScreen.cs | 24 ++++++++++-- 3 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 osu.Game/Screens/Menu/ConfirmDiscardChangesDialog.cs diff --git a/osu.Game/Screens/Menu/ConfirmDiscardChangesDialog.cs b/osu.Game/Screens/Menu/ConfirmDiscardChangesDialog.cs new file mode 100644 index 0000000000..450c559450 --- /dev/null +++ b/osu.Game/Screens/Menu/ConfirmDiscardChangesDialog.cs @@ -0,0 +1,39 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using osu.Framework.Graphics.Sprites; +using osu.Game.Overlays.Dialog; + +namespace osu.Game.Screens.Menu +{ + public class ConfirmDiscardChangesDialog : PopupDialog + { + /// + /// Construct a new discard changes confirmation dialog. + /// + /// An action to perform on confirmation. + /// An optional action to perform on cancel. + public ConfirmDiscardChangesDialog(Action onConfirm, Action? onCancel = null) + { + HeaderText = "Are you sure you want to go back?"; + BodyText = "This will discard any unsaved changes"; + + Icon = FontAwesome.Solid.ExclamationTriangle; + + Buttons = new PopupDialogButton[] + { + new PopupDialogDangerousButton + { + Text = @"Yes", + Action = onConfirm + }, + new PopupDialogCancelButton + { + Text = @"No I didn't mean to", + Action = onCancel + }, + }; + } + } +} diff --git a/osu.Game/Screens/Menu/ConfirmExitDialog.cs b/osu.Game/Screens/Menu/ConfirmExitDialog.cs index 734ff6b23f..20fa889986 100644 --- a/osu.Game/Screens/Menu/ConfirmExitDialog.cs +++ b/osu.Game/Screens/Menu/ConfirmExitDialog.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using osu.Framework.Graphics.Sprites; using osu.Game.Overlays.Dialog; @@ -16,7 +14,7 @@ namespace osu.Game.Screens.Menu /// /// An action to perform on confirmation. /// An optional action to perform on cancel. - public ConfirmExitDialog(Action onConfirm, Action onCancel = null) + public ConfirmExitDialog(Action onConfirm, Action? onCancel = null) { HeaderText = "Are you sure you want to exit osu!?"; BodyText = "Last chance to turn back"; diff --git a/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs b/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs index f5af110372..5b3ed0059d 100644 --- a/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs @@ -28,6 +28,7 @@ using osu.Game.Overlays; using osu.Game.Overlays.Mods; using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; +using osu.Game.Screens.Menu; using osu.Game.Screens.OnlinePlay.Match.Components; using osu.Game.Screens.OnlinePlay.Multiplayer; @@ -280,13 +281,30 @@ namespace osu.Game.Screens.OnlinePlay.Match }; } + [Resolved(canBeNull: true)] + private IDialogOverlay dialogOverlay { get; set; } + public override bool OnBackButton() { if (Room.RoomID.Value == null) { - // room has not been created yet; exit immediately. - settingsOverlay.Hide(); - return base.OnBackButton(); + if (dialogOverlay == null || Room.Playlist.Count == 0) + { + settingsOverlay.Hide(); + return base.OnBackButton(); + } + + // if the dialog is already displayed, block exiting until the user explicitly makes a decision. + if (dialogOverlay.CurrentDialog is ConfirmDiscardChangesDialog) + return true; + + dialogOverlay?.Push(new ConfirmDiscardChangesDialog(() => + { + settingsOverlay.Hide(); + this.Exit(); + })); + + return true; } if (UserModsSelectOverlay.State.Value == Visibility.Visible) From 0a2265b0e88c853108b4fb7eeba81c2381a7cd42 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 29 Jul 2022 17:05:51 +0900 Subject: [PATCH 168/278] Add test coverage of playlist exit confirmation --- .../Navigation/TestSceneScreenNavigation.cs | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/osu.Game.Tests/Visual/Navigation/TestSceneScreenNavigation.cs b/osu.Game.Tests/Visual/Navigation/TestSceneScreenNavigation.cs index 58898d8386..8fce43f9b0 100644 --- a/osu.Game.Tests/Visual/Navigation/TestSceneScreenNavigation.cs +++ b/osu.Game.Tests/Visual/Navigation/TestSceneScreenNavigation.cs @@ -26,6 +26,7 @@ using osu.Game.Rulesets.Osu.Mods; using osu.Game.Scoring; using osu.Game.Screens.Menu; using osu.Game.Screens.OnlinePlay.Lounge; +using osu.Game.Screens.OnlinePlay.Playlists; using osu.Game.Screens.Play; using osu.Game.Screens.Ranking; using osu.Game.Screens.Select; @@ -45,6 +46,57 @@ namespace osu.Game.Tests.Visual.Navigation private Vector2 optionsButtonPosition => Game.ToScreenSpace(new Vector2(click_padding, click_padding)); + [TestCase(false)] + [TestCase(true)] + public void TestConfirmationRequiredToDiscardPlaylist(bool withPlaylistItemAdded) + { + Screens.OnlinePlay.Playlists.Playlists playlistScreen = null; + + AddUntilStep("wait for dialog overlay", () => Game.ChildrenOfType().SingleOrDefault() != null); + + PushAndConfirm(() => playlistScreen = new Screens.OnlinePlay.Playlists.Playlists()); + + AddStep("import beatmap", () => BeatmapImportHelper.LoadQuickOszIntoOsu(Game).WaitSafely()); + + AddStep("open create screen", () => + { + InputManager.MoveMouseTo(playlistScreen.ChildrenOfType().Single()); + InputManager.Click(MouseButton.Left); + }); + + if (withPlaylistItemAdded) + { + AddUntilStep("wait for settings displayed", + () => (playlistScreen.CurrentSubScreen as PlaylistsRoomSubScreen)?.ChildrenOfType().SingleOrDefault()?.State.Value == Visibility.Visible); + + AddStep("edit playlist", () => InputManager.Key(Key.Enter)); + + AddUntilStep("wait for song select", () => (playlistScreen.CurrentSubScreen as PlaylistsSongSelect)?.BeatmapSetsLoaded == true); + + AddUntilStep("wait for selection", () => !Game.Beatmap.IsDefault); + + AddStep("add item", () => InputManager.Key(Key.Enter)); + + AddUntilStep("wait for return to playlist screen", () => playlistScreen.CurrentSubScreen is PlaylistsRoomSubScreen); + + pushEscape(); + AddAssert("confirmation dialog shown", () => Game.ChildrenOfType().Single().CurrentDialog is not null); + + AddStep("confirm exit", () => InputManager.Key(Key.Enter)); + + AddAssert("dialog dismissed", () => Game.ChildrenOfType().Single().CurrentDialog == null); + + exitViaEscapeAndConfirm(); + } + else + { + pushEscape(); + AddAssert("confirmation dialog not shown", () => Game.ChildrenOfType().Single().CurrentDialog == null); + + exitViaEscapeAndConfirm(); + } + } + [Test] public void TestExitSongSelectWithEscape() { From 07e3765b3492b1023039804e9e54b71c42e51cda Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 29 Jul 2022 17:25:30 +0900 Subject: [PATCH 169/278] Ensure collection is added to dropdown before trying to click it --- osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs index 82314f9764..d0523b58fa 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs @@ -93,6 +93,7 @@ namespace osu.Game.Tests.Visual.SongSelect public void TestCollectionRenamed() { AddStep("add collection", () => writeAndRefresh(r => r.Add(new BeatmapCollection(name: "1")))); + assertCollectionDropdownContains("1"); AddStep("select collection", () => { var dropdown = control.ChildrenOfType().Single(); @@ -120,6 +121,7 @@ namespace osu.Game.Tests.Visual.SongSelect { addExpandHeaderStep(); AddStep("add collection", () => writeAndRefresh(r => r.Add(new BeatmapCollection(name: "1")))); + assertCollectionDropdownContains("1"); AddStep("hover collection", () => InputManager.MoveMouseTo(getAddOrRemoveButton(1))); AddAssert("collection has add button", () => getAddOrRemoveButton(1).IsPresent); } @@ -130,6 +132,7 @@ namespace osu.Game.Tests.Visual.SongSelect addExpandHeaderStep(); AddStep("add collection", () => writeAndRefresh(r => r.Add(new BeatmapCollection(name: "1")))); + assertCollectionDropdownContains("1"); AddStep("select available beatmap", () => Beatmap.Value = beatmapManager.GetWorkingBeatmap(beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0])); AddAssert("button enabled", () => getAddOrRemoveButton(1).Enabled.Value); @@ -146,6 +149,7 @@ namespace osu.Game.Tests.Visual.SongSelect AddStep("select available beatmap", () => Beatmap.Value = beatmapManager.GetWorkingBeatmap(beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0])); AddStep("add collection", () => writeAndRefresh(r => r.Add(new BeatmapCollection(name: "1")))); + assertCollectionDropdownContains("1"); AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusSquare)); AddStep("add beatmap to collection", () => writeAndRefresh(r => getFirstCollection().BeatmapMD5Hashes.Add(Beatmap.Value.BeatmapInfo.MD5Hash))); @@ -163,6 +167,7 @@ namespace osu.Game.Tests.Visual.SongSelect AddStep("select available beatmap", () => Beatmap.Value = beatmapManager.GetWorkingBeatmap(beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0])); AddStep("add collection", () => writeAndRefresh(r => r.Add(new BeatmapCollection(name: "1")))); + assertCollectionDropdownContains("1"); AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusSquare)); addClickAddOrRemoveButtonStep(1); @@ -182,6 +187,8 @@ namespace osu.Game.Tests.Visual.SongSelect addExpandHeaderStep(); AddStep("add collection", () => writeAndRefresh(r => r.Add(new BeatmapCollection(name: "1", new List { "abc" })))); + assertCollectionDropdownContains("1"); + AddStep("select collection", () => { InputManager.MoveMouseTo(getCollectionDropdownItems().ElementAt(1)); From 8f1e3b01547884ca4687e8c38a1ca0d75ac29a9e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 29 Jul 2022 18:52:50 +0900 Subject: [PATCH 170/278] Fix editor summary timeline not responding to kiai changes correctly --- .../Summary/Parts/EffectPointVisualisation.cs | 80 ++++++++++++------- 1 file changed, 53 insertions(+), 27 deletions(-) diff --git a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/EffectPointVisualisation.cs b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/EffectPointVisualisation.cs index b2007273e8..3dca1b1e8c 100644 --- a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/EffectPointVisualisation.cs +++ b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/EffectPointVisualisation.cs @@ -4,6 +4,7 @@ #nullable disable using System.Linq; +using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Extensions.Color4Extensions; @@ -38,37 +39,62 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts private void load() { kiai = effect.KiaiModeBindable.GetBoundCopy(); - kiai.BindValueChanged(_ => + kiai.BindValueChanged(_ => refreshDisplay(), true); + } + + [CanBeNull] + private EffectControlPoint nextControlPoint; + + protected override void LoadComplete() + { + base.LoadComplete(); + + // Due to the limitations of ControlPointInfo, it's impossible to know via event flow when the next kiai point has changed. + // This is due to the fact that an EffectPoint can be added to an existing group. We would need to bind to ItemAdded on *every* + // future group to track this. + // + // I foresee this being a potential performance issue on beatmaps with many control points, so let's limit how often we check + // for changes. ControlPointInfo needs a refactor to make this flow better, but it should do for now. + Scheduler.AddDelayed(() => { - ClearInternal(); + var next = beatmap.ControlPointInfo.EffectPoints.FirstOrDefault(c => c.Time > effect.Time); - AddInternal(new ControlPointVisualisation(effect)); - - if (!kiai.Value) - return; - - var endControlPoint = beatmap.ControlPointInfo.EffectPoints.FirstOrDefault(c => c.Time > effect.Time && !c.KiaiMode); - - // handle kiai duration - // eventually this will be simpler when we have control points with durations. - if (endControlPoint != null) + if (!ReferenceEquals(nextControlPoint, next)) { - RelativeSizeAxes = Axes.Both; - Origin = Anchor.TopLeft; - - Width = (float)(endControlPoint.Time - effect.Time); - - AddInternal(new PointVisualisation - { - RelativeSizeAxes = Axes.Both, - Origin = Anchor.TopLeft, - Width = 1, - Height = 0.25f, - Depth = float.MaxValue, - Colour = effect.GetRepresentingColour(colours).Darken(0.5f), - }); + nextControlPoint = next; + refreshDisplay(); } - }, true); + }, 100, true); + } + + private void refreshDisplay() + { + ClearInternal(); + + AddInternal(new ControlPointVisualisation(effect)); + + if (!kiai.Value) + return; + + // handle kiai duration + // eventually this will be simpler when we have control points with durations. + if (nextControlPoint != null) + { + RelativeSizeAxes = Axes.Both; + Origin = Anchor.TopLeft; + + Width = (float)(nextControlPoint.Time - effect.Time); + + AddInternal(new PointVisualisation + { + RelativeSizeAxes = Axes.Both, + Origin = Anchor.TopLeft, + Width = 1, + Height = 0.25f, + Depth = float.MaxValue, + Colour = effect.GetRepresentingColour(colours).Darken(0.5f), + }); + } } // kiai sections display duration, so are required to be visualised. From 3f72e76348955667bd9e61a26fe5587a14516f9a Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 29 Jul 2022 16:12:52 +0300 Subject: [PATCH 171/278] Expose `StartTime` from gameplay clock --- osu.Game/Screens/Play/GameplayClock.cs | 9 +++++++++ osu.Game/Screens/Play/GameplayClockContainer.cs | 16 +++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Play/GameplayClock.cs b/osu.Game/Screens/Play/GameplayClock.cs index e6248014c5..6af795cfd8 100644 --- a/osu.Game/Screens/Play/GameplayClock.cs +++ b/osu.Game/Screens/Play/GameplayClock.cs @@ -35,6 +35,15 @@ namespace osu.Game.Screens.Play UnderlyingClock = underlyingClock; } + /// + /// The time from which the clock should start. Will be seeked to on calling . + /// + /// + /// If not set, a value of zero will be used. + /// Importantly, the value will be inferred from the current ruleset in unless specified. + /// + public double? StartTime { get; internal set; } + public double CurrentTime => UnderlyingClock.CurrentTime; public double Rate => UnderlyingClock.Rate; diff --git a/osu.Game/Screens/Play/GameplayClockContainer.cs b/osu.Game/Screens/Play/GameplayClockContainer.cs index 9396b3311f..7b75decb51 100644 --- a/osu.Game/Screens/Play/GameplayClockContainer.cs +++ b/osu.Game/Screens/Play/GameplayClockContainer.cs @@ -44,6 +44,8 @@ namespace osu.Game.Screens.Play /// public event Action OnSeek; + private double? startTime; + /// /// The time from which the clock should start. Will be seeked to on calling . /// @@ -51,7 +53,17 @@ namespace osu.Game.Screens.Play /// If not set, a value of zero will be used. /// Importantly, the value will be inferred from the current ruleset in unless specified. /// - public double? StartTime { get; set; } + public double? StartTime + { + get => startTime; + set + { + startTime = value; + + if (GameplayClock != null) + GameplayClock.StartTime = value; + } + } /// /// Creates a new . @@ -72,6 +84,8 @@ namespace osu.Game.Screens.Play var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); dependencies.CacheAs(GameplayClock = CreateGameplayClock(AdjustableSource)); + + GameplayClock.StartTime = StartTime; GameplayClock.IsPaused.BindTo(IsPaused); return dependencies; From 905bbdc8eebe51dacd9a63535996edd7253df358 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 29 Jul 2022 16:17:25 +0300 Subject: [PATCH 172/278] Remove caching of `GameplayClockContainer` in favour of `GameplayClock` Also fixes `SongProgress` being displayed in skin editor on non-gameplay screens, due to `GameplayClock` not marked as a required dependency. --- osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs | 3 +-- osu.Game/Screens/Play/GameplayClockContainer.cs | 1 - osu.Game/Screens/Play/HUD/DefaultSongProgress.cs | 5 +---- osu.Game/Screens/Play/HUD/SongProgress.cs | 8 ++++---- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs index 428c056fc6..efd3fae147 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs @@ -30,8 +30,7 @@ namespace osu.Game.Tests.Visual.Gameplay Add(gameplayClockContainer = new MasterGameplayClockContainer(Beatmap.Value, skip_target_time)); - Dependencies.CacheAs(gameplayClockContainer); // required for StartTime - Dependencies.CacheAs(gameplayClockContainer.GameplayClock); // required for everything else + Dependencies.CacheAs(gameplayClockContainer.GameplayClock); } [SetUpSteps] diff --git a/osu.Game/Screens/Play/GameplayClockContainer.cs b/osu.Game/Screens/Play/GameplayClockContainer.cs index 7b75decb51..b37d15e06c 100644 --- a/osu.Game/Screens/Play/GameplayClockContainer.cs +++ b/osu.Game/Screens/Play/GameplayClockContainer.cs @@ -16,7 +16,6 @@ namespace osu.Game.Screens.Play /// /// Encapsulates gameplay timing logic and provides a via DI for gameplay components to use. /// - [Cached] public abstract class GameplayClockContainer : Container, IAdjustableClock { /// diff --git a/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs b/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs index 7b9453f2ed..96a6c56860 100644 --- a/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs +++ b/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs @@ -42,9 +42,6 @@ namespace osu.Game.Screens.Play.HUD protected override bool BlockScrollInput => false; - [Resolved] - private GameplayClock? gameplayClock { get; set; } - [Resolved] private Player? player { get; set; } @@ -172,7 +169,7 @@ namespace osu.Game.Screens.Play.HUD protected override void UpdateProgress(double progress, bool isIntro) { - bar.CurrentTime = gameplayClock?.CurrentTime ?? Time.Current; + bar.CurrentTime = GameplayClock.CurrentTime; if (isIntro) graph.Progress = 0; diff --git a/osu.Game/Screens/Play/HUD/SongProgress.cs b/osu.Game/Screens/Play/HUD/SongProgress.cs index aaef141349..702d2f7c6f 100644 --- a/osu.Game/Screens/Play/HUD/SongProgress.cs +++ b/osu.Game/Screens/Play/HUD/SongProgress.cs @@ -17,7 +17,7 @@ namespace osu.Game.Screens.Play.HUD public bool UsesFixedAnchor { get; set; } [Resolved] - private GameplayClockContainer? gameplayClockContainer { get; set; } + protected GameplayClock GameplayClock { get; private set; } = null!; [Resolved(canBeNull: true)] private DrawableRuleset? drawableRuleset { get; set; } @@ -69,14 +69,14 @@ namespace osu.Game.Screens.Play.HUD return; // The reference clock is used to accurately tell the playfield's time. This is obtained from the drawable ruleset. - // However, if no drawable ruleset is available (i.e. used in tests), we fall back to either the gameplay clock container or this drawable's own clock. - double currentTime = referenceClock?.CurrentTime ?? gameplayClockContainer?.GameplayClock.CurrentTime ?? Time.Current; + // However, if no drawable ruleset is available (i.e. used in tests), we fall back to the gameplay clock. + double currentTime = referenceClock?.CurrentTime ?? GameplayClock.CurrentTime; bool isInIntro = currentTime < FirstHitTime; if (isInIntro) { - double introStartTime = gameplayClockContainer?.StartTime ?? 0; + double introStartTime = GameplayClock.StartTime ?? 0; double introOffsetCurrent = currentTime - introStartTime; double introDuration = FirstHitTime - introStartTime; From 3b1a76b1906d0b99f8690ed8cda037a94e870f53 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 29 Jul 2022 15:40:56 +0300 Subject: [PATCH 173/278] Remove redundant/overwritten specifications --- .../Visual/Gameplay/TestSceneSongProgress.cs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs index efd3fae147..9eb71b9cf7 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSongProgress.cs @@ -69,17 +69,8 @@ namespace osu.Game.Tests.Visual.Gameplay this.ChildrenOfType().ForEach(progress => progress.Objects = objects); } - protected override Drawable CreateDefaultImplementation() => new DefaultSongProgress - { - RelativeSizeAxes = Axes.X, - Anchor = Anchor.BottomLeft, - Origin = Anchor.BottomLeft, - }; + protected override Drawable CreateDefaultImplementation() => new DefaultSongProgress(); - protected override Drawable CreateLegacyImplementation() => new LegacySongProgress - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - }; + protected override Drawable CreateLegacyImplementation() => new LegacySongProgress(); } } From acf9ad1429ae0162e72f1d1f4738a97f2b18ccca Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 29 Jul 2022 23:26:38 +0900 Subject: [PATCH 174/278] Apply nullability to `EffectPointVisualisation` --- .../Summary/Parts/EffectPointVisualisation.cs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/EffectPointVisualisation.cs b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/EffectPointVisualisation.cs index 3dca1b1e8c..b61fcf4482 100644 --- a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/EffectPointVisualisation.cs +++ b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/EffectPointVisualisation.cs @@ -1,10 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Linq; -using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Extensions.Color4Extensions; @@ -19,13 +16,13 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts public class EffectPointVisualisation : CompositeDrawable, IControlPointVisualisation { private readonly EffectControlPoint effect; - private Bindable kiai; + private Bindable kiai = null!; [Resolved] - private EditorBeatmap beatmap { get; set; } + private EditorBeatmap beatmap { get; set; } = null!; [Resolved] - private OsuColour colours { get; set; } + private OsuColour colours { get; set; } = null!; public EffectPointVisualisation(EffectControlPoint point) { @@ -42,8 +39,7 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts kiai.BindValueChanged(_ => refreshDisplay(), true); } - [CanBeNull] - private EffectControlPoint nextControlPoint; + private EffectControlPoint? nextControlPoint; protected override void LoadComplete() { From eea211eb45864bf7708acf41ff6f90199d103ce4 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sat, 30 Jul 2022 02:46:39 +0900 Subject: [PATCH 175/278] Update framework --- osu.Android.props | 2 +- osu.Game/osu.Game.csproj | 2 +- osu.iOS.props | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Android.props b/osu.Android.props index 97fc97153c..9aba8e236c 100644 --- a/osu.Android.props +++ b/osu.Android.props @@ -52,7 +52,7 @@ - + diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index d95753179f..ecf5972797 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -36,7 +36,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/osu.iOS.props b/osu.iOS.props index 5455c94998..74d8f0d471 100644 --- a/osu.iOS.props +++ b/osu.iOS.props @@ -61,7 +61,7 @@ - + @@ -84,7 +84,7 @@ - + From 4e32d510c33ee3f501610818cb7bfa5dc7da2704 Mon Sep 17 00:00:00 2001 From: NaiPofo <50967056+naipofo@users.noreply.github.com> Date: Fri, 29 Jul 2022 20:08:32 +0200 Subject: [PATCH 176/278] Invalidate flashlightProperties on DrawInfo --- osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs index 3820e55e75..f0fce3d078 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs @@ -49,7 +49,7 @@ namespace osu.Game.Rulesets.Taiko.Mods private class TaikoFlashlight : Flashlight { - private readonly LayoutValue flashlightProperties = new LayoutValue(Invalidation.DrawSize); + private readonly LayoutValue flashlightProperties = new LayoutValue(Invalidation.DrawSize | Invalidation.DrawInfo); private readonly TaikoPlayfield taikoPlayfield; public TaikoFlashlight(TaikoModFlashlight modFlashlight, TaikoPlayfield taikoPlayfield) From e0107fc3dc296f9b863f2bc029604ab43a14a4e0 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 29 Jul 2022 20:54:57 +0300 Subject: [PATCH 177/278] Use `RequiredParentSizeToFit` to handle misc geometry changes --- osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs index f0fce3d078..8872de4d7a 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs @@ -49,7 +49,7 @@ namespace osu.Game.Rulesets.Taiko.Mods private class TaikoFlashlight : Flashlight { - private readonly LayoutValue flashlightProperties = new LayoutValue(Invalidation.DrawSize | Invalidation.DrawInfo); + private readonly LayoutValue flashlightProperties = new LayoutValue(Invalidation.RequiredParentSizeToFit | Invalidation.DrawInfo); private readonly TaikoPlayfield taikoPlayfield; public TaikoFlashlight(TaikoModFlashlight modFlashlight, TaikoPlayfield taikoPlayfield) From 0940e703b3bf8ff4a6b23be6d3d49f40905a91c4 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 30 Jul 2022 09:14:55 +0300 Subject: [PATCH 178/278] Fix normal skin hitsounds prioritised over default taiko hitsounds --- .../Skinning/Legacy/TaikoLegacySkinTransformer.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/osu.Game.Rulesets.Taiko/Skinning/Legacy/TaikoLegacySkinTransformer.cs b/osu.Game.Rulesets.Taiko/Skinning/Legacy/TaikoLegacySkinTransformer.cs index 888271f32d..c49884c00f 100644 --- a/osu.Game.Rulesets.Taiko/Skinning/Legacy/TaikoLegacySkinTransformer.cs +++ b/osu.Game.Rulesets.Taiko/Skinning/Legacy/TaikoLegacySkinTransformer.cs @@ -173,9 +173,6 @@ namespace osu.Game.Rulesets.Taiko.Skinning.Legacy { foreach (string name in base.LookupNames) yield return name.Insert(name.LastIndexOf('/') + 1, "taiko-"); - - foreach (string name in base.LookupNames) - yield return name; } } } From 40858c4cb7afec09e6a3b4a54b2d2e5c1f6e31f8 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 30 Jul 2022 09:32:39 +0300 Subject: [PATCH 179/278] Adjust existing test coverage --- .../TestSceneTaikoHitObjectSamples.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/osu.Game.Rulesets.Taiko.Tests/TestSceneTaikoHitObjectSamples.cs b/osu.Game.Rulesets.Taiko.Tests/TestSceneTaikoHitObjectSamples.cs index 674ac5670f..f8e04df78f 100644 --- a/osu.Game.Rulesets.Taiko.Tests/TestSceneTaikoHitObjectSamples.cs +++ b/osu.Game.Rulesets.Taiko.Tests/TestSceneTaikoHitObjectSamples.cs @@ -17,7 +17,6 @@ namespace osu.Game.Rulesets.Taiko.Tests protected override IResourceStore RulesetResources => new DllResourceStore(Assembly.GetAssembly(typeof(TestSceneTaikoHitObjectSamples))); [TestCase("taiko-normal-hitnormal")] - [TestCase("normal-hitnormal")] [TestCase("hitnormal")] public void TestDefaultCustomSampleFromBeatmap(string expectedSample) { @@ -29,7 +28,6 @@ namespace osu.Game.Rulesets.Taiko.Tests } [TestCase("taiko-normal-hitnormal")] - [TestCase("normal-hitnormal")] [TestCase("hitnormal")] public void TestDefaultCustomSampleFromUserSkinFallback(string expectedSample) { @@ -41,7 +39,6 @@ namespace osu.Game.Rulesets.Taiko.Tests } [TestCase("taiko-normal-hitnormal2")] - [TestCase("normal-hitnormal2")] public void TestUserSkinLookupIgnoresSampleBank(string unwantedSample) { SetupSkins(string.Empty, unwantedSample); From b32ff68a9517990dcb02484981ec9d2aaa5ae609 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 30 Jul 2022 09:33:23 +0300 Subject: [PATCH 180/278] Enable NRT on taiko legacy skin transformer and tests --- .../TestSceneTaikoHitObjectSamples.cs | 2 -- .../Skinning/Legacy/TaikoLegacySkinTransformer.cs | 6 ++---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/osu.Game.Rulesets.Taiko.Tests/TestSceneTaikoHitObjectSamples.cs b/osu.Game.Rulesets.Taiko.Tests/TestSceneTaikoHitObjectSamples.cs index f8e04df78f..c674f87f80 100644 --- a/osu.Game.Rulesets.Taiko.Tests/TestSceneTaikoHitObjectSamples.cs +++ b/osu.Game.Rulesets.Taiko.Tests/TestSceneTaikoHitObjectSamples.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Reflection; using NUnit.Framework; using osu.Framework.IO.Stores; diff --git a/osu.Game.Rulesets.Taiko/Skinning/Legacy/TaikoLegacySkinTransformer.cs b/osu.Game.Rulesets.Taiko/Skinning/Legacy/TaikoLegacySkinTransformer.cs index c49884c00f..992316ca53 100644 --- a/osu.Game.Rulesets.Taiko/Skinning/Legacy/TaikoLegacySkinTransformer.cs +++ b/osu.Game.Rulesets.Taiko/Skinning/Legacy/TaikoLegacySkinTransformer.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Collections.Generic; using osu.Framework.Audio.Sample; @@ -24,7 +22,7 @@ namespace osu.Game.Rulesets.Taiko.Skinning.Legacy hasExplosion = new Lazy(() => GetTexture(getHitName(TaikoSkinComponents.TaikoExplosionGreat)) != null); } - public override Drawable GetDrawableComponent(ISkinComponent component) + public override Drawable? GetDrawableComponent(ISkinComponent component) { if (component is GameplaySkinComponent) { @@ -151,7 +149,7 @@ namespace osu.Game.Rulesets.Taiko.Skinning.Legacy throw new ArgumentOutOfRangeException(nameof(component), $"Invalid component type: {component}"); } - public override ISample GetSample(ISampleInfo sampleInfo) + public override ISample? GetSample(ISampleInfo sampleInfo) { if (sampleInfo is HitSampleInfo hitSampleInfo) return base.GetSample(new LegacyTaikoSampleInfo(hitSampleInfo)); From 0c125db1972a619ec613f79406ba33b1575cb6d8 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 30 Jul 2022 09:57:18 +0300 Subject: [PATCH 181/278] Fix potential nullref on `TestSceneAutoplay` check steps --- osu.Game.Tests/Visual/Gameplay/TestSceneAutoplay.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneAutoplay.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneAutoplay.cs index 47c8dc0f8d..f2fe55d719 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneAutoplay.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneAutoplay.cs @@ -31,20 +31,20 @@ namespace osu.Game.Tests.Visual.Gameplay protected override void AddCheckSteps() { - // It doesn't matter which ruleset is used - this beatmap is only used for reference. - var beatmap = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo); + // we only want this beatmap for time reference. + var referenceBeatmap = CreateBeatmap(new OsuRuleset().RulesetInfo); AddUntilStep("score above zero", () => Player.ScoreProcessor.TotalScore.Value > 0); AddUntilStep("key counter counted keys", () => Player.HUDOverlay.KeyCounter.Children.Any(kc => kc.CountPresses > 2)); - seekTo(beatmap.Beatmap.Breaks[0].StartTime); + seekTo(referenceBeatmap.Breaks[0].StartTime); AddAssert("keys not counting", () => !Player.HUDOverlay.KeyCounter.IsCounting); AddAssert("overlay displays 100% accuracy", () => Player.BreakOverlay.ChildrenOfType().Single().AccuracyDisplay.Current.Value == 1); AddStep("rewind", () => Player.GameplayClockContainer.Seek(-80000)); AddUntilStep("key counter reset", () => Player.HUDOverlay.KeyCounter.Children.All(kc => kc.CountPresses == 0)); - seekTo(beatmap.Beatmap.HitObjects[^1].GetEndTime()); + seekTo(referenceBeatmap.HitObjects[^1].GetEndTime()); AddUntilStep("results displayed", () => getResultsScreen()?.IsLoaded == true); AddAssert("score has combo", () => getResultsScreen().Score.Combo > 100); From ec1a7994cccda03d7eaac4a37454e6ba9758aeb9 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 30 Jul 2022 09:58:17 +0300 Subject: [PATCH 182/278] Switch method to statement body for better readability Almost thought the method was not wrapped in an `AddStep`. --- .../TestSceneDrawableScrollingRuleset.cs | 41 ++++++++++--------- .../Gameplay/TestScenePoolingRuleset.cs | 29 +++++++------ 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableScrollingRuleset.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableScrollingRuleset.cs index a79ba0ae5d..334d8f1452 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableScrollingRuleset.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableScrollingRuleset.cs @@ -263,27 +263,30 @@ namespace osu.Game.Tests.Visual.Gameplay return beatmap; } - private void createTest(IBeatmap beatmap, Action overrideAction = null) => AddStep("create test", () => + private void createTest(IBeatmap beatmap, Action overrideAction = null) { - var ruleset = new TestScrollingRuleset(); - - drawableRuleset = (TestDrawableScrollingRuleset)ruleset.CreateDrawableRulesetWith(CreateWorkingBeatmap(beatmap).GetPlayableBeatmap(ruleset.RulesetInfo)); - drawableRuleset.FrameStablePlayback = false; - - overrideAction?.Invoke(drawableRuleset); - - Child = new Container + AddStep("create test", () => { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - RelativeSizeAxes = Axes.Y, - Height = 0.75f, - Width = 400, - Masking = true, - Clock = new FramedClock(testClock), - Child = drawableRuleset - }; - }); + var ruleset = new TestScrollingRuleset(); + + drawableRuleset = (TestDrawableScrollingRuleset)ruleset.CreateDrawableRulesetWith(CreateWorkingBeatmap(beatmap).GetPlayableBeatmap(ruleset.RulesetInfo)); + drawableRuleset.FrameStablePlayback = false; + + overrideAction?.Invoke(drawableRuleset); + + Child = new Container + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.Y, + Height = 0.75f, + Width = 400, + Masking = true, + Clock = new FramedClock(testClock), + Child = drawableRuleset + }; + }); + } #region Ruleset diff --git a/osu.Game.Tests/Visual/Gameplay/TestScenePoolingRuleset.cs b/osu.Game.Tests/Visual/Gameplay/TestScenePoolingRuleset.cs index 1fa4885b7a..618ffbcb0e 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestScenePoolingRuleset.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestScenePoolingRuleset.cs @@ -158,21 +158,24 @@ namespace osu.Game.Tests.Visual.Gameplay AddStep("clean up", () => drawableRuleset.NewResult -= onNewResult); } - private void createTest(IBeatmap beatmap, int poolSize, Func createClock = null) => AddStep("create test", () => + private void createTest(IBeatmap beatmap, int poolSize, Func createClock = null) { - var ruleset = new TestPoolingRuleset(); - - drawableRuleset = (TestDrawablePoolingRuleset)ruleset.CreateDrawableRulesetWith(CreateWorkingBeatmap(beatmap).GetPlayableBeatmap(ruleset.RulesetInfo)); - drawableRuleset.FrameStablePlayback = true; - drawableRuleset.PoolSize = poolSize; - - Child = new Container + AddStep("create test", () => { - RelativeSizeAxes = Axes.Both, - Clock = createClock?.Invoke() ?? new FramedOffsetClock(Clock, false) { Offset = -Clock.CurrentTime }, - Child = drawableRuleset - }; - }); + var ruleset = new TestPoolingRuleset(); + + drawableRuleset = (TestDrawablePoolingRuleset)ruleset.CreateDrawableRulesetWith(CreateWorkingBeatmap(beatmap).GetPlayableBeatmap(ruleset.RulesetInfo)); + drawableRuleset.FrameStablePlayback = true; + drawableRuleset.PoolSize = poolSize; + + Child = new Container + { + RelativeSizeAxes = Axes.Both, + Clock = createClock?.Invoke() ?? new FramedOffsetClock(Clock, false) { Offset = -Clock.CurrentTime }, + Child = drawableRuleset + }; + }); + } #region Ruleset From 369ab10212c87ea468749e3e16cd2e7805cdc60e Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 30 Jul 2022 10:31:23 +0300 Subject: [PATCH 183/278] Fix exit confirmation dialog not blocking all exit cases --- .../Screens/OnlinePlay/Match/RoomSubScreen.cs | 45 ++++++++++++------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs b/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs index 5b3ed0059d..1b90d557d1 100644 --- a/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs @@ -288,23 +288,11 @@ namespace osu.Game.Screens.OnlinePlay.Match { if (Room.RoomID.Value == null) { - if (dialogOverlay == null || Room.Playlist.Count == 0) - { - settingsOverlay.Hide(); - return base.OnBackButton(); - } - - // if the dialog is already displayed, block exiting until the user explicitly makes a decision. - if (dialogOverlay.CurrentDialog is ConfirmDiscardChangesDialog) + if (!ensureExitConfirmed()) return true; - dialogOverlay?.Push(new ConfirmDiscardChangesDialog(() => - { - settingsOverlay.Hide(); - this.Exit(); - })); - - return true; + settingsOverlay.Hide(); + return base.OnBackButton(); } if (UserModsSelectOverlay.State.Value == Visibility.Visible) @@ -348,8 +336,13 @@ namespace osu.Game.Screens.OnlinePlay.Match Scheduler.AddOnce(updateRuleset); } + private bool exitConfirmed; + public override bool OnExiting(ScreenExitEvent e) { + if (!ensureExitConfirmed()) + return true; + RoomManager?.PartRoom(); Mods.Value = Array.Empty(); @@ -358,6 +351,28 @@ namespace osu.Game.Screens.OnlinePlay.Match return base.OnExiting(e); } + private bool ensureExitConfirmed() + { + if (exitConfirmed) + return true; + + if (dialogOverlay == null || Room.RoomID.Value != null || Room.Playlist.Count == 0) + return true; + + // if the dialog is already displayed, block exiting until the user explicitly makes a decision. + if (dialogOverlay.CurrentDialog is ConfirmDiscardChangesDialog) + return false; + + dialogOverlay.Push(new ConfirmDiscardChangesDialog(() => + { + exitConfirmed = true; + settingsOverlay.Hide(); + this.Exit(); + })); + + return false; + } + protected void StartPlay() { // User may be at song select or otherwise when the host starts gameplay. From 8ca8484f0e387b1a8a86b943b566350232e398ba Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 30 Jul 2022 11:49:33 +0300 Subject: [PATCH 184/278] Fix failing tests --- .../TestSceneMultiplayerMatchSubScreen.cs | 30 ++++++++++++++++++- .../TestScenePlaylistsRoomCreation.cs | 20 +++++++++++++ .../Screens/OnlinePlay/Match/RoomSubScreen.cs | 6 ++-- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchSubScreen.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchSubScreen.cs index 8d31e9c723..9fc42dc68b 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchSubScreen.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchSubScreen.cs @@ -4,6 +4,7 @@ #nullable disable using System.Linq; +using JetBrains.Annotations; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Audio; @@ -17,6 +18,8 @@ using osu.Game.Online.API; using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Multiplayer; using osu.Game.Online.Rooms; +using osu.Game.Overlays; +using osu.Game.Overlays.Dialog; using osu.Game.Overlays.Mods; using osu.Game.Rulesets; using osu.Game.Rulesets.Osu; @@ -24,6 +27,7 @@ using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Taiko; using osu.Game.Rulesets.Taiko.Mods; using osu.Game.Rulesets.UI; +using osu.Game.Screens.Menu; using osu.Game.Screens.OnlinePlay; using osu.Game.Screens.OnlinePlay.Match; using osu.Game.Screens.OnlinePlay.Multiplayer; @@ -65,7 +69,7 @@ namespace osu.Game.Tests.Visual.Multiplayer AddStep("load match", () => { SelectedRoom.Value = new Room { Name = { Value = "Test Room" } }; - LoadScreen(screen = new MultiplayerMatchSubScreen(SelectedRoom.Value)); + LoadScreen(screen = new TestMultiplayerMatchSubScreen(SelectedRoom.Value)); }); AddUntilStep("wait for load", () => screen.IsCurrentScreen()); @@ -281,5 +285,29 @@ namespace osu.Game.Tests.Visual.Multiplayer return lastItem.IsSelectedItem; }); } + + private class TestMultiplayerMatchSubScreen : MultiplayerMatchSubScreen + { + [Resolved(canBeNull: true)] + [CanBeNull] + private IDialogOverlay dialogOverlay { get; set; } + + public TestMultiplayerMatchSubScreen(Room room) + : base(room) + { + } + + public override bool OnExiting(ScreenExitEvent e) + { + // For testing purposes allow the screen to exit without confirming on second attempt. + if (!ExitConfirmed && dialogOverlay?.CurrentDialog is ConfirmDiscardChangesDialog confirmDialog) + { + confirmDialog.PerformAction(); + return true; + } + + return base.OnExiting(e); + } + } } } diff --git a/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsRoomCreation.cs b/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsRoomCreation.cs index e798f72891..b304b34275 100644 --- a/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsRoomCreation.cs +++ b/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsRoomCreation.cs @@ -6,6 +6,7 @@ using System; using System.Diagnostics; using System.Linq; +using JetBrains.Annotations; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Audio; @@ -16,9 +17,12 @@ using osu.Framework.Testing; using osu.Game.Beatmaps; using osu.Game.Database; using osu.Game.Online.Rooms; +using osu.Game.Overlays; +using osu.Game.Overlays.Dialog; using osu.Game.Rulesets; using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu.Objects; +using osu.Game.Screens.Menu; using osu.Game.Screens.OnlinePlay.Components; using osu.Game.Screens.OnlinePlay.Match.Components; using osu.Game.Screens.OnlinePlay.Playlists; @@ -221,10 +225,26 @@ namespace osu.Game.Tests.Visual.Playlists public new Bindable Beatmap => base.Beatmap; + [Resolved(canBeNull: true)] + [CanBeNull] + private IDialogOverlay dialogOverlay { get; set; } + public TestPlaylistsRoomSubScreen(Room room) : base(room) { } + + public override bool OnExiting(ScreenExitEvent e) + { + // For testing purposes allow the screen to exit without confirming on second attempt. + if (!ExitConfirmed && dialogOverlay?.CurrentDialog is ConfirmDiscardChangesDialog confirmDialog) + { + confirmDialog.PerformAction(); + return true; + } + + return base.OnExiting(e); + } } } } diff --git a/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs b/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs index 1b90d557d1..25f2a94a3c 100644 --- a/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs @@ -336,7 +336,7 @@ namespace osu.Game.Screens.OnlinePlay.Match Scheduler.AddOnce(updateRuleset); } - private bool exitConfirmed; + protected bool ExitConfirmed { get; private set; } public override bool OnExiting(ScreenExitEvent e) { @@ -353,7 +353,7 @@ namespace osu.Game.Screens.OnlinePlay.Match private bool ensureExitConfirmed() { - if (exitConfirmed) + if (ExitConfirmed) return true; if (dialogOverlay == null || Room.RoomID.Value != null || Room.Playlist.Count == 0) @@ -365,7 +365,7 @@ namespace osu.Game.Screens.OnlinePlay.Match dialogOverlay.Push(new ConfirmDiscardChangesDialog(() => { - exitConfirmed = true; + ExitConfirmed = true; settingsOverlay.Hide(); this.Exit(); })); From 38a8b9cf0af9e5bbd523378710ab2adbd908a36d Mon Sep 17 00:00:00 2001 From: Susko3 Date: Sat, 30 Jul 2022 14:26:19 +0200 Subject: [PATCH 185/278] Add battery info for desktop platforms --- osu.Android/OsuGameAndroid.cs | 4 +-- osu.Desktop/OsuGameDesktop.cs | 22 ++++++++++++++++ .../Visual/Gameplay/TestScenePlayerLoader.cs | 25 ++++++++++--------- osu.Game/Screens/Play/PlayerLoader.cs | 4 ++- osu.Game/Utils/BatteryInfo.cs | 12 ++++++--- osu.iOS/OsuGameIOS.cs | 4 +-- 6 files changed, 51 insertions(+), 20 deletions(-) diff --git a/osu.Android/OsuGameAndroid.cs b/osu.Android/OsuGameAndroid.cs index 062f2ce10c..6b88f21bcd 100644 --- a/osu.Android/OsuGameAndroid.cs +++ b/osu.Android/OsuGameAndroid.cs @@ -106,9 +106,9 @@ namespace osu.Android private class AndroidBatteryInfo : BatteryInfo { - public override double ChargeLevel => Battery.ChargeLevel; + public override double? ChargeLevel => Battery.ChargeLevel; - public override bool IsCharging => Battery.PowerSource != BatteryPowerSource.Battery; + public override bool OnBattery => Battery.PowerSource == BatteryPowerSource.Battery; } } } diff --git a/osu.Desktop/OsuGameDesktop.cs b/osu.Desktop/OsuGameDesktop.cs index 524436235e..d9ad95f96a 100644 --- a/osu.Desktop/OsuGameDesktop.cs +++ b/osu.Desktop/OsuGameDesktop.cs @@ -29,6 +29,8 @@ using osu.Game.IPC; using osu.Game.Overlays.Settings; using osu.Game.Overlays.Settings.Sections; using osu.Game.Overlays.Settings.Sections.Input; +using osu.Game.Utils; +using SDL2; namespace osu.Desktop { @@ -166,6 +168,8 @@ namespace osu.Desktop } } + protected override BatteryInfo CreateBatteryInfo() => new SDL2BatteryInfo(); + private readonly List importableFiles = new List(); private ScheduledDelegate? importSchedule; @@ -206,5 +210,23 @@ namespace osu.Desktop base.Dispose(isDisposing); osuSchemeLinkIPCChannel?.Dispose(); } + + private class SDL2BatteryInfo : BatteryInfo + { + public override double? ChargeLevel + { + get + { + SDL.SDL_GetPowerInfo(out _, out int percentage); + + if (percentage == -1) + return null; + + return percentage / 100.0; + } + } + + public override bool OnBattery => SDL.SDL_GetPowerInfo(out _, out _) == SDL.SDL_PowerState.SDL_POWERSTATE_ON_BATTERY; + } } } diff --git a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs index 56588e4d4e..05474e3d39 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs @@ -308,17 +308,18 @@ namespace osu.Game.Tests.Visual.Gameplay } } - [TestCase(false, 1.0, false)] // not charging, above cutoff --> no warning - [TestCase(true, 0.1, false)] // charging, below cutoff --> no warning - [TestCase(false, 0.25, true)] // not charging, at cutoff --> warning - public void TestLowBatteryNotification(bool isCharging, double chargeLevel, bool shouldWarn) + [TestCase(true, 1.0, false)] // on battery, above cutoff --> no warning + [TestCase(false, 0.1, false)] // not on battery, below cutoff --> no warning + [TestCase(true, 0.25, true)] // on battery, at cutoff --> warning + [TestCase(true, null, false)] // on battery, level unknown --> no warning + public void TestLowBatteryNotification(bool onBattery, double? chargeLevel, bool shouldWarn) { AddStep("reset notification lock", () => sessionStatics.GetBindable(Static.LowBatteryNotificationShownOnce).Value = false); // set charge status and level AddStep("load player", () => resetPlayer(false, () => { - batteryInfo.SetCharging(isCharging); + batteryInfo.SetOnBattery(onBattery); batteryInfo.SetChargeLevel(chargeLevel); })); AddUntilStep("wait for player", () => player?.LoadState == LoadState.Ready); @@ -408,19 +409,19 @@ namespace osu.Game.Tests.Visual.Gameplay /// private class LocalBatteryInfo : BatteryInfo { - private bool isCharging = true; - private double chargeLevel = 1; + private bool onBattery; + private double? chargeLevel; - public override bool IsCharging => isCharging; + public override bool OnBattery => onBattery; - public override double ChargeLevel => chargeLevel; + public override double? ChargeLevel => chargeLevel; - public void SetCharging(bool value) + public void SetOnBattery(bool value) { - isCharging = value; + onBattery = value; } - public void SetChargeLevel(double value) + public void SetChargeLevel(double? value) { chargeLevel = value; } diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index 5d7319c51f..674490d595 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -549,6 +549,8 @@ namespace osu.Game.Screens.Play #region Low battery warning + private const double low_battery_threshold = 0.25; + private Bindable batteryWarningShownOnce = null!; private void showBatteryWarningIfNeeded() @@ -557,7 +559,7 @@ namespace osu.Game.Screens.Play if (!batteryWarningShownOnce.Value) { - if (!batteryInfo.IsCharging && batteryInfo.ChargeLevel <= 0.25) + if (batteryInfo.OnBattery && batteryInfo.ChargeLevel <= low_battery_threshold) { notificationOverlay?.Post(new BatteryWarningNotification()); batteryWarningShownOnce.Value = true; diff --git a/osu.Game/Utils/BatteryInfo.cs b/osu.Game/Utils/BatteryInfo.cs index dd9b695e1f..ef75857a26 100644 --- a/osu.Game/Utils/BatteryInfo.cs +++ b/osu.Game/Utils/BatteryInfo.cs @@ -9,10 +9,16 @@ namespace osu.Game.Utils public abstract class BatteryInfo { /// - /// The charge level of the battery, from 0 to 1. + /// The charge level of the battery, from 0 to 1, or null if a battery isn't present. /// - public abstract double ChargeLevel { get; } + public abstract double? ChargeLevel { get; } - public abstract bool IsCharging { get; } + /// + /// Whether the current power source is the battery. + /// + /// + /// This is false when the device is charging or doesn't have a battery. + /// + public abstract bool OnBattery { get; } } } diff --git a/osu.iOS/OsuGameIOS.cs b/osu.iOS/OsuGameIOS.cs index 452b573389..ecbea42d74 100644 --- a/osu.iOS/OsuGameIOS.cs +++ b/osu.iOS/OsuGameIOS.cs @@ -43,9 +43,9 @@ namespace osu.iOS private class IOSBatteryInfo : BatteryInfo { - public override double ChargeLevel => Battery.ChargeLevel; + public override double? ChargeLevel => Battery.ChargeLevel; - public override bool IsCharging => Battery.PowerSource != BatteryPowerSource.Battery; + public override bool OnBattery => Battery.PowerSource == BatteryPowerSource.Battery; } } } From e5118130db0dd53f3f46a7a5404d23524a55083f Mon Sep 17 00:00:00 2001 From: Susko3 Date: Sat, 30 Jul 2022 16:05:35 +0200 Subject: [PATCH 186/278] Add 'SDL' acronym --- osu.sln.DotSettings | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.sln.DotSettings b/osu.sln.DotSettings index b16e309e52..3ad29ea6db 100644 --- a/osu.sln.DotSettings +++ b/osu.sln.DotSettings @@ -350,6 +350,7 @@ PM RGB RNG + SDL SHA SRGB TK From b95aff3e5f4bae1917cc8c546dab295bc9874201 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 30 Jul 2022 18:50:41 +0300 Subject: [PATCH 187/278] Add failing test case --- .../SongSelect/TestScenePlaySongSelect.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs b/osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs index 12f15b04dc..3d8f496c9a 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs @@ -10,6 +10,7 @@ using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Bindables; +using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics.Containers; using osu.Framework.Platform; using osu.Framework.Screens; @@ -282,6 +283,28 @@ namespace osu.Game.Tests.Visual.SongSelect AddAssert("filter count is 2", () => songSelect.FilterCount == 2); } + [Test] + public void TestCarouselSelectionUpdatesOnResume() + { + addRulesetImportStep(0); + + createSongSelect(); + + AddStep("push child screen", () => Stack.Push(new TestSceneOsuScreenStack.TestScreen("test child"))); + AddUntilStep("wait for not current", () => !songSelect.IsCurrentScreen()); + + AddStep("update beatmap", () => + { + var selectedBeatmap = Beatmap.Value.BeatmapInfo; + var anotherBeatmap = Beatmap.Value.BeatmapSetInfo.Beatmaps.Except(selectedBeatmap.Yield()).First(); + Beatmap.Value = manager.GetWorkingBeatmap(anotherBeatmap); + }); + + AddStep("return", () => songSelect.MakeCurrent()); + AddUntilStep("wait for current", () => songSelect.IsCurrentScreen()); + AddAssert("carousel updated", () => songSelect.Carousel.SelectedBeatmapInfo.Equals(Beatmap.Value.BeatmapInfo)); + } + [Test] public void TestAudioResuming() { From 8e06d55960bdcc7c6f741cbd6480fe4c678f264f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 31 Jul 2022 00:53:39 +0900 Subject: [PATCH 188/278] Fix collection migration incorrectly running asynchronously --- osu.Game/Database/RealmAccess.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Database/RealmAccess.cs b/osu.Game/Database/RealmAccess.cs index 6a0d4d34db..bcfb6828f8 100644 --- a/osu.Game/Database/RealmAccess.cs +++ b/osu.Game/Database/RealmAccess.cs @@ -802,8 +802,8 @@ namespace osu.Game.Database if (legacyCollectionImporter.GetAvailableCount(storage).GetResultSafely() > 0) { - legacyCollectionImporter.ImportFromStorage(storage); storage.Delete("collection.db"); + legacyCollectionImporter.ImportFromStorage(storage).WaitSafely(); } } catch (Exception e) From 80ffa2cf200ac634865f767a6957c61a96d296a9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 31 Jul 2022 00:54:00 +0900 Subject: [PATCH 189/278] Move collection database rather than deleting post-migration for safety --- osu.Game/Database/RealmAccess.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Database/RealmAccess.cs b/osu.Game/Database/RealmAccess.cs index bcfb6828f8..8ab04cce3e 100644 --- a/osu.Game/Database/RealmAccess.cs +++ b/osu.Game/Database/RealmAccess.cs @@ -802,8 +802,8 @@ namespace osu.Game.Database if (legacyCollectionImporter.GetAvailableCount(storage).GetResultSafely() > 0) { - storage.Delete("collection.db"); legacyCollectionImporter.ImportFromStorage(storage).WaitSafely(); + storage.Move("collection.db", "collection.db.migrated"); } } catch (Exception e) From 6ad86ce5b780c6b74fbd3f37bc2e80c3d4476310 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 31 Jul 2022 01:06:55 +0900 Subject: [PATCH 190/278] Run collection import process asynchronously Actually required to avoid deadlocking.. --- osu.Game/Database/RealmAccess.cs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/osu.Game/Database/RealmAccess.cs b/osu.Game/Database/RealmAccess.cs index 8ab04cce3e..1a0c03af7d 100644 --- a/osu.Game/Database/RealmAccess.cs +++ b/osu.Game/Database/RealmAccess.cs @@ -794,22 +794,23 @@ namespace osu.Game.Database break; case 21: - try - { - // Migrate collections from external file to inside realm. - // We use the "legacy" importer because that is how things were actually being saved out until now. - var legacyCollectionImporter = new LegacyCollectionImporter(this); + // Migrate collections from external file to inside realm. + // We use the "legacy" importer because that is how things were actually being saved out until now. + var legacyCollectionImporter = new LegacyCollectionImporter(this); - if (legacyCollectionImporter.GetAvailableCount(storage).GetResultSafely() > 0) - { - legacyCollectionImporter.ImportFromStorage(storage).WaitSafely(); - storage.Move("collection.db", "collection.db.migrated"); - } - } - catch (Exception e) + if (legacyCollectionImporter.GetAvailableCount(storage).GetResultSafely() > 0) { - // can be removed 20221027 (just for initial safety). - Logger.Error(e, "Collections could not be migrated to realm. Please provide your \"collection.db\" to the dev team."); + legacyCollectionImporter.ImportFromStorage(storage).ContinueWith(task => + { + if (task.Exception != null) + { + // can be removed 20221027 (just for initial safety). + Logger.Error(task.Exception.InnerException, "Collections could not be migrated to realm. Please provide your \"collection.db\" to the dev team."); + return; + } + + storage.Move("collection.db", "collection.db.migrated"); + }); } break; From faefda9143ec1185cecc5ea445d6825cd67d3830 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 30 Jul 2022 18:51:19 +0300 Subject: [PATCH 191/278] Fix song select not updating selected beatmap card on editor resume --- osu.Game/Screens/Select/SongSelect.cs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index 7abcbfca42..596a8eb896 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -405,20 +405,21 @@ namespace osu.Game.Screens.Select private ScheduledDelegate selectionChangedDebounce; - private void workingBeatmapChanged(ValueChangedEvent e) + private void updateCarouselSelection(ValueChangedEvent e = null) { - if (e.NewValue is DummyWorkingBeatmap || !this.IsCurrentScreen()) return; + var beatmap = e?.NewValue ?? Beatmap.Value; + if (beatmap is DummyWorkingBeatmap || !this.IsCurrentScreen()) return; - Logger.Log($"Song select working beatmap updated to {e.NewValue}"); + Logger.Log($"Song select working beatmap updated to {beatmap}"); - if (!Carousel.SelectBeatmap(e.NewValue.BeatmapInfo, false)) + if (!Carousel.SelectBeatmap(beatmap.BeatmapInfo, false)) { // A selection may not have been possible with filters applied. // There was possibly a ruleset mismatch. This is a case we can help things along by updating the game-wide ruleset to match. - if (!e.NewValue.BeatmapInfo.Ruleset.Equals(decoupledRuleset.Value)) + if (!beatmap.BeatmapInfo.Ruleset.Equals(decoupledRuleset.Value)) { - Ruleset.Value = e.NewValue.BeatmapInfo.Ruleset; + Ruleset.Value = beatmap.BeatmapInfo.Ruleset; transferRulesetValue(); } @@ -426,10 +427,10 @@ namespace osu.Game.Screens.Select // we still want to temporarily show the new beatmap, bypassing filters. // This will be undone the next time the user changes the filter. var criteria = FilterControl.CreateCriteria(); - criteria.SelectedBeatmapSet = e.NewValue.BeatmapInfo.BeatmapSet; + criteria.SelectedBeatmapSet = beatmap.BeatmapInfo.BeatmapSet; Carousel.Filter(criteria); - Carousel.SelectBeatmap(e.NewValue.BeatmapInfo); + Carousel.SelectBeatmap(beatmap.BeatmapInfo); } } @@ -597,6 +598,8 @@ namespace osu.Game.Screens.Select if (Beatmap != null && !Beatmap.Value.BeatmapSetInfo.DeletePending) { + updateCarouselSelection(); + updateComponentFromBeatmap(Beatmap.Value); if (ControlGlobalMusic) @@ -805,7 +808,7 @@ namespace osu.Game.Screens.Select }; decoupledRuleset.DisabledChanged += r => Ruleset.Disabled = r; - Beatmap.BindValueChanged(workingBeatmapChanged); + Beatmap.BindValueChanged(updateCarouselSelection); boundLocalBindables = true; } From 93b783d9eaa6203de4be2987e6da816ad27dc32f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 31 Jul 2022 03:25:38 +0900 Subject: [PATCH 192/278] Fix previous skins not loading due to namespace changes --- osu.Game/Skinning/Skin.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/osu.Game/Skinning/Skin.cs b/osu.Game/Skinning/Skin.cs index d6aa9cdaad..7d93aeb897 100644 --- a/osu.Game/Skinning/Skin.cs +++ b/osu.Game/Skinning/Skin.cs @@ -108,6 +108,13 @@ namespace osu.Game.Skinning try { string jsonContent = Encoding.UTF8.GetString(bytes); + + // handle namespace changes... + + // can be removed 2023-01-31 + jsonContent = jsonContent.Replace(@"osu.Game.Screens.Play.SongProgress", @"osu.Game.Screens.Play.HUD.DefaultSongProgress"); + jsonContent = jsonContent.Replace(@"osu.Game.Screens.Play.HUD.LegacyComboCounter", @"osu.Game.Skinning.LegacyComboCounter"); + var deserializedContent = JsonConvert.DeserializeObject>(jsonContent); if (deserializedContent == null) From 632577389df1890a6c3a987954156c8cb4634a4b Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 31 Jul 2022 21:43:16 +0800 Subject: [PATCH 193/278] Mark the property as non-nullable. --- osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs | 11 +++-------- osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs | 5 +---- osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs | 5 ++--- osu.Game.Rulesets.Osu/Mods/OsuModMagnetised.cs | 5 +---- osu.Game.Rulesets.Osu/Mods/OsuModNoScope.cs | 5 ++--- osu.Game.Rulesets.Osu/Mods/OsuModRelax.cs | 10 +++------- osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs | 7 ++----- 7 files changed, 14 insertions(+), 34 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs b/osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs index 83c1deb3b9..872fcf7e9b 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using osu.Framework.Graphics.Sprites; using osu.Framework.Input.StateChanges; @@ -29,20 +28,16 @@ namespace osu.Game.Rulesets.Osu.Mods public bool RestartOnFail => false; - private OsuInputManager? inputManager; + private OsuInputManager inputManager = null!; - private IFrameStableClock? gameplayClock; + private IFrameStableClock gameplayClock = null!; - private List? replayFrames; + private List replayFrames = null!; private int currentFrame; public void Update(Playfield playfield) { - Debug.Assert(inputManager != null); - Debug.Assert(gameplayClock != null); - Debug.Assert(replayFrames != null); - if (currentFrame == replayFrames.Count - 1) return; double time = gameplayClock.CurrentTime; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs index 808e7720a4..56665db770 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs @@ -2,7 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Diagnostics; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -32,7 +31,7 @@ namespace osu.Game.Rulesets.Osu.Mods public override double ScoreMultiplier => UsesDefaultConfiguration ? 1.12 : 1; public override Type[] IncompatibleMods => new[] { typeof(OsuModFlashlight) }; - private DrawableOsuBlinds? blinds; + private DrawableOsuBlinds blinds = null!; public void ApplyToDrawableRuleset(DrawableRuleset drawableRuleset) { @@ -41,8 +40,6 @@ namespace osu.Game.Rulesets.Osu.Mods public void ApplyToHealthProcessor(HealthProcessor healthProcessor) { - Debug.Assert(blinds != null); - healthProcessor.Health.ValueChanged += health => { blinds.AnimateClosedness((float)health.NewValue); }; } diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs b/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs index 510e95b13f..e5a458488e 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs @@ -4,7 +4,6 @@ using System; using System.Linq; using osu.Framework.Bindables; -using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Framework.Input; using osu.Framework.Input.Events; @@ -52,14 +51,14 @@ namespace osu.Game.Rulesets.Osu.Mods public override float DefaultFlashlightSize => 180; - private OsuFlashlight? flashlight; + private OsuFlashlight flashlight = null!; protected override Flashlight CreateFlashlight() => flashlight = new OsuFlashlight(this); public void ApplyToDrawableHitObject(DrawableHitObject drawable) { if (drawable is DrawableSlider s) - s.Tracking.ValueChanged += flashlight.AsNonNull().OnSliderTrackingChange; + s.Tracking.ValueChanged += flashlight.OnSliderTrackingChange; } private class OsuFlashlight : Flashlight, IRequireHighFrequencyMousePosition diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModMagnetised.cs b/osu.Game.Rulesets.Osu/Mods/OsuModMagnetised.cs index 107eac6430..9316f9ed74 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModMagnetised.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModMagnetised.cs @@ -2,7 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Diagnostics; using osu.Framework.Bindables; using osu.Framework.Graphics.Sprites; using osu.Framework.Utils; @@ -27,7 +26,7 @@ namespace osu.Game.Rulesets.Osu.Mods public override double ScoreMultiplier => 1; public override Type[] IncompatibleMods => new[] { typeof(OsuModAutopilot), typeof(OsuModWiggle), typeof(OsuModTransform), typeof(ModAutoplay), typeof(OsuModRelax), typeof(OsuModRepel) }; - private IFrameStableClock? gameplayClock; + private IFrameStableClock gameplayClock = null!; [SettingSource("Attraction strength", "How strong the pull is.", 0)] public BindableFloat AttractionStrength { get; } = new BindableFloat(0.5f) @@ -75,8 +74,6 @@ namespace osu.Game.Rulesets.Osu.Mods { double dampLength = Interpolation.Lerp(3000, 40, AttractionStrength.Value); - Debug.Assert(gameplayClock != null); - float x = (float)Interpolation.DampContinuously(hitObject.X, destination.X, dampLength, gameplayClock.ElapsedFrameTime); float y = (float)Interpolation.DampContinuously(hitObject.Y, destination.Y, dampLength, gameplayClock.ElapsedFrameTime); diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModNoScope.cs b/osu.Game.Rulesets.Osu/Mods/OsuModNoScope.cs index 0197b7cb1b..3eb8982f5d 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModNoScope.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModNoScope.cs @@ -4,7 +4,6 @@ using System; using System.Linq; using osu.Framework.Bindables; -using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Utils; using osu.Game.Beatmaps; using osu.Game.Configuration; @@ -20,7 +19,7 @@ namespace osu.Game.Rulesets.Osu.Mods { public override string Description => "Where's the cursor?"; - private PeriodTracker? spinnerPeriods; + private PeriodTracker spinnerPeriods = null!; [SettingSource( "Hidden at combo", @@ -42,7 +41,7 @@ namespace osu.Game.Rulesets.Osu.Mods public void Update(Playfield playfield) { - bool shouldAlwaysShowCursor = IsBreakTime.Value || spinnerPeriods.AsNonNull().IsInAny(playfield.Clock.CurrentTime); + bool shouldAlwaysShowCursor = IsBreakTime.Value || spinnerPeriods.IsInAny(playfield.Clock.CurrentTime); float targetAlpha = shouldAlwaysShowCursor ? 1 : ComboBasedAlpha; playfield.Cursor.Alpha = (float)Interpolation.Lerp(playfield.Cursor.Alpha, targetAlpha, Math.Clamp(playfield.Time.Elapsed / TRANSITION_DURATION, 0, 1)); } diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModRelax.cs b/osu.Game.Rulesets.Osu/Mods/OsuModRelax.cs index ac45ce2ade..908bb34ed6 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModRelax.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModRelax.cs @@ -29,9 +29,9 @@ namespace osu.Game.Rulesets.Osu.Mods private bool isDownState; private bool wasLeft; - private OsuInputManager? osuInputManager; + private OsuInputManager osuInputManager = null!; - private ReplayState? state; + private ReplayState state = null!; private double lastStateChangeTime; private bool hasReplay; @@ -44,8 +44,6 @@ namespace osu.Game.Rulesets.Osu.Mods public void ApplyToPlayer(Player player) { - Debug.Assert(osuInputManager != null); - if (osuInputManager.ReplayInputHandler != null) { hasReplay = true; @@ -134,9 +132,7 @@ namespace osu.Game.Rulesets.Osu.Mods wasLeft = !wasLeft; } - Debug.Assert(osuInputManager != null); - - state?.Apply(osuInputManager.CurrentState, osuInputManager); + state.Apply(osuInputManager.CurrentState, osuInputManager); } } } diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs b/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs index c793ed4937..c273da2462 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using osu.Framework.Bindables; using osu.Framework.Extensions.ObjectExtensions; @@ -96,7 +95,7 @@ namespace osu.Game.Rulesets.Osu.Mods #region Private Fields - private ControlPointInfo? controlPointInfo; + private ControlPointInfo controlPointInfo = null!; #endregion @@ -156,7 +155,7 @@ namespace osu.Game.Rulesets.Osu.Mods circle.ApproachCircle.Hide(); } - using (circle.BeginAbsoluteSequence(startTime - controlPointInfo.AsNonNull().TimingPointAt(startTime).BeatLength - undim_duration)) + using (circle.BeginAbsoluteSequence(startTime - controlPointInfo.TimingPointAt(startTime).BeatLength - undim_duration)) circle.FadeColour(Color4.White, undim_duration); } @@ -372,8 +371,6 @@ namespace osu.Game.Rulesets.Osu.Mods int i = 0; double currentTime = timingPoint.Time; - Debug.Assert(controlPointInfo != null); - while (!definitelyBigger(currentTime, mapEndTime) && ReferenceEquals(controlPointInfo.TimingPointAt(currentTime), timingPoint)) { beats.Add(Math.Floor(currentTime)); From 6c964dee308a48b57699fa5877e846e2cfda3ce9 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 31 Jul 2022 22:00:14 +0800 Subject: [PATCH 194/278] Rename the nullable disable annotation in the Audio namespace and mark some properties as nullable. --- osu.Game/Audio/Effects/AudioFilter.cs | 2 -- osu.Game/Audio/Effects/ITransformableFilter.cs | 2 -- osu.Game/Audio/IPreviewTrackOwner.cs | 2 -- osu.Game/Audio/ISampleInfo.cs | 2 -- osu.Game/Audio/ISamplePlaybackDisabler.cs | 2 -- osu.Game/Audio/PreviewTrack.cs | 6 ++---- osu.Game/Audio/PreviewTrackManager.cs | 8 +++----- osu.Game/Audio/SampleInfo.cs | 4 +--- 8 files changed, 6 insertions(+), 22 deletions(-) diff --git a/osu.Game/Audio/Effects/AudioFilter.cs b/osu.Game/Audio/Effects/AudioFilter.cs index 5c318eb957..9446967173 100644 --- a/osu.Game/Audio/Effects/AudioFilter.cs +++ b/osu.Game/Audio/Effects/AudioFilter.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Diagnostics; using ManagedBass.Fx; using osu.Framework.Audio.Mixing; diff --git a/osu.Game/Audio/Effects/ITransformableFilter.cs b/osu.Game/Audio/Effects/ITransformableFilter.cs index 02149b362c..fb6a924f68 100644 --- a/osu.Game/Audio/Effects/ITransformableFilter.cs +++ b/osu.Game/Audio/Effects/ITransformableFilter.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Graphics; using osu.Framework.Graphics.Transforms; diff --git a/osu.Game/Audio/IPreviewTrackOwner.cs b/osu.Game/Audio/IPreviewTrackOwner.cs index 6a3acc2059..8ab93257a5 100644 --- a/osu.Game/Audio/IPreviewTrackOwner.cs +++ b/osu.Game/Audio/IPreviewTrackOwner.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - namespace osu.Game.Audio { /// diff --git a/osu.Game/Audio/ISampleInfo.cs b/osu.Game/Audio/ISampleInfo.cs index 8f58415587..4f81d37e78 100644 --- a/osu.Game/Audio/ISampleInfo.cs +++ b/osu.Game/Audio/ISampleInfo.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Collections.Generic; namespace osu.Game.Audio diff --git a/osu.Game/Audio/ISamplePlaybackDisabler.cs b/osu.Game/Audio/ISamplePlaybackDisabler.cs index 250e004b05..4167316780 100644 --- a/osu.Game/Audio/ISamplePlaybackDisabler.cs +++ b/osu.Game/Audio/ISamplePlaybackDisabler.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Game.Skinning; diff --git a/osu.Game/Audio/PreviewTrack.cs b/osu.Game/Audio/PreviewTrack.cs index 8ff8cd5c54..cfedd581e5 100644 --- a/osu.Game/Audio/PreviewTrack.cs +++ b/osu.Game/Audio/PreviewTrack.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using osu.Framework.Allocation; using osu.Framework.Audio.Track; @@ -18,13 +16,13 @@ namespace osu.Game.Audio /// Invoked when this has stopped playing. /// Not invoked in a thread-safe context. /// - public event Action Stopped; + public event Action? Stopped; /// /// Invoked when this has started playing. /// Not invoked in a thread-safe context. /// - public event Action Started; + public event Action? Started; protected Track Track { get; private set; } diff --git a/osu.Game/Audio/PreviewTrackManager.cs b/osu.Game/Audio/PreviewTrackManager.cs index d19fdbd94c..a0537d7a4e 100644 --- a/osu.Game/Audio/PreviewTrackManager.cs +++ b/osu.Game/Audio/PreviewTrackManager.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Audio.Track; @@ -20,9 +18,9 @@ namespace osu.Game.Audio private readonly BindableDouble muteBindable = new BindableDouble(); - private ITrackStore trackStore; + private ITrackStore trackStore = null!; - protected TrackManagerPreviewTrack CurrentTrack; + protected TrackManagerPreviewTrack? CurrentTrack; public PreviewTrackManager(IAdjustableAudioComponent mainTrackAdjustments) { @@ -90,7 +88,7 @@ namespace osu.Game.Audio public class TrackManagerPreviewTrack : PreviewTrack { [Resolved(canBeNull: true)] - public IPreviewTrackOwner Owner { get; private set; } + public IPreviewTrackOwner? Owner { get; private set; } private readonly IBeatmapSetInfo beatmapSetInfo; private readonly ITrackStore trackManager; diff --git a/osu.Game/Audio/SampleInfo.cs b/osu.Game/Audio/SampleInfo.cs index 54b380f23a..19c78f34b2 100644 --- a/osu.Game/Audio/SampleInfo.cs +++ b/osu.Game/Audio/SampleInfo.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Collections; using System.Collections.Generic; @@ -34,7 +32,7 @@ namespace osu.Game.Audio Volume); } - public bool Equals(SampleInfo other) + public bool Equals(SampleInfo? other) => other != null && sampleNames.SequenceEqual(other.sampleNames); public override bool Equals(object obj) From 094793bbe3fdfcdc5769e821a5d19bf3c0d5e843 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 31 Jul 2022 22:01:30 +0800 Subject: [PATCH 195/278] Mark the GetTrack() return type as nullable. --- osu.Game/Audio/PreviewTrack.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Audio/PreviewTrack.cs b/osu.Game/Audio/PreviewTrack.cs index cfedd581e5..7fb92f9f9d 100644 --- a/osu.Game/Audio/PreviewTrack.cs +++ b/osu.Game/Audio/PreviewTrack.cs @@ -24,7 +24,7 @@ namespace osu.Game.Audio /// public event Action? Started; - protected Track Track { get; private set; } + protected Track? Track { get; private set; } private bool hasStarted; @@ -56,7 +56,7 @@ namespace osu.Game.Audio /// public bool IsRunning => Track?.IsRunning ?? false; - private ScheduledDelegate startDelegate; + private ScheduledDelegate? startDelegate; /// /// Starts playing this . @@ -104,6 +104,6 @@ namespace osu.Game.Audio /// /// Retrieves the audio track. /// - protected abstract Track GetTrack(); + protected abstract Track? GetTrack(); } } From 5dd641bc60065e5555a8c50b04387cdd0febe33b Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 31 Jul 2022 22:02:07 +0800 Subject: [PATCH 196/278] Remove the nullable disable annotation in the test project. --- osu.Game.Tests/Audio/SampleInfoEqualityTest.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/osu.Game.Tests/Audio/SampleInfoEqualityTest.cs b/osu.Game.Tests/Audio/SampleInfoEqualityTest.cs index d05eb7994b..149096608f 100644 --- a/osu.Game.Tests/Audio/SampleInfoEqualityTest.cs +++ b/osu.Game.Tests/Audio/SampleInfoEqualityTest.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using NUnit.Framework; using osu.Game.Audio; From db4c6aa3d3aaaa570d6800ec8219a2ac4682e247 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 31 Jul 2022 23:47:48 +0900 Subject: [PATCH 197/278] Add test skin layout json resources --- .../Archives/modified-classic-20220723.osk | Bin 0 -> 32757 bytes .../Archives/modified-default-20220723.osk | Bin 0 -> 1383 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 osu.Game.Tests/Resources/Archives/modified-classic-20220723.osk create mode 100644 osu.Game.Tests/Resources/Archives/modified-default-20220723.osk diff --git a/osu.Game.Tests/Resources/Archives/modified-classic-20220723.osk b/osu.Game.Tests/Resources/Archives/modified-classic-20220723.osk new file mode 100644 index 0000000000000000000000000000000000000000..8e7a1b42df38ea5d2f9a0c325c1fabf3ade153f0 GIT binary patch literal 32757 zcmV)KK)SzBO9KQH0000800;>IRfyT-wTu7&0H*)|00;m80CQ_;ZZ2tVX&uZl4#F@D zK+!#?FdImS?A@5ym|#K-ZtT*C#72pus%K;1NL+!I`9J;d`{O-aMutIC(kaRVf{L*i zOjrS%X-10yQTM zyE`wU`;S7xT4R81R*FMp+PP!1QA-C`d5TWreo#vT1QY-O00;mG2?14X;C7sG0001n z0000D0001UYiVw2Zf0*TYIARHHOxT@!axj0;eAgLvr;H?0JjQK5I5oh!gQvDwtt|L zA|l>h2X*`Sc+ZB2FES_I6I)p~agtIr(ss69v!;H>Z8e7_iQ7`y4I}K1Z|_iC;3}?$ z4%vRAaQaNcbyPqxgk#FGPJT{<#7C_y{Sh~>H&9Ch1QY-O00;mG2?13vP#|?sdH?|D zd;kCr0001RaCu*BZ)a~UGA?j#XMDK@P+UQ`EsVPdcNyH>-4h_e-3Qm;7Cg8O8ax34 z!QCY|gF|qKAPKI)A@7iTzx!_e_18NE#mwpM-Q9byz4qEg^gA_0Of*t77#J8#WhFTc z7#P^AmtPb(;Eh~^(i-rG#6w=sL(|3D!`s}=3Pu|2VqrzC>|}0ZrD0_b_I*EWB?bcn ze`%+s=b@*nB4X*{#9{t2hr`Fo73Sp;lk{;lw{)=bpti8Gv2zxuJ#GI^OKk@hr`6?G zcD900x|_Jj|(moE)9qMSR3*|JfA*KEJ%? zq^15h#lu0I_P-9Lr}~as*2T?=T9AW_-I9xoi&{{a18i<#ZfRk`M$N;;!_CRX$H~pd z&c!9dD=fmtNB!RqEwG&%*jhwGPT{{d1HOsV+Io1nig0pzdwX+u^K!Vj*>G|T3k!2{ z@o@6+umdyL-F=-s%zfCM-Rb^gLC(tE(#_7*!_LK-`sKU1g^Q<$I4$je?%?FAs`@{M zo!$T2Q-IGneau}sxjDEvot!xTGuz!m!^-;qJ= zX$KY&;FlNR73LBU5|CBk=9ZI@7LezW6A}`Xm6w*4;o}ngkAeTa5O~7@2G$D7@X7JY zN%JZw@bPhT%gYM$@(2hCbIZuc^T-R!ax462t+KPbhq<$*)qmF7{ol1b|If7|vTj!9 z9xiTLE-sG$!HTk@qo=!v+skWe9sv$sY9?JfXRwR6JM&8@|NF33ZgyT)UpF+VUFm5fQPVEe;yP{=0wjDT;D3|0HVvy{H%# z=dzfkOqG&i+Fzv>;w`teSMUK=vCbR&kcgAVJuhrAM z?QhjCtTOc_^b}ar+ohqBTmI~SryweW@FC}5o{%u8gLAU7zE|rS!C8E9&~H~Ei`sWw zLZ};A2c9_-cqKC>p5xtz;eGCBh#Q+_Qws>>a1XtTkOCh>Y1X>(2X?%3M!fgrvVjU* zA{bni1hX&-^uvgz2Ay!H3(*SZR!gH&7~AJ4j#^+1 zq%mAB9f3F<{QM;bltn2JPxX@~J)(5zf--FrT}z>raul_K^~zre)CjLRizYyjGEt!r zHd1yErM42g2*1)GN}VAYYJj&s@}I!u1@( zr2I3~RU1#$TM9%Jre8-=XXM!QCJ$KPm1H)^Y5;ieE*vRU(qPRkNj}E9eMk9_b%#3E zgU(mcRk3h&e3T{Vs_=1IWeMZK=t6}8)ZbYBi?*bm*a`xy)O!AHl_qIHLgIdBM`nBh zPL)sALwFfML1qeSAo6XVp`X-hgnqjY3r7fUXDVRB>*)-xrPxhu>hrz^4#8n1q7Uk) z#V8-!!l^X?h5FOXc%@1%xerj{Y5`G?>guwz1cU}K4aEf18c4=|43wQ`WmSh48plb}q<{Q2dUIJTl| z&5jpCz8Ef*h^Jm{JDJJyJPW!~`k>JET!^@`j&SxPchrRxD5zd=h%FL3uNI*$1%eP;=q>@8}=3*bkO9~M zGPL%64#@C$CiRg!u3?R1XU#c7EHe{%gcf)8xb`bz#dB1XP>Dd>PU|9fgfwC4KQk8% zxlk%Aq-88NPRc~!aMn9(CUr{x)}Z6BxI-j)O2?3Le;7kYKLiG;LxsZ=a2h^ zkxSJ;p6B5CEeKC2qN(V#^i3X?s_>PTK%Y}D!}7V09BaqSf1xhD|2kDB)53#ilyeaz z_e?Ce>}=?vTTkL%+KxVa^j%{Kqkfo{h;@OH|3i<^r^;h|AboX^9&pMf3%-t8!)#fN zSVvipTH{J{wOJ%|!%)Jjr=pH6a% zR6js_#yG5CpWqQ4h2lR=?JmgggiQLA-Vdp=Avb+k;m*>0`o>2Ljo2yC5lNWaqMR^O z?gem5wZ`}a5nX?Z?k&U3QwsGd*N8ZL8HfQcIN~=H2-B&uAwzCrp#Uy|L~=PTX}1^L z@D(Q>N=u?Pz5itMN?_VLU0&p0K$w+9N2sRtV7Vh5BS@?ujw&DfX(cMHpf7o*Hv^X~ z#h$6cg)7Ks$Q@<`hFGtlIo2s9&!xVkjC0#KYODqhD1yT;yz$Fp?bNWp*hJv4Ccg0t z{go5i4Td2g+=LEZYyC1EZx8-MDw2g6f44dio+0)s8sShnGD6RMX>LcQ zRLKJNdaW$AOM4!3fiNhoevEDj7;+-B4mjZM7en%nMT%tI9Dy_|%mpQsCfi&@AIvwx z6bs5Jb)~`T5kGYx+D){*=S2bt&!c~vdw%2(B0I40md-1xj3A%w`F3xU17{UyfU$R8PQ=A#1jI{+qn3@Myki zYhk6NBAJ(@{Dlc5Wz--U4v>KlBuD6Bi#zRasS5ekU`g z;UO%7A#xq>q;@EJ#Idv40jq4zMaQ#lZ?3bkHRZa5$SC^BsD|yld}Zu*7`;DQpvn1ClMB+!i_fR zk`YNwh1~E3odEs{r-cRdi%?ksN?9?Fg|r8;1?1;Me*pr!cH}wy3hE!O3KXgD2t5?+ z?n=Mm_9j?@;x>g@3=;kkv3sgKTIkak?4GrnMu0~f9(gfdDo{Ex2vIuK>S6TdM9W%^ z(Qklo@2mbJJYR1d{UTj_r++YkThXTnij>?81&)*FFfX!xk!<>ZjhHO2&l`~g#yeV( zTX#x5-!o7ofcB}atL8G5`Zb?^@^`BB4!+P)LW8loSWzyfERi^HwfDa$0n$_kL+p3` zj(5aqMk&=(k2B!pU4MOiK~`ozhOMmuth&?SC`;^B7JD`zPrp`%Q!Ys|%?!G}1}1KwQtP`*POgfXxUxSBVs zkri z-XN?6F8IW@yaLFD0{z*e)NyL3$V@AUn!3jlwQ$&G6`3Yf^`%TCqB7yV;= zf9JT>okUyP;!P%?jwxF~UgSj6BTHzzxZMl?9d)Z80Tt0xp4H^j%Y1Ppb!hD!Kdoq1 z^qAUG961&qLVaVdjO!%4(XHb4 z;pB0P7jdTbjWE7$m{y+!p0>phWyw8N(gL_LYqIx?ynN3_s1LejLI1}mF%vcSbXi}8 zF-K^X*(|=k+<{FcT>F_=9=L(La6E7W0FEjwG04>Gc#P#JCk9C9K>mD;Jq0*cxd~*r z>(>*Ic8I&`UJNKeIaaXGzYyr40a_{<4EutcV#FALI%F9Bt-!`37Q=G1a!WG1rikCH zVr~HF+(0@T*oLQ>lR>uu|5EoQZag@$0L^Euarh>OAxOgC(AFu{{~NHE1}=%oKBVoW zrVnzMByV)yB{cFJI_*fs`6R=NEQlIY0=4 zJ{&v&e*NKvmf6n#4{K989Ik-Bi|U|yar%V&d^T=KJ>oN~wZl}(8SsvQ@zyRE6CAO8 zyY!PFLpB*J$lmHc%1Nd!&2~dAJ3bICl0*8*B4$os4SjGFAWpM2Uk*gG>6RSKD$S(O zWLhJj6cu@)$oG(PGfO{7tLl$%jlX1Mogyy+%`I*z_NJ*$K`^C9DeluixM|?Ud^Na7 zpacZ0A=FH|B13Hdna7Z-%LmlU6w7B0@WRa;tU)?}>xe=A>@T0{48T(YbuVv`r_opj$9I!Ua={R+`j=4adiDYVk{!*PsYx5;-3EGwVH`sJBDQuF`dEBG z85!lh`GsP^D$hJEB3*-T79H8=uCy|Zme^6gY^v@dLS9fD4=>4vq9I1f%<}pZb4n&c zjDm&&1|7}dHVycMfxqb>(X40_3GgNw@4Bkg;>Zs17*lNAP$AGEM6vx~d+8H0ro9+t z&E#cUeZ=B^eX~V;vp!51wfNPb$WK0&9K@wnb@NFMaNYBdoDrVFM@W3r=PygqWRMhX z!Z-o*(^xrLHI7UNN(9>2tG(=wa!*{qA`i+-U~Ap!%ubqGca))`mW@iGpu1Fg5%RJy zY1g+Oxd2&E8;3z^F#To;qjEOpdW)BgoZdZ2ey`H)!|PK<>K0B4tQQ;m$>U}afC`p4 zd}Y}1Vg`CukWm2=+Y9RmB0!>Pnb}JEG|{4sNGyx3z{h8pa`QRY&ooId{HvR|aQ7%Y z58J^L&Z;RX)^P(x`3uzg8gn>&v&Ibvw$&NnGKlm+j~W>u=Bo^VgIIz9HjHR;bm;Cf zJN~dW0<_WYYy!kO}z31d#qYt_Igv?|(u@!8hMpK)4q*&wb@c{H1*y>2q zzwg|+6-l@(har^R80uKmyY`3^415L>D&AC}uPs9?!;()}iK~Ro?T?`uBKpbLG}Vjc zI>u9-&Yjk>UFz5!1Jj<`vh}xY92}fuX}>(uljaJSdbjlJOs1!%>R{~~131DgU4{Df z*uZre(W2yV`_Ej zAqvgbHs>bGey=FcaY`BtF^PKc1f8BKR^3BD9cFfmujOTBSrdgNpT zQUAQY+kW$xlY^QMc;Hnw>>=eNRDe>Pnwq+hStn5U*#81&(2gPzDoRR9nq_`#Qp98; z9=z~{$stu#&Q(!XR+blQ9Z`CYY0oW3sz`2v|4$&G>w!lh`DUQ~yrO6gqVpWJnGg{X zkuC`DVO>=%6%gic_eT-I`(?-aByWw@ysrje>pQxCTNnfmxBJnK%*IV+?|Pd4o75nd z=?J(zu)WU)FtxytN5SzaC61U;LM)hQ~ht>pCdgeT13=ya#w;EgM@2Kk6H1b_At5=&V^27h~o60D|p8MWx$zkhGOMf?eQ!tuAU(vM8l zbBgAnXFLRwt{=LwDs`Uz>7hN!h9^{d+#I^h@Lh~4(XKx8j_hz#Q;r9AvmeSD(~zHb zw$40gA)5=QKe!CwtEB=n=+=f{ma!z>u`Q(s3v@_onp>VrTl zL`v%N;~;9F_o}V981oH>uZVf`!Qw-24xQXiGFF5E;0%UxLKl0u1+IbJk&+(RSL&G*u$`RiO*lY?8aHh!zf@7WBv^d-xnB@Dk_tVF>puS zq$`{@qs4u7BuHMs#EqfIMi@6_36SU11>7l&0*vxr zCUYokD+wfc=!!srCFjN05CHKW5!_b!h-Zv}v9KzZ#!U;05vu^NWk9!RD`bn`CqQ0P z_HHpDB7K8B2gc0ev))c}$&kY82lZ#@=bKoLJQI{_QY@lF*Kk1nf7#9Lc%?3zx(}YC zkBKpcK7>9(LN*m>P4}OUGz}w0s7N$icF6f#LB!!UpjW7W5<#`{p?}@FZ|ADr0<7Sk zs8+ufqwUY$setpw3%>rcKO=@|Yc*k(l|_sY3&D%P&w++yE{3X6U!JHL*^~ z%&wcSc%DTwS(lhv30Z_;Ize3vQM$iT=P7=)T6*DlO%PLD17}J@T`@+a4)O z7w=x{NqSFLPk@O~Y$nvPp8Vs-NK6drEem^P@LvxR@jA8=quMY9kvBo|_Ba&G#rdD7 za8Sl3##GeQ5`Z6-w~2^w?zMVjO!JykS7Kje{Kz9naXQM%3JNTY<>lE`Sc6knjuCV4 z5R`Fr^2h04l|765YO#@HA%?jJJJi@QGMaYhUtaRo_%l!a`q8=Wh{TBwucy0E=X;rV ze~)QWotXFb2TcJ!B@+#XyvynKP@)Um$S)N0OktrU?_|sAtQ_?|?_jgF6yBOf^C!pE z7XR(RiGu?qGyj^5jBr0JJlAmZQAvNVo27cuknWBGCY6tswto~MrOq*aN)h|=GUaX}rdDL0ROlS5T1y^TVTUBkX z=UUtS&!2dD6*Z~Dx*9H#*x5bOyzgP8r0z{RejgwD!%1NuQA!A~A&yP_k`dTK7t-?d z6hG>Wh!Bus()Z#R9tL@u+Oe22R-irdZHkWVZEjv>0?nVQQJn=C35xY8@Mux6WBrFM zU(WdF9-MBWu#|_Z8PoVg?B1IkFM%Tm7|{r0R4&B>n!UEx-@=&P_f^J<=5ER=HBCKT zNLeW7;~&vady=g4dqX#N-R>5(XtvH)M*>nCdngoo_OGnc?`N*iG2UxyJGr|9rH;3M zKU{w(`f>WxwrAR(?&nBs__*rtfAw`2)*z5Tl$+a+&0b#*xU#uE5D*+17&bRGIEJ`% z%f5Q16g*-;->NBdiP*%53ea8X3<;?+bET9(jsIH_dbHAXEa`VeHmh%c-&|MG-5zwi z^)@mh@3Pz5uL`Qe&O?YEDN`@Z!&nv{_-D?=d8v*F>9wZ1g2vS#Ki3(?Ao9=bqcd@4 z6f|LF>*^u_Yy@(V zW7VolmCVd7+*}R&ywqU# ztLwwi%1X0ur$p$V^A1zZVmpgl)BNg=Mo;tr;oOtVOy$iF*MyckJQkpS$nuIerSJt| zKa_xgpDSKUPi0DzUU|mPxw*NvwzKntqMhBquGCVzxhDIk% z{F~WXTc(`_d3Fafcs=B(qu-0Z0D40dd^_pE0+!b8RWfc*+>67FjpJu_Z{D!>n8T0E zXzJGszq!5ak9N`3p6j(9cETLmQr*G?PT`KCLmqx9LtG@xMy*JP8u9RM_EKA`Le%#{ z6k|M5C*iH?xL?$?omd9Vv%AO#72VeDb5>S}<^%`;l0=aC(f2 zf7MfT@eAZk(sNZ+kJ;G`H(jWqh;sGs4$@Pm=`_y*synYMb43$<#0KQt^0@vw_L_WT z$7G}Y{n+2H#AVA7iJ4u{=y{kYUM*iJVssZm^5vFaT)gU`;3GGD0BFa!J~$kOq!)u1 zC5TcIE3cYEaWdnzi84@rCiB*eeO;W-1>uzGPob_3%rM!sYd`8hEhQ0sjY8x*c&{6p zyu`cj_r`O>D;3$bm=Z!mM|WWZs;f6PZzkbl1!?wqxv&clE)&S_?w_ArQd3jIn(MXB zsXPT>_en_wVB&gjwzp;F!d&nobHzMTn0L(K=BPIbdEMZkKZN z##N<4C8R`%67{A`kn0s;-$O7vf-0R}UG>|eOI1Gq_8{bqR}mx6n>=$%NATt$@1noN z^=virzb0R5ztMJ0o)7(#_N8-D7prLUkez~z3Q>Vk@95)%WwL~d;@%ZXLZGSMb(AfymQ7S5 z!>kv{NDUGx{N11KF@1G=e>Z4v5+r+ijhj%rv$w&5B`XxN?n2))cZZ>pAVFGBJg2ixK*U^dWgCjxKux zHi%sE`S{>KWQ`~fGz>(P9#M^)6Inc_z$bGj5m&>Jdd6QLYjq9{4=kjG1t(^^P$m0t z^Bw6CiX>GNXWnW=DTRDjDXH9Q_<5mC=K&<>UL+_g1q z=>Dk2_Y;`qiKgnltvi0x5x=oqj7S7?HD%?y=|Y?3<)$C#zpwj5{l@FQn9CX)k3yl{ zkB@Q2ntU*aINnsk7xP^oO3eNozF|>K`&wF2VQ04_A}Gku&7G5hkE!fS!NkF_AU>!{ zZxiF^pMR$Jt%gF+3i2bXPU%zD#f3cz$sbiHoB4@`=>{N^s(+m1>?F=3dTT#3jZ&hl zFH~=w9h93^fBS}%+U#8nmu{@AjMzV2U#|&3_WIT9AN4acB|*)VPNFnNsD_i)tNR{3 z*}XTivTNXK(u{&H1Fu6`0To6W5CyU!rQzF3%GqLyEo%I%EK{7P2^airEnh_~fej0t z5$NzZol7fef(v5@Xbqc=0*@P;SDmYmA>xQZxFs`BgJc^Uoe$b>Mvhds@RDm&Q_t}( zk1fT;%;Z?hjqy)BE|}Clo89}b7}sfZi!BwNufJ-m`6f9;m0?rdlL~RI!q7U8ko5ES;f$nkN-P_m#E-J%GcB1t3N=&`k+U<{Jh4`OUS2g=3ZqSp zPSfj2ea&ZEwh)UDXz0Lpg1C8MU<5vZUkJK!us+dZJ3_{ z`qovvX)7xyWT;+X8p-RoerD2A#~nd((w5Mzlqp)o9lp47Js#reGjh>uv#)2co- zyX*-SE2COKdt;i5#uy9I*jGTLRaCT<{KDPuwD|gnQ3-cF!a9UaDVAGxDjhOzy?Xcu z_9GSf5iOoF53({kw>dLO++;DXd@`bBTIEtE15eQW+X@W z@`0Y7po3Qnh7~~n_BN-_sQn$i4KxaoxYv6*(xn#DjfG}=n_M(h@U@q>q>@!+j^lW> zWi1y3#UV;xWqj4nQUztb*?CQ|jHQr$`xLW=&)<&{kGmT23bL8k?6~B8^;=L0*Guj? z~~2h_hhy(iIBJ@hkkAf zVP`EDdjC_jfXR)4#NKi)mS}^Dj0^`MTJw+MVTfo=$9T4>aKNoLl2Zw@F z)-KkA-e)s&bAL+S{;dKre+&q1v*y#$*WdOcO0kX8m8N;U{%fyTsg(?QVdS=9Zw#um zF*X+7HH3Mc@>PBm8H`T@u#G!HIJBi%1L9-piDrhG)w+9CX zCP7c_tqY@^2o8>pWMpJHd6c}2UGR*a?VZ5Bfy&Ch(q)v53YMx;Gf2qox8n?(N3*k^ zMtALOZFh5XARrPk9o+@v4}G`>>>Bv|y0Hk3fXrI}a>!>i#VjerGgtJ+eX}%_S}1n_ zIs8 zG~U0U>9b`OJ|WEgM6M#BKR?IuKZL{k{I(ogzrGu}gOJ@4e0jI|bD;ienQ=j|fM~wk za{oDV!UtNkObU6d>B37-Y6j8c%N0rc#6{mH*|E+HuM&aKIZ4n z4ij}Q_i$zm+EWTI0_=7Xv!Osa_wss|6Ch;=L12kzJyobwcz^qSA%8bTO=(-(R)4g2 zj0Q4;HCN;2-_V|l=pqif02h%zG;w;y#+PTVr>m=}Br)In1S0gVW=l_rh%&MmJNNWH ziFpd_$Nkt>)t==^Yp%lncuSeq*Pa-6MV6Ao%vv69`o-IAP&zxmf;m=&9y~#ulGN&R zZhC*8H&Q24cRV;urHXb^L|MAMGkltwRypb-@1mW^^17RUGd4Vs8-*^k$M?Hwr|i+q zWJDj$vML-Q+8EX2Cu$`GisU;AsavkyT|jTPTS`^rVmfU!pQfVX@z_^`MY3yVV9+-& zVQi7$xW4d$1>n1DloB-~MGouW>feqi5$t}Daj?(2f5`7u-1SI>i$z%f;FZo|(<1ti zmGy_yFCQdG_BP-GZANm=H7ERvoftF^dNa|AOJqSGxyMS6gQ zAN)~`<&Z<}9GpW@YE>rSfCxfd&HqGvvhRx^iDZTrV)NmHgXYZO!2#0kTaC^iwyJ_` zrZ6{od6Al$zM2ZXEj`ui-~Zy{m~T6r%#_u@(5Ivn!o$CPcxY!}G(`vt%sMt!`o^x@ z3ySJ#>6z^Q{O3lpFbP>*4CmM0UOdn+X|-4dxS{5}bHCiXzRpdg+CX>>-EW2&>Ii(& z+|=IPoih@oemA|m{HJCd_SpkO1rn!t?OmV0ip6?*BqoP;e69-Zu0uBA=jTUrLC!~j z!iEjP&NIlRw6?p~7g?FDkV`x=P#5-Ws$HSJ%3JRa+$3XAqdz?=rKY#LMEpp#} zWnr;57qF}){_dcP!;#{kD(Y)fAVhCt`_pPJMVsyw&)OO~D#<4%GvdKfDplkYP`HaY zphX~KQEpDbe?+}GawPwr%#<{5`Qt%HOSk#Qu|bQU88%>d0Y3Hi-oXC&*d3u^JdP3S zb8DQI#&2mECS{EIji=?JxqWSYd+0mn&H_~Pz3Y#fKtNr6cz%@J==4Xe347<0S;@Wi z)3KLo%M~Z!y58m{7!uNlM2bQ-&lQPj`TH`hmlAfc`;S42`3Q*~v6gV*;c(J26pn#B z)Rl)nq2MFj@2!M{V>y~WaT?hwwx`fleq6ghL$ky2^R7;Lj^u{HqAG*6mM$4-+GI#4 zAjh{70Y1AkZ-WqLF#~>Z=Sc<-H!H)!CY7aIz}ngr6?T1fd}k{m))M|+CAMGc zvmg!P9sW1mKXCXhW=G3@ece=*d^pm*IWb0xM5|W@bKQ3cIjY}c)@&#!BIk>@AKpy% zIJ!BV*0_bikX~Pjp?wS$bBIyj9aE@Yu!(b1xXI!z5^Hg{ld&F7qwnGeN6GAc@S$7W zle^y!A7Mr5lWaGd0`rell+xU|=S5DvIO3J1M4cINh8dhc~tG zazo*Qja^O)zkH$mdVx~kQ zepl>LwD9i|%Vu3Rx?u2K{QTgG`-4aC@qYrEBKWFjXKt>so0Ff~6xPMS$Veuz^!*M+ z=!S87LSuuYK)1H0Bxb;MA9j#{&?4f)NH976$6Hq+1lWzEBdre~&_8#;z9AyS2yg1f zllcPkUH(lnFC7wt&Ag}Q+Ki~MEcygWH|fes^T}duzPAjL0IAAItGnb|dT_Gb^S7E| zs#nobCUs1;Wo6L~BC)%>NXRPP_kWJ1Rxp*I-FwJ*m^Fci^S;UP{94K~HWUQ{W;5~e zPIBDCL>pUo^z^&i+kLNIamEdI^toL5y-A>aLi+1ZD}N=k6i=4_;e0?6egm|X(bv7C z6(rst1P^a~IM1J+s&!`4&6Vfe%t#n}&T;DK>c&8sc=#bb3FPvHC%aH_vRmMnYLVHo zafeS+^(nV16s7@ZdE#d}E$;UOA-41k!6fI=J6yVyup{2hZr@W(V(%zH$=gk;;0KtR zz1>i3`VWBo1yD>zDv%@^5@W_2)z|OjKIP}{ANm{UE*xE+AE!%&6Yc_yX?^`FIv&hbw~S=KExRkD zQ7c|+2L9jMZBsE{H?lz8K+d1ZtS*p~6XbybE2*v4pQ1FU1Dk3Q5x4UvCBr0%Lx!d< za&8f;rSqD?viLlrUdJLM4@yB+G732O`qw-laIi@VsktAA^%vVO)@+V=!<(b?HS(e& zUU-d?3nvXDS69T;fV}=xeDFD^FRJur<8OO(v^n0$`*3(=4G|G966$fJ7@(P(5JjO= zx5j9Cg`+3s#XH78@FU=UUsB?OU+j${9Lv-?mf_&A=pmxm)pFxopsG)aUWpZUqSWL} zsI3JPrz_go&2@cXM0NTp{u(b1PpCJwdi?9X<-5P*b-zWxOHQsbgNJ_r@b4KYASrB| z=0BbF<-@uELMz0`9y-mBz(&f+I(&v5b8=qaxlB7B^wyKvL5mCfRsHUiD&YC9I$ts< z=?29yb2LN}AgBd#@x;3|I{Nz3`R9sqhY%N`?+_fcJ5J;KV3Qwv@u#`DiqJRmZVChh zOxWZ;@NmrV_&i)|*iI%z`1{R->YxRU6Q3qY#;qnVKF=|oF7<8vKA^^NnQ?-&s zdpZc29@F1S+zp+dn`_eeqiqnNFi1S#5*5+#ROg@`cdX9N_VC}Kr0D7BXq#^IUN(Qz z_{pj(;diltoC8p65Up;!PrQJ+ypxGbDQu}gve&JTg++hx4h9$e=4mU)MoFgF;_tJj0zFtF zFDC%<8Vcj&J=4&xLma0NHVh&PZO2~?=@`YBV_y1QG^wj&xH87+0mtTZe|7!zkf9QL zG#eZ);pahdiz_(>C-kkIH_L$7z+|Ly8cuL}xp;y-ufoGfL;TY;V?TclSgBCPu zZ{+pTYvKO(?YHgKG3DtjZx<1SRPu|8qQ?H%!WoZ4jLp9uNlPp)RuDd?Gn?Vah|IqT z*#qC&!P=#GNO{4K^77H>yZ;JnJ~?PBXX;4i<)T(q&5m=^odC2~1icLw#Xac}T*NIW z9=8Y$ylra~d)<+BnW>iCgt{+e-%2PC~VsuFfj8&TqrajPSP?XIq{cjeYuHSk3DEK1U=t_Z%Z!3?C<_ zlp#$=72_r?H|yDkVUoUAJX(sNuXvO(K>Ira?cc`Lpa>?yLSvOBTdz~{ORO!n7H2GA z9CZu&TVL|_R1X22@VANgO;}!@V$Q@*vv1|)hr(;Z2>I%!-$POau+QE*JKxV&a*oXq z3uM1@^z%EK$c@dJ;-Y+uPn4mfGk-B!U#T)-)DjK~0=2S~3ovFiD3qf%Xkaz>yNDmyTV5!rsa%_r#aWV6(ZbEWrqU zM>=)q;f8a3Ld}2{#juwv6@b5*YW&%`vOOohlvE$f=*-Soq2fZk>I8Uz2%7d)4Zcm7 zLmA2@(n`LY7!ccqQr?EI!JU@E#>0&Aqs{Yh81n*z%=Yg7VNT~Y!>mMAv;`gAlejoG z^~EOd5v|;twm#TWoVu!(PqF0@PQ1Ll=eOso8WF>vNvoettQ~z9o^1Ma3P`JGp1`!UabHw8Hfcx;n!oSxM)27s*LqE)+wen=X?jt1wUa zPUytTuhweq@weT4g$ZsyPKt?$aEYysXB)ZFpZ4{2ib+U*gwGf)JY^=Ym_0ZUp`5^P zQsolbnDex$6>Hvw`crc)%y}jvxAcM9)&}V5(-Z{uRhez#-b{cQFd<4UogZwvfR=E> z>T;N>9@d+(PKlUE9S1*gXf*nLH+i>7j6z}hXcOm0v(NrHpF}Z4nYGiWPBZOmYwGIk zDRJN_oy|Tw`1$o3EL~eUZr@!#K$Mhj-0_n|(^y#MNmi%Q1cC+Fgk@8Cw>(6@78N~q zhiFECz&m7u5{6kxG(mO>ca}PvYDOuatJyTt=N?lhbziqR96b7^{sx*C{+4&5*mBwV z`E$ndiisMp->`ZjdZ$VHb<&IR`JRO+N6Mg+NzrUl%UR~kgMED)dtBte?d};IAI!Ae z_Vk>bX3B;$!8~0-f0^^EdxPz_!ot=j^Tds^l5pkalgF5X#_(2&z>wfGzfI8=w9IeP zbF>X&>4=U+wY5DmO{lIs;>`o)J!-=YhCK* z(@6o-MyosGdTNeznVr4frIfEKYtSsr39~*p0nuhQIb}yrge)8#Q60Wz1~bRK zQ3*Cr>J582@)(C8va4YIxQZZln8eM>uEZQQ^Kjw2o+GaOVF7DQ zB4|m4C1@7uB({J`rw#edR2oYJ>L$mfZKoVZ>D!Mof&SgnAUxVglW@qMx2Z+cu zBWuo_i9&4nXcxpG9mH{yJ3CP)2t*1LX9>23m+s|ZMh+r^{QMK5r&RF@q@)5zi|?86 z(UQW)$dDMp=~XJlE4hQiRE?pcyC^t`T<@^8pOp$efu}<|G#H3tJ-zF(y5Yz`tED}$ zQuw_z?C_UNDGW}i#(7AGc}0jV{pK|(m`v~N@ z$#WJL`{puJg78AQDA0MkulJ@WU!jNwi*SMb)Ljx<-+wanJ?+{ zxEQsA@ot~jCh&WuQ~Nn;Cbh^_0X9z}@NlWZ@`UzB=BWqgOUipmn3|B(dW`otXF8fMTz1 zd7`uldr;7qIn61yqF}@BVVSl~G6?M}fxv}AW4Q4OLWs1!-|G}zKt^4UApkPEz1Pcs zT78VeA_HU;33Ct_!8_S<+=TEh?eYCm*KQ3Ad9>UQ0d+C{sGrI-=()MnacKz{u^WLC zUo(oCZFnd4rJxuY9ZGI{&)Y+Ss_Q>~Y=)~$hdy$ra{ee~mz4oS^tEFV{M2?6S^rW= za3=HBg(kyVmt4XNBv@yAZ@m^)k+B69)2Y#OVe%>`pRRY7>B=y0UMPCGzGc2!0D8|h z!~zI%|MfeaPfjz|6gZoX)&+7+f>}8<#<3KHn4j%r_NEJ0M3}K=+ev+kjxjd#;@Og~ z;k?P9;wf@tbSu%vz0Nf8U(osbYmKVY__seeV>*uWWCQ7d-q>s;BE99RG!%{@7M4@E z_X>hgJjtGvG6%lT-4|H&@2jS}lgJJhW&b)lg={wdp4R4uP$&l`xMmvmHIHYf?B72m zv6;VJ;fROl%70l~S7hYSpk}hRF@P`Vf{cvZ3cjK2NW?b1m8#wzkI#>`7RXf-q#Cz{6f6AbP{kj(yCbno<-O;Lets^wIW?U= zloCq37?PJ{9i^lp{li-+teBOeUFoL0Hg?F)UI!r{a`&Z(`su61G)sXgPMPm?;TSCk zXA+sJF#X|kOz&1wDZ{I?+VauY!z57xw2;lOZ>YliF54=aA4jM(Aq9Rr%u{F556-&P zbd^l?QvM;MgC&Y)IohJ8}>sgm=%H|HOdoZWzA$7oj} zv!+9e`PUOk9B=Xy<1u4ch>_gaNwK!eC94+q3fRj16+b)W6MLz@CS+#wWwPW}G2Vo^ zP88n^)_I^~Px_$OpnAm0)J8?e9N!Gv?VE0NWEMdpn?+j5nYix-9Q@u$as(|wyw{HTEvis&P zUUEDKCSt5ZySK^(@#{psb9x;rMdb=AV-R7?Pk&#E$Z@L0w- zTkO1@^+j(qtYe`39s@MzpEBH-+BuECg{Ce+g9{A}&I4O=X#9HBst;d?K%JCTI**H4 zxq2#j!?1^o<0cu@?)QTbyn=-TV*5GTV40MKTv}F_y8H%|R_wKWoE~mz6jF?AaO?H3 zHMWlwhxcz4@-A*y^o@kiV7Z1v0n3oroOruhCf=798A6W9j1(X2D4Q~`R<&s|Jdoc` zG7b!`2l%6WKM00;+5*-(P)Q6BenfB*!Xwh`9RIHDfN+s<@AcFo_)_2@_4UPS92T7K%XKyv$sbRWtwZbnV2?% z7Q>I*6~VxOLMAu7H6Vof)i_K`D_&R`l&Wqf?MdbTu$=q9Sl==pqQZN)3m$LdZ=^F* z5y{AKMqJLvW6ZFzRsW4E>$eem=Jv+r8APphTtQS9hP5W9AEPUx zA}zziLMRaJ2$T%C8rHk(H5>dY!&uuY=@`Sv<5ob)BjNjEkZR}4k@>gRG{>GTzQ_}{ zfRUYBdnL7b;48S?l6$l1C6h&QvVW(oH=&5Hn95n3=;agm$md0J%y64lpbm)&53T-t z()aCP7;dQ8_TAmR)t2-bnn=ql(Oqg#g%Yevfu|dz<2>zZk`pPSHHSt+P|gf#yb)I|zB__KSVh+2>ytKYKmh)AVMYJI)WD z0C@6k7mRpxKv=wExFrW`7#EN+C8geTFyL#rvC*X7Sl5=>1phWadN|z+TrP4;m;G0;-DI_+wS1Fn=(rjX7%%aPQxUB}1q*GYP9EmAd}Z1V+R zAq~^^T)wL5DQY>j*RW0_hII-VZW-g1;RiXN|CxxcTxZl4UyOZK_nwAfCImsg1?6&2nWC+$k+fV>Q4S4LP#=Y+T7?XZr5`N@z|Dk& z*e-!pf_JUl6vPo|OPZ`aBDWk*|q1O`)!mXKyVnz*}ECwnN!`mCzagQr7t!5Y1n{_UAl zEGHtK=Icj=^?79>A(6zd#0U}0$w6z12Jxuy(SLE;+plM$pQtM$yTt1?HF@k;y!+_V zG5>&s9UB542u$xNQxBUL8OJe9Ghum-y>m7Ae?|b7F3|3Bv#u5(o2f z(ldtPHh^3X8|5S{{q1VObgbg<-0M5L5{Z9aXO4-%UA<-(q7FAK_I&r-i7a5q#&v<( z<#i=sZT&YQ8D$qdbYE^r39JbfP1KsSpXx&o)k7fB+<@eKW90n&3m(*}9jyM*)zYFI z6!bJeHycd;{aqh!MJelY!t66aId8f1@uS*qqPZd7quU+Vs>t|e0Wf>jEh<|?+S(1@ zTt>}mRjzD>-vqG6&CaBFei|9W zmEJjjmy_yiCpE!H3N2Ei4|FE@=1i!crBkgjo72YcS6{W~H>j1EKXnETHC1T{CHlPa zrQq_p27M}m$XlCXQ)bZc^kZRxcorQbCWj{R^Zh*+g9?i$2#-dvcmhzT*SFR@si(Gv z_1mH4UXZe`cRCl>r8FvrR+#HtU?0Y{CD@;+@6plI|8h1I!fB>$>NKGnEIt>|;<9&%P3_X=o%UyWZv6V{sk;j!#R(xfF(&iu;z#2uK$%8)E%sA@ zyemE6Byc}_JQ&Xn@8Al1kUB+B`GE~9yDpw!2ou_(N+s0-Xwe`-V+u-;$ok)1kCgGVmCXKkN{EwwDeEt>e@T zP!LD0J6I@6i~LeHlP7;g;V+ed!C~xHS-Ofx!%LWU@asv7KZbGcp-`KuIGen4r3-J( z2U!qfS*T1nQc5zetL`vR*OuIVoU~5HkN83#kbVdJYz9Brg%g@UejPccMiJR)_1G?- z7Q{fNo0q1mZSRGfyXyJ*@k+laHQBRkV!}WgT<+LP5e`WufBa|1JgBBEEOGMpDyBXe zo`W3&GHVW%ThL@W(W7lK3aJcwai(FLqd;nfYD$6h#0~P5F;4DwufWqTCrW%xn~Q}9H`_c`jJC8$m^T{rrZ$U%GsOsrQs?M*ecA^>q-C2+(@fz zQCPC}<@Q;bruJU4AL9P8h(QiS!yaotaOp9Wp-$E3^i6xhetus%#HafX{7@J-OiMum zPT|l5tgDmS+eowzK)dVbLP5bJIYqg*VLIvPQNcEACx-*T#~l#6&-XEBzS*SX52vuy zs7VYlCW&|qR3i>zy?p}&H~vT93x?6qyz(R@IAor zyy7nn@02K-Lqz%1sj4UAdatc!c*Ltvp+svd_c`=k@n_bx6~7|m5cn(ca9&*eOA+CZ z^qsFxa3Wg*v3?j)?ZZDCbtPA~a%XHgKNTA&-`if|`M3spvM=1Ig zALg`jI-{-O84``YII~{ZZ?`p#bDg~7Qqibv*Nx`!9IW+YMk}htP@xCA8w3yy1y@RJ zR=WX((K5Dp$HU>f69?U`y?pm_0G9z*p~d)BrsolD5X$0xxUVb2P@dqO$;Hhtde_$) zv=)4xKOejZdKs!%yrJv$!+Fud&%?zfmO#RNt%->uYmlw3L`B46Y_s5`5e-!b;d_5@ z;XOTwp7?d8O$Xw-=I4{c!bX~!!dqSY#{(1Gxmb`iM&7c%+(AJS)=H!a3=VnnizOi; z>-1vdaHxB8QDbTCU5*f{c0*1zncSysw(Pi>gU~2rr zq)B->;N#s~xk;(tV|Ae!D?8Vmb2wRyw5L`rvIi^Zt78MLnM6b$BMJ^XWtJr1grN}!&>wUeXi2p{z4L{5FxTV}Vh-HA0(-uH^@6HE;^f_e%f?V+z6cQZ>_X<5 zd7}_3?Z+nsaP8_@kdzM)Mr9Z$uwXF~(iQ~k-yX#o((jWP!=)3zI}wJ>=#|0Hq;+Y- zml@t*T^-d(L~gBM5}8&O&xO&D`DcA4UvK;%OFk*P(69byf~c8fkFH)^S=?vLi*QSV zT1LY9i7DMxj4r&xVb)em6muM}p_o*r;d>!5G>X{hCNWuzCf@k&+O7%px>A>*+%Ui{ z-J?xP8}k6qCW^Q|4!ud;OUE=`twEY`ZZB?wboxxs=7N(4njTx7c0_+v9%qKIkULdM z&JR>hT!4{WC}D7;eZ(9sSnyPXAFPe`d-%8RMR~s6y84BSPnzsdS?W&&2&jmm3Lvo8 zI8w0Q07d~CwunFo>27`$3YT>2j!r_b{Mxtt{6Yf|8jF*sr%|)T1lF*`^q`eH-A`Cx zCNpnCzH+#|%Z^VF>0<$*F(T@*IfKpegw_5OA{ZKc?8~(#`xE;P7?)cg_5F!H@*f;o zXkXzcd)w;m7vufnY}HswQ>ln)adARWv8<#uVApp0T^XULsNh5fStFqg_X{qD#$Ya( z4N9Y;=pm4Kc)rXwD@@x*togdZN{ko&aD0w0!U!n3+!Fbtr&SM;|?BY zOz=AttFSB@Ortz##!%I6%$lMsgpSDCO#mh6KBERs9;4x2BVnb6LsXb{v>_o4{uOW= z|I2RkR%k#@Mk6m99L}aPG(LHK4f=7g9I8VM_@-%$V>6;3i>`pK~xD3L3|x6B|+M z0#d)m!cUV1*Uq3)b@lB#Qw;eYgZENg_b$ktvg}iLGTQLwp`OUiP+nOqVP!+4bJr=; zKP^H!@??&Eli2NM@nm<*GUgrv6Kv~?26ykPZ-S1G)tkKXNt`i7G&W8`1k_7G^9mu{ zJ3@Wdp5RXNVrV4asY-^*%T6Oul9Y^#6wQ}69%YG7rOS1up@_$G>Nqp%`VGrJtN3SU z*8R#PfJ&rAW&B5GafE{U%H6etgN3E}iE0ZXW##s7_3+yb-kSZ|pI85n5OBQML}T=y zB+)D|<9%UA(#}&+ZPI0rpt4nQu3|{*_AVC#$1=p?Pc9YY>C9nz3LS08K zC=T}ayyud^=}@zV;|$trU_{~GHMv~nw<;edf50$FeMS!kL68xK;m=+RrZD}E-DFLz zfqDYoBYqXs(;EQ-jEoo_KyK}Pz7=`$-8a?7I-9GgXQ2N)qNFPEBMX;mTw#sVR_xxT zqRB-wG!7l1#rU=$WUV3G7i^QMuKOFe;|M){P1&;##DrD7(GM@K<8!xV5h}AJ9R*tGDcFWHA)i_sY$Hu<4b4ASB+D)zt@ zOF688X0jC+o%7gKC+5jvvFX`PC9{ras~7qjaZoMeJn(5*_&d^ShQ8}&6*DL&%-HJ! zm7~ozw&&ykClEPezQ-mL|1^e=s2)nfoJ9DVV?D8dVl1AEemu>!U#JoPV5HKASHZTZ zBA-nKht%Lpckgg>EB`_~AI!+de=u^CTQ7OFd-%k3si-;VTIxDM9DfdtLlP5<>EMyE z9hMPmm3qvoQd>42b>6oCG^E)F>1#F=@cHRSE}ZIULylJYAFMYxbF9Ny>*NMBmE>Tg zEm;=(U~od+1AdCcqvc|^l9bu^td#M}4iIEW7Z+KO zut51J*png;wpdtTOMxRHae4NcVQFYp>TyGoaF&goY%{`8-h6J}cyg|oA4+jor`VYn?2`-KLqwJkolI&SJVbxWvsYJ)wn{B zrkUt_0ON@-_0S;R-uA1v+r55Za>V`xQ$|EA9#l!AKju1A%qPHA#_avsJd;OQ7Ct2M z3(eBKj+UZi7ES4FEuc;@r9jX$FsoPTCB-k#!9p1EMMCut_q-jx@f)?T!eC#0qqr+$&>7;F? zDnBjorsdz5mStll*6!P!IDLu(K_Y5Dof~@0(;Es2Jqizp$yLS5$+s(Et&+K#H`aXq zqHx`L7b>vn%*cxfWoQSML@dTU(_VMq$z*Kq;iti9?(28f{X~p@8|+$mPwmFM{@FQk z-Bwo$Tur;*vUd-D6|UuQo_P%ne0xy>qz7kaNJeI%q47-fmjm?U{_nzl0ZkU2OWrV2 z4o-=q=exH+=)(eKQr&hoEi^cZ0EPQz$9#0q9Qz>q@^Mg}S}7k0^}sEEi&ciGoxcQy zaSeG79|l)&)Y8N|aWPpw<%tnW>#_#eNnD)SKs1?AbboBfi2YtKCaS0Bx2W0PlO~tt zv-O(mJawoZP>MjS&#Se1T28-Pw@udwM(II z_70Q$N2sFq@*ZMiSuV*Ye57x6o#&7wSqSdNqdAW=+`spplcll z=4y(PMj8R*cg`TEyAREIlF8d#pP2g&u1_2+kA5tvcsbBh%PlKsZ?Id%Z%jP%u-~uP zvkJqDsi`R|q?d8WO{GIRqlT$E3iTz8+<>@Hv6Znj5T+fAVPFhV%JW0m+v=M6#;0rj zO-kmuzNH!-$qDa~zb2AW3_rQO0VDd#uLPYdtIP}y!Ri6DLkMR@{PdK!wTb>)%_iOP zoP^v|YG^|1+Q8LPuQfln#BKj=(uU^+8u>Hq>`cYEF@?|{nHURS*r#k#0WaAqEb}nM zY1k;$!9=TitHtENv0IO}D$PZ1ry{6=cgR?7wm)Qa(Lzef5uyD%o>W`Tz}LG5;)H!c zEeu(P<_nO2QsE_Sc4s{P<{_^3TV2b*7nv0BkQMaA&NPS(j*Q9Btku6s6zQT~4SoE2 zC@4aN!d`Bn2@Ty987V`^W^HZ#6zt7hBeoRoog$sPz+g7{8~`^krD8AtB4R{xQhFavkKs!66)iJA;EA zflQwNPEhb(%A5uLy~)B1Qt0&LF7FEoN;kG8CU(A{b83o=)T1u6eZnhad2upA(sMNy z3=?=?>?T(QpdJzY^Ar4&L~E0a3u%13sX(euZ16zByc5$veyDh%aKL+qe|qZV600O% zmKNyn34#r0r5I2OhGKBzo0M2@tQ~frEnWz?lRsJo{Z?aAPTO0b&EUROxdJU-PXXRQ zmFeZ%23lU6FrSBLY)ie)eHL76Y3}57;o}bAB@`Y2r}^8uD=SSBAcvh2@P zvq;)PpzEiO=VJvSC&Z7d&;99vzbe0a>5@Tg|g9^Jt)fY2=;TWJn97j4f2+pLw#AxgsL3>nGM@Ls*lkS|9gk~qC3Ow{WnaT zbq%|{>Sn8h-t;e@8Vy1!a84~HU8N#Nxd$Zmzi1Cg5bu8s$aG_IHKGrbUwjLTSV&&C$ToagYo#?LX_$WckGMhGlcRgM9Dp z5k9Y=ovOC#iWD^a-ET$;!ZAgthhtD3lQh97xVc%oT@7u*I*G~(hQc6VNQIz;y7!1J z+KMp+C*(63_q=w|vLQ&sgNu~qyz%Kt%$MjRO(~YL#HO@xf=}P;Vie1d&n@rMYT(6M zS;G34X5t}*@)6~yGb#h`9b0yPz@eg`tkDM27M*(&kSgKKLzR@20FL<`J96%jWsYKs z?ZN2o++mkH9$wLFEcyllfVMSQmZo^=@lNkG1}Jz-byVvB?G=kl)4LEHiWPP}HY1AT z)r9+B`VVn7itU|p&w3oxSdPv}?*(!bgYRZ$7EFYoGV!*p3U&xmME-O688w?V_%&CAhQl?;@=}_h_&6fpuQ8s8oaCIozAb2 zX*h)JxynQPisi~0)j=eXNy)NvTHU#O>b&gJU5X#cQBITD;T6`DDM>)wLv$JuvjQvf z%H&YTYR5@Z>iCJZ!dN0@rz5olr2RdRq_GQ+_fcSts zfRX`{b$!$DAGog)CA6I0;3LAK;j?$CtqJ2+3GwY1+ico5_T5wu$MrL!bu;ymQ?oxw zgt>bDrnIqDR@qqySh6rjXoBnH+?EjEb`>DY^*I& zYapai=A``UZCn3K-iMO!s7{e|CRXA}kiSu?6YPSR9b84Y{g3SCD^mY#QV;L|&J zKH_JlJ9nrHo+8df*zq@pu_AyyT&Td>VOvJ1uQ8tAuQs)(XNb42ak_4LveJ_wMcQQW zHo!^CY+Vu?%bv2-9kN12xWD+({B+nCHB9Gk9nH)Sj@5-GM1B1t-oeKjeZ3z1x_z!5 zgYz~7oO?DcN!MQ;z81Zv-L?1kXBmHj7U?(OUAD6YW8a+mLF%%j8spx-!8q^RKMFHx zXCB@z(6GZ=a3WKN*sKdWJ=CB)fC6mmjNE1-13q2$Jhft!{KQz)D&3$0|f$4Gj2QlURJjY|f0{ zJnd2F+rGQ!CVpy@HRuR;;CCL)6B84Epib1ACHEIBg@UV zLt;P|sTv&>^@O{0e3-Xav(9~wv49ccZOSr6+-_if*RUZM@Ak-vh`w~7JjxZz8Ch?D z$*yi|0d(Om&wYvodz7!u2H{=E?+%@Ga-S00LV{PO96B;NS|8k(TbFJ?*X1 z_0!dO#WYF$2?pA*>PcH$n9T)8A)|Ni}=PtTt!a4ol*ev1p|?`QoKv z$=Q9>Fc%rF_7k@d8FmptHoeV~TK)#gz*Wex=e@pfg|LOPM1I=#zcKd|2L!UeL zSp9LvhVUVs4ILdNf7juQMW1cUWAA!m%qfJnu-z@GYaVQsg!q@I((<_pj(Tbzo0}px zNi+mxg&H|IAYaYz=!f2S=fKGK^f)u!$z?If)?Q6bsxrr}P1K)gOKXCW#ZbWoAQa*! zqKFuOm{;&Uok1fIfrqs;A(!eV16)nIqGtgDDMNmcTr+L*Um<{_m4 zxJl#c@Xt>Vc%vkGwze+Vy=R*J6Dz$~A3!|nK@6*PS~!A%_o1NC;lTVLJJ@=CPmWGQ zR<#Y;1qiDt81&`!yXC)P@8(+h;<{a^(cFFvr4Zx73Qy{>l&MAQKw;xQRA1d8Z$4$= zlOr6I<9iNW#2SoRqeZ{p2Jc?0(&Q(tyUxy%uR^C*G)v*q9vU+T+JPCmH(NWnxvZD7 za&pMj3Q~zggTv4(n_W0;Tr6y%Su1KwOFsjet~__%-qf^FN>B9r zK<~d?MY`ZwTW@g*DTpx;6R^HamYtRPiB?;}U&Az&E(JO*-8s(c&YjT}CyeHvVI|U` zkvw_T_j_=T%}q&(k+Q#7+BOPC9m?ZHXbAlHbdBt}4P>p+C7S*XlJ@BR71#qoDVbDf zG{OtnmC^;w)^q2%qGk?QepJ_@!|5<5V+ooNY9vXXY!Xo}KF2y*dbNRagh?X{IF~da z(6b-OOyg1meMT=+jcivNn_7|=<|%GUOR!vbTy(MVV8aWa8mnl)FfcH`3A<>H2cJE< zGG=aBik-g+Gvo`S08W%0%(kO2-YeQ)RpY5WmmEoHlqA+^e{4z`Hva~4Z4$kEU7oM*W|A9V@ z6R`Oh`auj;aJFLv7`2vv$82mu!9(WHx?IcNtK4&mw86+Sio*Ma8+S~$TU&EOL&>Pd z4wg4ztKYXpN7qVBTA^sDla+OM9!Et;RNt$`K_VPf35!g3cAj4{G%+izq8!0;;Z|Xw z38*M_HNvH?iI8aX^@flrQ71|#CMoIRPc@f-B@WKkeD zLzzl6Ei*Ya<<*X-WDd&vgG=t}gl%+*+SViv>VgEyjf>j^bldV70t36+n}NtS+x~+^ z)A{SgzTcr4y_eul5Bl+Jz0>+VcVHSFl@v-xI|DGiWsQN(%0rA1dn9tJfP53J7X!Nr zID2Zdvhg@P5lk&1Lj#sf*@w>L>)Sj{IJS5Y+*S|{xymP!PvG^aiTWj^26!6%;ui_~ z2H=Mel6B!y*FV_FEcs$ov^TDuel#X1!|p*emxgh;ReoN?#x2^ppnpTD)ah8g{vC#5 zI#AQd$MRhZTd=N*$>>OIjE$h)FbL{wvZs^na7z|rr%(}l@@Yc|g|(%r9)0AmQ+rjr zs?vJIgSL7V*L%erUQqWJEeN=%8Y|D8u=jvwSd==;ZsdcB_1CW!ycSAmCGKg}%IGnJ zgi9J`QrO})akW!s%v5GN6>b9ja5ZtYy`95~^2njcRLcvSd;4G*dFWHGiMMuADXy}E zA|Bf=U-Yms1(83uR)l$$K3dsF*vqX03IH!O^(?iT}xi-@ap9B>Z#fha!!Pq zcE>tMP~}$Inc$CHt{W(bF4|M{sIK*U78`+X?P=azo^6TVF7FyKI+vGja54-pF(2xt zpV~OO`%c@fw9m=tz?mC{g8y8+QBIkH_0EfK@T7p| zVY|$KRDcRSLdlmdM%>~{PxN|wxOX`?^-WBT{aWjF>0Zg6z`?+XaGFymTtkC%d3LU$ zw1$}spmBM3Fk)8(of`i+%ySzP<9ES$b>Ab8*AD0+v;|R6$f4*2+rjoD83uu>w6yK^ zKn-PVDX6Fnu+@8*T3=ya+f0zPwp&e88X zb)>30K!tfGK!D7%?lBs;6i{FdqbiE@sg|7(b$~eso&q$f%|FC)?@q$J59CyL17yYjw}X zPh(h(_v&cx4*gB>e^{nLb=H_PHm)~}DReO$ziMv8fJ7>oFwLJYGA;6dLE877NL3t5z?)7hH zR?Bb4D4a(;;I~r^<4r)eH5!d_YDa}mYgByDWhvj)Qsyk`s8<#+E-w#D0K>Bd64S$N zCKh&oYP`;CVnFT1$Hzj-UPQ$E+tuKGIv2cD7F#FuPOpTl)u%yps#Gyda^KZOCXdYg^h zIlWjSbC=lH2t6WXOutlWqN8uOuhL2)rB46AcTsWu=G#HKx$8gW+q^B*3SYM9<)U&B%)pOC>JR22YMnWt*3%8dodr8?)7!@4sH0G&D zuDr)rf5$+l-tLtOFP>|P;*AX!W{oLqzWi&tAG ziFnO=^EY;|xIjBQIbZZU-EqW85z$mxc#D5t&5O%g`U$Pv+Ng$!&Wu<*ecK3rm<`Dh zk(`7=50%^lnG=$kA^jN?o1EjpjsZ2?+K>SWgOF`_f~RrP?VhP#7aIay0)ZWwQs3bS z0*Nu?Xyd~kCX7aOc#klKg3&EjQ&DJ^M@%XFlZ(X@tR;%71z!YXu#zbV!xxjh1Y@d2(DyGzn~_q!3V% zpV{F*_qb1sS8D+2qSx7wQb~X~%{%qYUa{4fMI`AQRMdbI?sGUXYNtz3`IIB5I<_bw z%UY!Q<@Jnk$nv$KFtR_@;hGLb+FGdz7!C~T^W$5d8@b*)SGOuBCy-1$u7@HVXLtqH z4AD(&T}VUe!!gsGg(-gZ$8EMHa%ju7uJWH{`ChuGLg`j~SrBTBsJG)1jN+%8+yV!q zGzNODeu;TM3Ni(<#kiIRPzJvbilUcg5bnv!FWG(ErmsEFVQ&Qkq;8%@N3|~#TE=>n z>Dx&?8iv9&@;W-S;8TNqL%KUv;u&Vj)4j(tjM{K=Vo!31#@dYcXhO`#+s#2irxKlC z4^-@k5d?GimMEy?NLnt*SfMUt%N=DpS?Kpt8_UAa(KZ_dCDxH{ROeKWWqjv%P`U$% z@C7!=^<{&$80!^sQDN!QDzC3ASh)nscWD`-7nQ70U+1#`+dqY*`35I?04p62@tMLh z!3MtVn0yJZIus&#DB}Q?1U@{9Rbr>v+QLbBz)j(0s4S{@v}Qb12Wus6gZ7F6lW{WXg%Q&Rmdf`53(nRSZ+M+>Q#g)BB5?!llVZ5II z0D}A6Wj6eCb`^OVL@#j|_IdrQ4@rb1Gu4G?wLp;H3b1*3cNDP+bNVdr;cDv?-w71% zg0IbYh@RpQysSM8my^4jd?k^^49Vp1emxP7vhE|bsvZf(+MZ&;@Vt(ilvCR8ZZT|` zshXECIKA(v&a;r>t0tL@RV~9t0s-cgytD7>wPa?438suwW?f_yT)R8 zvaSu2FjTT`wY@f{Nl9MNT;!Rketntz(9`&ecs0{mP{awD(N zUxi?pUd&KcwHI>BcR|-rTFPaMwRb&wOyC&j2Lm@#A{JO=N_Rb*qLWU)lVYvNa5dy= z(OD6XIHBReJl2#bkk+)K_cLM!(UI`P#eMY_QA31$G2tu{{>B8qb^q3oo?WP{|N00A z`0(e}!SLj=ozz6_xgFss^%+)u9T8z&@blIi1=JRw03XR$ zCT;K6?_;Ricg9G~J_{T^+>&AdR^#KNuFy6Xc`-?7jnP|L(}}+kKeZ20Bz_B?KICul zkJ4FwdD-XwgXvsb9El~#-7HKcW@GyTW13|s^XhJ&;yS?==ew5xsl+st8It3a0{65>;mYC5m z)n;`G+`SARS!0V`U)P8&Kl)jwE2k-(wKUu@W#vitcb>4h6r$i6k~1f&5HBHRe%~15 z<={*ey+VTre!v={q0CLn_ctti`SP5`=)jyCK5tBli4Xd8a&YN)&d%{nz6qHwL5_1! zKu#XM#K;f4iYBD$R@{Yj(W4Rl0X9IzKZicJ1}^NMcUv+nP{N@%JM4{PvQupVm145X z-a=)tYMCz4v+Qhi79Zqr{9E=nPfI-}C4zXuH~&^$Er9kCv2tF!Ddp145@;m>jYX@h zfdt2Au*Il2l5m6JwXbVsqmEmSF5-G4>LYDHqUAxMk~8>|+a2yTybfk0Uq&MA*qFxD z@H(xPm+0juoMBaI2ZX*J#Gy=27;K>!Zd?%NgxAJkheQUbWep&Yt#m$Y*oCc3Vq1ZI zCmDcY6@^s*&PYwX%T2#aJ+^6chBKp^U%Y$O(Ya}9q-UHp=$J!Ib0J3BvN#CPtjzp8 zs<0|Xp4bA*t8|jDtY29(wou)1@rUgX``Znez%@4r``-vfymYB3>}$t`NW8|B%>`mv}XW*+>O;Slh5K1ybrC)YK>P^0qz#=z7mcf$w+%U-E zDUjF0F+@w*+7QW3PUfFdb6tr0K{yP3X|XV>_WL)cFE#JJVyf7NZtO~x~s0@lr5nT^P$)>R^(&WNc^Ow0=;POuY98li05~ic8JQG5ozt^~bkuIBj!khY51DTTFHeYCT|}h4R@H!Sz)) zjEak(0*&FF>v>m%8oZ(#%^1l;^~kurHy-_4Q^m$?qQRVz1uvz~l*+vmV%=LO-$Z7F zw2{&rBB+F-fzseE}Hif zL?GQ%9wYDmAgesKLTj4wWa0NLcotYB8+r7dY#>EuD$OJM8IK(09&{JXF66#{Ld;u+ z{TCPz0SMfp<@u&TC@IBH=djw8}K)_#-EIyz#qoV|x?^GAQ>CA=BK%{K|?kQ-Z zsI*cauAz<%-0pU4|TWleJl52RA3=Eofu~%nLa=U1pnmoADP)ud}=}?VveN5h58EwDNZ2ok+WrHk`co7S9TpEzaB}F3?c(psh z#z}fE3%|DjUZQnzgR$2$`-+x$Lh|?T^m)ECe`g343GKubT=kmLcpS{U@h4;FFhPbbY`{*FrSvs{g zYquC!=eg4*N?BQ_9J!E}x@$S!+*p+q#{aFudTX^ihH4*j*Ku)RWtTh!z^Mf~6%voo zk;eeZ%r6<>cMsGJGv&!G9il85tbIEC&Mum{bN%2dU(m1r`X2mU#ZQg>=uOzcr9iqJ zT!Ia1NgACY-5F!PP@BJnZNaPuKYGk08n}~nOLm>&YZJS&RGB#G?ecp8o_?F(n7qwx z#@pZ&K(Ed`BeizgeOy5z!NV_$msxwp?0RT8-i#GkA5p5u0*quz{3=$^MUjAgjGt)~ zfW?FHg5S+%^XM)e{ zW&>6!eCJr))h7IDamTBTDHGQ%T!f~MbS=_@fS9k|xgJHWfwxe^`K@B|wMCQf!&{^l zFVD8~s$oYnAjBgJ8nL@tr>fKlHXpdd z08&qF(Ty2hHq;p^3j0B~dricE=StGg0%(B6yv345(7w&MxHS``k6AeSs6ZvJDmD*_ zJ@99}Jo(fiIlAhN2z1K#rWmx@Ca2OLIDHzp*CQ8-*TJY(_32sE>NXFV>r6RYV0qAw z;jS(YeaDO(K*uQw2CTn#?`QDGES01|<{0>Wds#emRGdgiJ|HFh1^=JyX#{K*xvziB z=^{V?0Qi5clAW!Yl8Lp6(ck|~#x{x5u^OO93Az17C0x}gJ2ySeLl?3~?@X(*Wg|km z)PNmHOn|S0`TbPfjA)4Df5^J)3Uy^6I%2~UJZmWT??JHC-m`mv=wc@q4pwoE*Mb$X zNd^}Up^Negbe_tYyWzWbdl}n_+HeX!$JJmRDl%ccN?&^g_=P8!C+h34`^`jAbzjrvEeU3WW zU4Kn*IUcH#JfQV(+&8@p>9RV@r^tn2*#D`X(JAASy2FY=WrbaHX<8^_f(KGtU*HNo z^&)vo-Q-{CEPOiu0slV()!oNF8}Tnl;}8G3_#- zJ6Yhr;x&5f6EWum`)`&2{*N($+`^#YjDC-BsRcVCoPa`YwCi22I&a$sr-S@C%=n4 zg}%NPhULt&CE%R)J=+m>b3h*kIef;-PKS$Wq!h|Ab-qne`7`+|3(^1=>Og@SRXd5D zBZIBqK)wMgFxP$6(qxD0xT|Z^A*!`}v+O?xL{Y7A0sp11R0o=u*3}+R)#Gd9=v20% zB2Qqq3Ug2K1%La%XcN{yAPz4@Z2zB9Y$20>_GnUoKqvtJ|H%4(pYZ=W{Qs-@zXA6D zsrpZB{QuDa0QfijAJzW@k^fKWe^TB5TPpjn8~snl`+sWxb5#DfcEa=jHAeqa{GUDb gzr~OL0Q3Lf{Z?KI6zsq51O0c>{(HQ7pZ~i0UkaAA#Q*>R literal 0 HcmV?d00001 diff --git a/osu.Game.Tests/Resources/Archives/modified-default-20220723.osk b/osu.Game.Tests/Resources/Archives/modified-default-20220723.osk new file mode 100644 index 0000000000000000000000000000000000000000..7547162165c84e5cd05b7c2cd259f17add5940a5 GIT binary patch literal 1383 zcmWIWW@Zs#U|`^2xXR2JdTQq0HlX?>Con{nEK zB&mxv{fasbEB*hd%(t;s0&#T`mGTx)X?bff(fQ z%)GRGy{zK=Jky@tT!$P4Tz}Ub-4V)^c<@@7vYouBy6Y*63#yWtT}c$q1W z$2a3+uk-r9M=~B2(VtWiz31D!f8`nX;`7~I+%s#kqpqP{Cc?1K8+viWzIr50Y*;9Atdw|EAd$%m6i=4uGKad~z7{8G`M zzvRLG1yL_dS4`Ae`sGh8=T5UjR$Sr7_Gz@gy`$vgB$alv^4a!`rx$*(^WM9*{_My5 zw>CYim|Mkv&T{gH#tppYArA#FFMXulTbgh~VY>!bps~4WMLFA(HzgPVzUMFZJYHx8#i|^NjzYSlO{8oLgY7|$h_4j6Z z)*p*^*Bd1bGQ)!tx9MH*e_ejz=gp08YVVjAukDg4ZA>_GQcHHZyp_${m50+0{d2ie z!Tc`Eu;k1K*`iHiEeAKUvOn3+TAzCG=5zbzC$}pmFzcD-&3H5+d*PawrRO|@rFN)$ z`d8eDZE>kX;^92~cjlj6(2hzd$dFjEaIjPAd;0TVLu-EUffr#68yVj{UBR1Zi&@`pd zrKz#8OKjSzW>5WDCP47{dG>}}rYw7TnQ&%{Z(o_<9=Qu=ev12jLJ zE9ks0&`T7UFj2k3C7r^>dQrbvgY{;6iEP54HerMkWyk+yx9UlpvrHM8S$1bY1AV8>$Bw y(mSEL;CUTgD|+5TXbl6#684;kZU%b1BFwO3#)#zrZ&o&t0u~_r1f=6xKs*59D<&=g literal 0 HcmV?d00001 From f9f9b65c86baf9d3a5f18dc422b720e925614d5f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 31 Jul 2022 23:42:18 +0900 Subject: [PATCH 198/278] Add test coverage of deserialisation skin layouts --- .../Skins/SkinDeserialisationTest.cs | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 osu.Game.Tests/Skins/SkinDeserialisationTest.cs diff --git a/osu.Game.Tests/Skins/SkinDeserialisationTest.cs b/osu.Game.Tests/Skins/SkinDeserialisationTest.cs new file mode 100644 index 0000000000..699c1bcc2c --- /dev/null +++ b/osu.Game.Tests/Skins/SkinDeserialisationTest.cs @@ -0,0 +1,78 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Linq; +using NUnit.Framework; +using osu.Framework.Audio.Sample; +using osu.Framework.Bindables; +using osu.Framework.Graphics.OpenGL.Textures; +using osu.Framework.Graphics.Textures; +using osu.Framework.IO.Stores; +using osu.Game.Audio; +using osu.Game.IO; +using osu.Game.IO.Archives; +using osu.Game.Skinning; +using osu.Game.Tests.Resources; + +namespace osu.Game.Tests.Skins +{ + /// + /// Test that the main components (which are serialised based on namespace/class name) + /// remain compatible with any changes. + /// + /// + /// If this test breaks, check any naming or class structure changes. + /// Migration rules may need to be added to . + /// + [TestFixture] + public class SkinDeserialisationTest + { + [Test] + public void TestDeserialiseModifiedDefault() + { + using (var stream = TestResources.OpenResource("Archives/modified-default-20220723.osk")) + using (var storage = new ZipArchiveReader(stream)) + { + var skin = new TestSkin(new SkinInfo(), null, storage); + + Assert.That(skin.DrawableComponentInfo, Has.Count.EqualTo(2)); + Assert.That(skin.DrawableComponentInfo[SkinnableTarget.MainHUDComponents], Has.Length.EqualTo(9)); + } + } + + [Test] + public void TestDeserialiseModifiedClassic() + { + using (var stream = TestResources.OpenResource("Archives/modified-classic-20220723.osk")) + using (var storage = new ZipArchiveReader(stream)) + { + var skin = new TestSkin(new SkinInfo(), null, storage); + + Assert.That(skin.DrawableComponentInfo, Has.Count.EqualTo(2)); + Assert.That(skin.DrawableComponentInfo[SkinnableTarget.MainHUDComponents], Has.Length.EqualTo(6)); + Assert.That(skin.DrawableComponentInfo[SkinnableTarget.SongSelect], Has.Length.EqualTo(1)); + + var skinnableInfo = skin.DrawableComponentInfo[SkinnableTarget.SongSelect].First(); + + Assert.That(skinnableInfo.Type, Is.EqualTo(typeof(SkinnableSprite))); + Assert.That(skinnableInfo.Settings.First().Key, Is.EqualTo("sprite_name")); + Assert.That(skinnableInfo.Settings.First().Value, Is.EqualTo("ppy_logo-2.png")); + } + } + + private class TestSkin : Skin + { + public TestSkin(SkinInfo skin, IStorageResourceProvider? resources, IResourceStore? storage = null, string configurationFilename = "skin.ini") + : base(skin, resources, storage, configurationFilename) + { + } + + public override Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => throw new NotImplementedException(); + + public override IBindable GetConfig(TLookup lookup) => throw new NotImplementedException(); + + public override ISample GetSample(ISampleInfo sampleInfo) => throw new NotImplementedException(); + } + } +} From 57b43e006583a1789f784c54600ecc9d4801cce7 Mon Sep 17 00:00:00 2001 From: notmyname <50967056+naipofo@users.noreply.github.com> Date: Sun, 31 Jul 2022 19:12:29 +0200 Subject: [PATCH 199/278] Stop capturing arrow keys on Playlist --- osu.Game/Screens/OnlinePlay/DrawableRoomPlaylist.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylist.cs b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylist.cs index 5193fe5cbf..d3212b1b3b 100644 --- a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylist.cs +++ b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylist.cs @@ -204,6 +204,9 @@ namespace osu.Game.Screens.OnlinePlay public bool OnPressed(KeyBindingPressEvent e) { + if (!AllowSelection) + return false; + switch (e.Action) { case GlobalAction.SelectNext: From 98214beb6cd92b272872e6c8645aad185b7ee640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gutyina=20Gerg=C5=91?= Date: Sun, 31 Jul 2022 21:24:41 +0200 Subject: [PATCH 200/278] Prevent overflow on beatmap info using scrollable container --- osu.Game/Overlays/BeatmapSet/Info.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/BeatmapSet/Info.cs b/osu.Game/Overlays/BeatmapSet/Info.cs index 666ceff6cb..5517e51515 100644 --- a/osu.Game/Overlays/BeatmapSet/Info.cs +++ b/osu.Game/Overlays/BeatmapSet/Info.cs @@ -9,6 +9,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Game.Graphics; +using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; using osu.Game.Online.API.Requests.Responses; @@ -62,7 +63,7 @@ namespace osu.Game.Overlays.BeatmapSet Child = new MetadataSection(MetadataType.Description), }, }, - new Container + new OsuScrollContainer { Anchor = Anchor.TopRight, Origin = Anchor.TopRight, From cbabc4886cc7b94abca634ca618525fb32eb5cad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sat, 23 Jul 2022 17:25:11 +0200 Subject: [PATCH 201/278] Convert `ModPreset` to realm object --- osu.Game/Rulesets/Mods/ModPreset.cs | 46 +++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/osu.Game/Rulesets/Mods/ModPreset.cs b/osu.Game/Rulesets/Mods/ModPreset.cs index 367acc8a91..2c3f574d47 100644 --- a/osu.Game/Rulesets/Mods/ModPreset.cs +++ b/osu.Game/Rulesets/Mods/ModPreset.cs @@ -3,6 +3,12 @@ using System; using System.Collections.Generic; +using System.Linq; +using Newtonsoft.Json; +using osu.Framework.Extensions.ObjectExtensions; +using osu.Game.Database; +using osu.Game.Online.API; +using Realms; namespace osu.Game.Rulesets.Mods { @@ -10,12 +16,18 @@ namespace osu.Game.Rulesets.Mods /// A mod preset is a named collection of configured mods. /// Presets are presented to the user in the mod select overlay for convenience. /// - public class ModPreset + public class ModPreset : RealmObject, IHasGuidPrimaryKey, ISoftDelete { + /// + /// The internal database ID of the preset. + /// + [PrimaryKey] + public Guid ID { get; set; } = Guid.NewGuid(); + /// /// The ruleset that the preset is valid for. /// - public RulesetInfo RulesetInfo { get; set; } = null!; + public RulesetInfo Ruleset { get; set; } = null!; /// /// The name of the mod preset. @@ -30,6 +42,34 @@ namespace osu.Game.Rulesets.Mods /// /// The set of configured mods that are part of the preset. /// - public ICollection Mods { get; set; } = Array.Empty(); + [Ignored] + public ICollection Mods + { + get + { + if (string.IsNullOrEmpty(ModsJson)) + return Array.Empty(); + + var apiMods = JsonConvert.DeserializeObject>(ModsJson); + var ruleset = Ruleset.CreateInstance(); + return apiMods.AsNonNull().Select(mod => mod.ToMod(ruleset)).ToArray(); + } + set + { + var apiMods = value.Select(mod => new APIMod(mod)).ToArray(); + ModsJson = JsonConvert.SerializeObject(apiMods); + } + } + + /// + /// The set of configured mods that are part of the preset, serialised as a JSON blob. + /// + [MapTo("Mods")] + public string ModsJson { get; set; } = string.Empty; + + /// + /// Whether the preset has been soft-deleted by the user. + /// + public bool DeletePending { get; set; } } } From fa3b9ee32ffa18764cd96246f5bef092a69421b9 Mon Sep 17 00:00:00 2001 From: notmyname <50967056+naipofo@users.noreply.github.com> Date: Sun, 31 Jul 2022 23:42:20 +0200 Subject: [PATCH 202/278] remove unneded guard --- osu.Game/Screens/OnlinePlay/DrawableRoomPlaylist.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylist.cs b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylist.cs index d3212b1b3b..ed554ebd34 100644 --- a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylist.cs +++ b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylist.cs @@ -227,9 +227,6 @@ namespace osu.Game.Screens.OnlinePlay private void selectNext(int direction) { - if (!AllowSelection) - return; - var visibleItems = ListContainer.AsEnumerable().Where(r => r.IsPresent); PlaylistItem item; From 345f10311935da5f49e7f230acb82e3348af8fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sat, 23 Jul 2022 18:01:11 +0200 Subject: [PATCH 203/278] Migrate mod preset column to use realm --- .../UserInterface/TestSceneModPresetColumn.cs | 61 ++++++++++++++++--- .../UserInterface/TestSceneModPresetPanel.cs | 3 +- osu.Game/Database/RealmAccess.cs | 3 +- osu.Game/Overlays/Mods/ModPresetColumn.cs | 55 +++++++++++------ osu.Game/Overlays/Mods/ModPresetPanel.cs | 11 ++-- 5 files changed, 99 insertions(+), 34 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs index f6209e1b42..f86072dbc0 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs @@ -5,10 +5,14 @@ using System.Collections.Generic; using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; +using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Testing; using osu.Game.Overlays; using osu.Game.Overlays.Mods; +using osu.Game.Rulesets; +using osu.Game.Rulesets.Mania.Mods; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Osu.Mods; @@ -16,29 +20,54 @@ namespace osu.Game.Tests.Visual.UserInterface { public class TestSceneModPresetColumn : OsuTestScene { + protected override bool UseFreshStoragePerRun => true; + + [Resolved] + private RulesetStore rulesets { get; set; } = null!; + [Cached] private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green); + [BackgroundDependencyLoader] + private void load() + { + Dependencies.Cache(Realm); + } + + [SetUpSteps] + public void SetUpSteps() + { + AddStep("reset storage", () => + { + Realm.Write(realm => + { + realm.RemoveAll(); + realm.Add(createTestPresets()); + }); + }); + } + [Test] public void TestBasicAppearance() { - ModPresetColumn modPresetColumn = null!; - + AddStep("set osu! ruleset", () => Ruleset.Value = rulesets.GetRuleset(0)); AddStep("create content", () => Child = new Container { RelativeSizeAxes = Axes.Both, Padding = new MarginPadding(30), - Child = modPresetColumn = new ModPresetColumn + Child = new ModPresetColumn { Anchor = Anchor.Centre, Origin = Anchor.Centre, - Presets = createTestPresets().ToArray() } }); - AddStep("change presets", () => modPresetColumn.Presets = createTestPresets().Skip(1).ToArray()); + AddUntilStep("3 panels visible", () => this.ChildrenOfType().Count() == 3); + + AddStep("change ruleset to mania", () => Ruleset.Value = rulesets.GetRuleset(3)); + AddUntilStep("1 panel visible", () => this.ChildrenOfType().Count() == 1); } - private static IEnumerable createTestPresets() => new[] + private IEnumerable createTestPresets() => new[] { new ModPreset { @@ -48,7 +77,8 @@ namespace osu.Game.Tests.Visual.UserInterface { new OsuModHardRock(), new OsuModDoubleTime() - } + }, + Ruleset = rulesets.GetRuleset(0).AsNonNull() }, new ModPreset { @@ -60,7 +90,8 @@ namespace osu.Game.Tests.Visual.UserInterface { ApproachRate = { Value = 0 } } - } + }, + Ruleset = rulesets.GetRuleset(0).AsNonNull() }, new ModPreset { @@ -70,7 +101,19 @@ namespace osu.Game.Tests.Visual.UserInterface { new OsuModFlashlight(), new OsuModSpinIn() - } + }, + Ruleset = rulesets.GetRuleset(0).AsNonNull() + }, + new ModPreset + { + Name = "Different ruleset", + Description = "Just to shake things up", + Mods = new Mod[] + { + new ManiaModKey4(), + new ManiaModFadeIn() + }, + Ruleset = rulesets.GetRuleset(3).AsNonNull() } }; } diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetPanel.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetPanel.cs index 62e63d47bc..dd3c7000a2 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetPanel.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetPanel.cs @@ -7,6 +7,7 @@ using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Game.Database; using osu.Game.Overlays; using osu.Game.Overlays.Mods; using osu.Game.Rulesets.Mods; @@ -31,7 +32,7 @@ namespace osu.Game.Tests.Visual.UserInterface Anchor = Anchor.Centre, Origin = Anchor.Centre, Spacing = new Vector2(0, 5), - ChildrenEnumerable = createTestPresets().Select(preset => new ModPresetPanel(preset)) + ChildrenEnumerable = createTestPresets().Select(preset => new ModPresetPanel(preset.ToLiveUnmanaged())) }); } diff --git a/osu.Game/Database/RealmAccess.cs b/osu.Game/Database/RealmAccess.cs index 1a0c03af7d..5f0ec67c71 100644 --- a/osu.Game/Database/RealmAccess.cs +++ b/osu.Game/Database/RealmAccess.cs @@ -66,8 +66,9 @@ namespace osu.Game.Database /// 19 2022-07-19 Added DateSubmitted and DateRanked to BeatmapSetInfo. /// 20 2022-07-21 Added LastAppliedDifficultyVersion to RulesetInfo, changed default value of BeatmapInfo.StarRating to -1. /// 21 2022-07-27 Migrate collections to realm (BeatmapCollection). + /// 22 2022-07-31 Added ModPreset. /// - private const int schema_version = 21; + private const int schema_version = 22; /// /// Lock object which is held during sections, blocking realm retrieval during blocking periods. diff --git a/osu.Game/Overlays/Mods/ModPresetColumn.cs b/osu.Game/Overlays/Mods/ModPresetColumn.cs index 1eea8383f8..bed4cff0ea 100644 --- a/osu.Game/Overlays/Mods/ModPresetColumn.cs +++ b/osu.Game/Overlays/Mods/ModPresetColumn.cs @@ -7,31 +7,24 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using osu.Framework.Allocation; +using osu.Framework.Bindables; +using osu.Game.Database; using osu.Game.Graphics; using osu.Game.Localisation; +using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; using osuTK; +using Realms; namespace osu.Game.Overlays.Mods { public class ModPresetColumn : ModSelectColumn { - private IReadOnlyList presets = Array.Empty(); + [Resolved] + private RealmAccess realm { get; set; } = null!; - /// - /// Sets the collection of available mod presets. - /// - public IReadOnlyList Presets - { - get => presets; - set - { - presets = value; - - if (IsLoaded) - asyncLoadPanels(); - } - } + [Resolved] + private IBindable ruleset { get; set; } = null!; [BackgroundDependencyLoader] private void load(OsuColour colours) @@ -44,7 +37,20 @@ namespace osu.Game.Overlays.Mods { base.LoadComplete(); - asyncLoadPanels(); + ruleset.BindValueChanged(_ => rulesetChanged(), true); + } + + private IDisposable? presetSubscription; + + private void rulesetChanged() + { + presetSubscription?.Dispose(); + presetSubscription = realm.RegisterForNotifications(r => + r.All() + .Filter($"{nameof(ModPreset.Ruleset)}.{nameof(RulesetInfo.ShortName)} == $0" + + $" && {nameof(ModPreset.DeletePending)} == false", ruleset.Value.ShortName) + .OrderBy(preset => preset.Name), + (presets, _, _) => asyncLoadPanels(presets)); } private CancellationTokenSource? cancellationTokenSource; @@ -52,11 +58,17 @@ namespace osu.Game.Overlays.Mods private Task? latestLoadTask; internal bool ItemsLoaded => latestLoadTask == null; - private void asyncLoadPanels() + private void asyncLoadPanels(IReadOnlyList presets) { cancellationTokenSource?.Cancel(); - var panels = presets.Select(preset => new ModPresetPanel(preset) + if (!presets.Any()) + { + ItemsFlow.Clear(); + return; + } + + var panels = presets.Select(preset => new ModPresetPanel(preset.ToLive(realm)) { Shear = Vector2.Zero }); @@ -73,5 +85,12 @@ namespace osu.Game.Overlays.Mods latestLoadTask = null; }); } + + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + + presetSubscription?.Dispose(); + } } } diff --git a/osu.Game/Overlays/Mods/ModPresetPanel.cs b/osu.Game/Overlays/Mods/ModPresetPanel.cs index 47e2f25538..a00729d9fd 100644 --- a/osu.Game/Overlays/Mods/ModPresetPanel.cs +++ b/osu.Game/Overlays/Mods/ModPresetPanel.cs @@ -4,6 +4,7 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics.Cursor; +using osu.Game.Database; using osu.Game.Graphics; using osu.Game.Rulesets.Mods; @@ -11,16 +12,16 @@ namespace osu.Game.Overlays.Mods { public class ModPresetPanel : ModSelectPanel, IHasCustomTooltip { - public readonly ModPreset Preset; + public readonly Live Preset; public override BindableBool Active { get; } = new BindableBool(); - public ModPresetPanel(ModPreset preset) + public ModPresetPanel(Live preset) { Preset = preset; - Title = preset.Name; - Description = preset.Description; + Title = preset.Value.Name; + Description = preset.Value.Description; } [BackgroundDependencyLoader] @@ -29,7 +30,7 @@ namespace osu.Game.Overlays.Mods AccentColour = colours.Orange1; } - public ModPreset TooltipContent => Preset; + public ModPreset TooltipContent => Preset.Value; public ITooltip GetCustomTooltip() => new ModPresetTooltip(ColourProvider); } } From c837848238f3b75b9a567b412916f4117b656571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sat, 23 Jul 2022 18:09:27 +0200 Subject: [PATCH 204/278] Add extended test coverage of preset realm subscription --- .../UserInterface/TestSceneModPresetColumn.cs | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs index f86072dbc0..f927d83722 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs @@ -48,7 +48,7 @@ namespace osu.Game.Tests.Visual.UserInterface } [Test] - public void TestBasicAppearance() + public void TestBasicOperation() { AddStep("set osu! ruleset", () => Ruleset.Value = rulesets.GetRuleset(0)); AddStep("create content", () => Child = new Container @@ -65,6 +65,41 @@ namespace osu.Game.Tests.Visual.UserInterface AddStep("change ruleset to mania", () => Ruleset.Value = rulesets.GetRuleset(3)); AddUntilStep("1 panel visible", () => this.ChildrenOfType().Count() == 1); + + AddStep("add another mania preset", () => Realm.Write(r => r.Add(new ModPreset + { + Name = "and another one", + Mods = new Mod[] + { + new ManiaModMirror(), + new ManiaModNightcore(), + new ManiaModHardRock() + }, + Ruleset = rulesets.GetRuleset(3).AsNonNull() + }))); + AddUntilStep("2 panels visible", () => this.ChildrenOfType().Count() == 2); + + AddStep("add another osu! preset", () => Realm.Write(r => r.Add(new ModPreset + { + Name = "hdhr", + Mods = new Mod[] + { + new OsuModHidden(), + new OsuModHardRock() + }, + Ruleset = rulesets.GetRuleset(0).AsNonNull() + }))); + AddUntilStep("2 panels visible", () => this.ChildrenOfType().Count() == 2); + + AddStep("remove mania preset", () => Realm.Write(r => + { + var toRemove = r.All().Single(preset => preset.Name == "Different ruleset"); + r.Remove(toRemove); + })); + AddUntilStep("1 panel visible", () => this.ChildrenOfType().Count() == 1); + + AddStep("set osu! ruleset", () => Ruleset.Value = rulesets.GetRuleset(0)); + AddUntilStep("4 panels visible", () => this.ChildrenOfType().Count() == 4); } private IEnumerable createTestPresets() => new[] From 9dea8e3d12ef84ca23b4d36a2e114dc5e3501218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sat, 23 Jul 2022 18:12:55 +0200 Subject: [PATCH 205/278] Add test coverage of preset soft deletion --- .../UserInterface/TestSceneModPresetColumn.cs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs index f927d83722..2ef6d2ab70 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs @@ -102,6 +102,44 @@ namespace osu.Game.Tests.Visual.UserInterface AddUntilStep("4 panels visible", () => this.ChildrenOfType().Count() == 4); } + [Test] + public void TestSoftDeleteSupport() + { + AddStep("set osu! ruleset", () => Ruleset.Value = rulesets.GetRuleset(0)); + AddStep("create content", () => Child = new Container + { + RelativeSizeAxes = Axes.Both, + Padding = new MarginPadding(30), + Child = new ModPresetColumn + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + } + }); + AddUntilStep("3 panels visible", () => this.ChildrenOfType().Count() == 3); + + AddStep("soft delete preset", () => Realm.Write(r => + { + var toSoftDelete = r.All().Single(preset => preset.Name == "AR0"); + toSoftDelete.DeletePending = true; + })); + AddUntilStep("2 panels visible", () => this.ChildrenOfType().Count() == 2); + + AddStep("soft delete all presets", () => Realm.Write(r => + { + foreach (var preset in r.All()) + preset.DeletePending = true; + })); + AddUntilStep("no panels visible", () => this.ChildrenOfType().Count() == 0); + + AddStep("undelete preset", () => Realm.Write(r => + { + foreach (var preset in r.All()) + preset.DeletePending = false; + })); + AddUntilStep("3 panels visible", () => this.ChildrenOfType().Count() == 3); + } + private IEnumerable createTestPresets() => new[] { new ModPreset From 9d3cdae4bba5cd15eaaecea1b9ad32107541103c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sat, 23 Jul 2022 21:56:10 +0200 Subject: [PATCH 206/278] Fix test scene to handle restarts properly --- .../UserInterface/TestSceneModPresetColumn.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs index 2ef6d2ab70..593c8abac4 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs @@ -22,8 +22,7 @@ namespace osu.Game.Tests.Visual.UserInterface { protected override bool UseFreshStoragePerRun => true; - [Resolved] - private RulesetStore rulesets { get; set; } = null!; + private RulesetStore rulesets = null!; [Cached] private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green); @@ -31,18 +30,25 @@ namespace osu.Game.Tests.Visual.UserInterface [BackgroundDependencyLoader] private void load() { + Dependencies.Cache(rulesets = new RealmRulesetStore(Realm)); Dependencies.Cache(Realm); } [SetUpSteps] public void SetUpSteps() { + AddStep("clear contents", Clear); AddStep("reset storage", () => { Realm.Write(realm => { realm.RemoveAll(); - realm.Add(createTestPresets()); + + var testPresets = createTestPresets(); + foreach (var preset in testPresets) + preset.Ruleset = realm.Find(preset.Ruleset.ShortName); + + realm.Add(testPresets); }); }); } @@ -75,7 +81,7 @@ namespace osu.Game.Tests.Visual.UserInterface new ManiaModNightcore(), new ManiaModHardRock() }, - Ruleset = rulesets.GetRuleset(3).AsNonNull() + Ruleset = r.Find("mania") }))); AddUntilStep("2 panels visible", () => this.ChildrenOfType().Count() == 2); @@ -87,7 +93,7 @@ namespace osu.Game.Tests.Visual.UserInterface new OsuModHidden(), new OsuModHardRock() }, - Ruleset = rulesets.GetRuleset(0).AsNonNull() + Ruleset = r.Find("osu") }))); AddUntilStep("2 panels visible", () => this.ChildrenOfType().Count() == 2); @@ -140,7 +146,7 @@ namespace osu.Game.Tests.Visual.UserInterface AddUntilStep("3 panels visible", () => this.ChildrenOfType().Count() == 3); } - private IEnumerable createTestPresets() => new[] + private ICollection createTestPresets() => new[] { new ModPreset { From 5a34122a85c746e5eb1d954c6df898519ef9ef2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sat, 23 Jul 2022 21:29:30 +0200 Subject: [PATCH 207/278] Fix test breakage after realm migration --- .../Visual/UserInterface/TestSceneModPresetPanel.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetPanel.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetPanel.cs index dd3c7000a2..92d1cba2c2 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetPanel.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetPanel.cs @@ -11,6 +11,7 @@ using osu.Game.Database; using osu.Game.Overlays; using osu.Game.Overlays.Mods; using osu.Game.Rulesets.Mods; +using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu.Mods; using osuTK; @@ -46,7 +47,8 @@ namespace osu.Game.Tests.Visual.UserInterface { new OsuModHardRock(), new OsuModDoubleTime() - } + }, + Ruleset = new OsuRuleset().RulesetInfo }, new ModPreset { @@ -58,7 +60,8 @@ namespace osu.Game.Tests.Visual.UserInterface { ApproachRate = { Value = 0 } } - } + }, + Ruleset = new OsuRuleset().RulesetInfo }, new ModPreset { @@ -68,7 +71,8 @@ namespace osu.Game.Tests.Visual.UserInterface { new OsuModFlashlight(), new OsuModSpinIn() - } + }, + Ruleset = new OsuRuleset().RulesetInfo } }; } From 85f77abee113342d224c03353f9aa2a7e597e1a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 31 Jul 2022 22:59:33 +0200 Subject: [PATCH 208/278] Fix code quality inspection about ambiguous equality --- osu.Game/Overlays/Mods/ModPresetTooltip.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Overlays/Mods/ModPresetTooltip.cs b/osu.Game/Overlays/Mods/ModPresetTooltip.cs index 68da649e81..97d118fbfd 100644 --- a/osu.Game/Overlays/Mods/ModPresetTooltip.cs +++ b/osu.Game/Overlays/Mods/ModPresetTooltip.cs @@ -50,7 +50,7 @@ namespace osu.Game.Overlays.Mods public void SetContent(ModPreset preset) { - if (preset == lastPreset) + if (ReferenceEquals(preset, lastPreset)) return; lastPreset = preset; From 415d6def2d345903a51634ec544c693c46bd3166 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Mon, 1 Aug 2022 13:22:58 +0900 Subject: [PATCH 209/278] Remove unnecessary AsNonNull() --- osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs b/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs index c273da2462..623157a427 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModTarget.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Linq; using osu.Framework.Bindables; -using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; using osu.Framework.Utils; @@ -274,7 +273,7 @@ namespace osu.Game.Rulesets.Osu.Mods { if (hitObjects.Count == 0) return; - float nextSingle(float max = 1f) => (float)(rng.AsNonNull().NextDouble() * max); + float nextSingle(float max = 1f) => (float)(rng.NextDouble() * max); const float two_pi = MathF.PI * 2; From 5b98a73edcb2dc061e0898251098a5de405d5325 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 1 Aug 2022 14:03:57 +0900 Subject: [PATCH 210/278] Apply nullability to `SkinComponentToolbox` and split out reflection method to get all skinnable components --- osu.Game/Screens/Play/HUD/SkinnableInfo.cs | 9 +++++ .../Skinning/Editor/SkinComponentToolbox.cs | 35 ++++++++----------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/osu.Game/Screens/Play/HUD/SkinnableInfo.cs b/osu.Game/Screens/Play/HUD/SkinnableInfo.cs index ee29241321..6d63776dbb 100644 --- a/osu.Game/Screens/Play/HUD/SkinnableInfo.cs +++ b/osu.Game/Screens/Play/HUD/SkinnableInfo.cs @@ -98,5 +98,14 @@ namespace osu.Game.Screens.Play.HUD return Drawable.Empty(); } } + + public static Type[] GetAllAvailableDrawables() + { + return typeof(OsuGame).Assembly.GetTypes() + .Where(t => !t.IsInterface && !t.IsAbstract) + .Where(t => typeof(ISkinnableDrawable).IsAssignableFrom(t)) + .OrderBy(t => t.Name) + .ToArray(); + } } } diff --git a/osu.Game/Skinning/Editor/SkinComponentToolbox.cs b/osu.Game/Skinning/Editor/SkinComponentToolbox.cs index 344a659627..980dee8601 100644 --- a/osu.Game/Skinning/Editor/SkinComponentToolbox.cs +++ b/osu.Game/Skinning/Editor/SkinComponentToolbox.cs @@ -1,11 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Diagnostics; -using System.Linq; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -16,24 +13,25 @@ using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; using osu.Game.Overlays; using osu.Game.Screens.Edit.Components; +using osu.Game.Screens.Play.HUD; using osuTK; namespace osu.Game.Skinning.Editor { public class SkinComponentToolbox : EditorSidebarSection { - public Action RequestPlacement; + public Action? RequestPlacement; - private readonly CompositeDrawable target; + private readonly CompositeDrawable? target; - public SkinComponentToolbox(CompositeDrawable target = null) + private FillFlowContainer fill = null!; + + public SkinComponentToolbox(CompositeDrawable? target = null) : base("Components") { this.target = target; } - private FillFlowContainer fill; - [BackgroundDependencyLoader] private void load() { @@ -52,12 +50,7 @@ namespace osu.Game.Skinning.Editor { fill.Clear(); - var skinnableTypes = typeof(OsuGame).Assembly.GetTypes() - .Where(t => !t.IsInterface && !t.IsAbstract) - .Where(t => typeof(ISkinnableDrawable).IsAssignableFrom(t)) - .OrderBy(t => t.Name) - .ToArray(); - + var skinnableTypes = SkinnableInfo.GetAllAvailableDrawables(); foreach (var type in skinnableTypes) attemptAddComponent(type); } @@ -90,21 +83,21 @@ namespace osu.Game.Skinning.Editor public class ToolboxComponentButton : OsuButton { + public Action? RequestPlacement; + protected override bool ShouldBeConsideredForInput(Drawable child) => false; public override bool PropagateNonPositionalInputSubTree => false; private readonly Drawable component; - private readonly CompositeDrawable dependencySource; + private readonly CompositeDrawable? dependencySource; - public Action RequestPlacement; - - private Container innerContainer; + private Container innerContainer = null!; private const float contracted_size = 60; private const float expanded_size = 120; - public ToolboxComponentButton(Drawable component, CompositeDrawable dependencySource) + public ToolboxComponentButton(Drawable component, CompositeDrawable? dependencySource) { this.component = component; this.dependencySource = dependencySource; @@ -184,9 +177,9 @@ namespace osu.Game.Skinning.Editor public class DependencyBorrowingContainer : Container { - private readonly CompositeDrawable donor; + private readonly CompositeDrawable? donor; - public DependencyBorrowingContainer(CompositeDrawable donor) + public DependencyBorrowingContainer(CompositeDrawable? donor) { this.donor = donor; } From d112743cea7d959a1f1d8e22dc3b58f04aa356aa Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 1 Aug 2022 14:04:06 +0900 Subject: [PATCH 211/278] Improve test coverage of skin serialisation to ensure full coverage Will fail when new skinnable components are added until they have coverage in resources. --- .../Skins/SkinDeserialisationTest.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/osu.Game.Tests/Skins/SkinDeserialisationTest.cs b/osu.Game.Tests/Skins/SkinDeserialisationTest.cs index 699c1bcc2c..2ef8de387b 100644 --- a/osu.Game.Tests/Skins/SkinDeserialisationTest.cs +++ b/osu.Game.Tests/Skins/SkinDeserialisationTest.cs @@ -2,6 +2,7 @@ // 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.Audio.Sample; @@ -12,6 +13,7 @@ using osu.Framework.IO.Stores; using osu.Game.Audio; using osu.Game.IO; using osu.Game.IO.Archives; +using osu.Game.Screens.Play.HUD; using osu.Game.Skinning; using osu.Game.Tests.Resources; @@ -28,6 +30,39 @@ namespace osu.Game.Tests.Skins [TestFixture] public class SkinDeserialisationTest { + private static readonly string[] available_skins = + { + // Covers song progress before namespace changes, and most other components. + "Archives/modified-default-20220723.osk", + "Archives/modified-classic-20220723.osk" + }; + + /// + /// If this test fails, new test resources should be added to include new components. + /// + [Test] + public void TestSkinnableComponentsCoveredByDeserialisationTests() + { + HashSet instantiatedTypes = new HashSet(); + + foreach (string oskFile in available_skins) + { + using (var stream = TestResources.OpenResource(oskFile)) + using (var storage = new ZipArchiveReader(stream)) + { + var skin = new TestSkin(new SkinInfo(), null, storage); + + foreach (var target in skin.DrawableComponentInfo) + { + foreach (var info in target.Value) + instantiatedTypes.Add(info.Type); + } + } + } + + Assert.That(SkinnableInfo.GetAllAvailableDrawables(), Is.EquivalentTo(instantiatedTypes)); + } + [Test] public void TestDeserialiseModifiedDefault() { From 3b6349a14522c7bc7293ead59b47d508fdfa0061 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 1 Aug 2022 14:16:26 +0900 Subject: [PATCH 212/278] Add test coverage of remaining components which weren't already included --- .../Archives/modified-classic-20220801.osk | Bin 0 -> 1182 bytes .../Skins/SkinDeserialisationTest.cs | 20 ++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 osu.Game.Tests/Resources/Archives/modified-classic-20220801.osk diff --git a/osu.Game.Tests/Resources/Archives/modified-classic-20220801.osk b/osu.Game.Tests/Resources/Archives/modified-classic-20220801.osk new file mode 100644 index 0000000000000000000000000000000000000000..9236e1d77f181e680171e0ffb4374f4eb291944d GIT binary patch literal 1182 zcmWIWW@Zs#U|`^2cvrv}`s~Z3;}d|q)nE|@hT`nZJiW}kOxZJre1{Bp94^`}H;C3& z)Vh}EljCEc$Yx%qsI)Qg(TZ0$B`k!(7o`64|Nr}6iR>JCp2f#j1W&N85KT6mv4J7% za*LSFF$-oP!-EFR({?egs(h-r*W|Vsn~rx#qoIqK56@jI)pHYWOt?_+e4V@4If?vt zTRQ&Pe-iZOl$*6g~tTM0A1V##JoTZa&=~2 zTE1RZaekiZ8Aq-|4nU{Z`U`H(TFA4bbhQHOOE(*b8EIY_vmMl3UH0ted-d(}kMmp% z)lm}s4b!&A&e2To4A3|85R#Kx@tt?uQQ2^{?OQL*_RA{&`^|6jO9TeKD;bIXE6aWKM)7!=cNay=A{_}ow0%nVOW!QCnJX)!{_qdIf z`=zrdKL0aY|NQ6mugX8>+r;1Is(sAg@a(&j=0dM8%wBON?+M);XG|_ z?r*Crns(oPU>_58LyhgZRKT{gdrQxTJKdAah|SA$kKJazXrB131IL|Zm8S8niTGud z<TY55_N7#|D5n+C-Z!!>3OA^Zx%oK%C41XQ*elRxvY&D z%UQoemFq$+jdz(Oygg{xUnrw|=*EKonN1OgHmTT|d=_72Z71~g5Q9c{ny=~Nmyd*e zTYo3@nAtD9>8JDSjIY1t@-F$!-yg}hI{&k<5&Yk}sZU=urm%dAvPiq(p-7)abw8I& zsH%8oZc6{D-XSzAHSqs|8y#PIXY((6evy6Wv|Uz3+6i5oM2<)P|7Xr8sA$5)dHP$- z^s?32*BXx5-uFvge@B=9mg3^u{{y@knM4?H=SyIsfPh921T0?;e6D @@ -60,7 +64,9 @@ namespace osu.Game.Tests.Skins } } - Assert.That(SkinnableInfo.GetAllAvailableDrawables(), Is.EquivalentTo(instantiatedTypes)); + var editableTypes = SkinnableInfo.GetAllAvailableDrawables().Where(t => (Activator.CreateInstance(t) as ISkinnableDrawable)?.IsEditable == true); + + Assert.That(instantiatedTypes, Is.EquivalentTo(editableTypes)); } [Test] @@ -94,6 +100,16 @@ namespace osu.Game.Tests.Skins Assert.That(skinnableInfo.Settings.First().Key, Is.EqualTo("sprite_name")); Assert.That(skinnableInfo.Settings.First().Value, Is.EqualTo("ppy_logo-2.png")); } + + using (var stream = TestResources.OpenResource("Archives/modified-classic-20220801.osk")) + using (var storage = new ZipArchiveReader(stream)) + { + var skin = new TestSkin(new SkinInfo(), null, storage); + Assert.That(skin.DrawableComponentInfo[SkinnableTarget.MainHUDComponents], Has.Length.EqualTo(8)); + Assert.That(skin.DrawableComponentInfo[SkinnableTarget.MainHUDComponents].Select(i => i.Type), Contains.Item(typeof(UnstableRateCounter))); + Assert.That(skin.DrawableComponentInfo[SkinnableTarget.MainHUDComponents].Select(i => i.Type), Contains.Item(typeof(ColourHitErrorMeter))); + Assert.That(skin.DrawableComponentInfo[SkinnableTarget.MainHUDComponents].Select(i => i.Type), Contains.Item(typeof(LegacySongProgress))); + } } private class TestSkin : Skin From a5f48e336a2021efd96096ea3b9215b1da0ef004 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 1 Aug 2022 14:38:02 +0900 Subject: [PATCH 213/278] Isolate development builds' storage from release builds --- osu.Desktop/Program.cs | 4 ++++ osu.Game/OsuGameBase.cs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/osu.Desktop/Program.cs b/osu.Desktop/Program.cs index 19cf7f5d46..c7505e624c 100644 --- a/osu.Desktop/Program.cs +++ b/osu.Desktop/Program.cs @@ -21,7 +21,11 @@ namespace osu.Desktop { public static class Program { +#if DEBUG + private const string base_game_name = @"osu-development"; +#else private const string base_game_name = @"osu"; +#endif private static LegacyTcpIpcProvider legacyIpc; diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index c7820d395d..97d15ae6ad 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -212,6 +212,10 @@ namespace osu.Game { Name = @"osu!"; +#if DEBUG + Name += " (development)"; +#endif + allowableExceptions = UnhandledExceptionsBeforeCrash; } From fc8835d43a71b6c1f43eb434eeb60bb850f31913 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 1 Aug 2022 14:58:09 +0900 Subject: [PATCH 214/278] Fix migration failing on single file copy failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No longer throw if copying of single files fails during data migration. Aiming to fix https://github.com/ppy/osu/runs/7601653833?check_suite_focus=true, which could also affect end users. I've left a limit before an exception is still thrown, to handle cases like the user running out of disk space (where we probably *do* want to bail, so they can continue to use their still-intact original storage location). If this isn't seen as a good direction, an alternative will be to make the migration code aware of the structure of the temporary files created by `Storage` (but doesn't guarantee this will cover all cases of such temporary files – there could for isntance be metadata files created by the host operating system). Another option would be to mark those temporary files as hidden and skip any hidden files during iteration. --- osu.Game/IO/MigratableStorage.cs | 34 ++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/osu.Game/IO/MigratableStorage.cs b/osu.Game/IO/MigratableStorage.cs index 30e74adca4..4bc729f429 100644 --- a/osu.Game/IO/MigratableStorage.cs +++ b/osu.Game/IO/MigratableStorage.cs @@ -7,6 +7,7 @@ using System; using System.IO; using System.Linq; using System.Threading; +using osu.Framework.Logging; using osu.Framework.Platform; namespace osu.Game.IO @@ -16,6 +17,12 @@ namespace osu.Game.IO /// public abstract class MigratableStorage : WrappedStorage { + /// + /// The number of file copy failures before actually bailing on migration. + /// This allows some lenience to cover things like temporary files which could not be copied but are also not too important. + /// + private const int allowed_failures = 10; + /// /// A relative list of directory paths which should not be migrated. /// @@ -73,7 +80,7 @@ namespace osu.Game.IO if (topLevelExcludes && IgnoreFiles.Contains(fi.Name)) continue; - allFilesDeleted &= AttemptOperation(() => fi.Delete(), throwOnFailure: false); + allFilesDeleted &= AttemptOperation(() => fi.Delete()); } foreach (DirectoryInfo dir in target.GetDirectories()) @@ -81,16 +88,16 @@ namespace osu.Game.IO if (topLevelExcludes && IgnoreDirectories.Contains(dir.Name)) continue; - allFilesDeleted &= AttemptOperation(() => dir.Delete(true), throwOnFailure: false); + allFilesDeleted &= AttemptOperation(() => dir.Delete(true)); } if (target.GetFiles().Length == 0 && target.GetDirectories().Length == 0) - allFilesDeleted &= AttemptOperation(target.Delete, throwOnFailure: false); + allFilesDeleted &= AttemptOperation(target.Delete); return allFilesDeleted; } - protected void CopyRecursive(DirectoryInfo source, DirectoryInfo destination, bool topLevelExcludes = true) + protected void CopyRecursive(DirectoryInfo source, DirectoryInfo destination, bool topLevelExcludes = true, int totalFailedOperations = 0) { // based off example code https://docs.microsoft.com/en-us/dotnet/api/system.io.directoryinfo if (!destination.Exists) @@ -101,7 +108,14 @@ namespace osu.Game.IO if (topLevelExcludes && IgnoreFiles.Contains(fi.Name)) continue; - AttemptOperation(() => fi.CopyTo(Path.Combine(destination.FullName, fi.Name), true)); + if (!AttemptOperation(() => fi.CopyTo(Path.Combine(destination.FullName, fi.Name), false))) + { + Logger.Log($"Failed to copy file {fi.Name} during folder migration"); + totalFailedOperations++; + + if (totalFailedOperations > allowed_failures) + throw new Exception("Aborting due to too many file copy failures during data migration"); + } } foreach (DirectoryInfo dir in source.GetDirectories()) @@ -109,7 +123,7 @@ namespace osu.Game.IO if (topLevelExcludes && IgnoreDirectories.Contains(dir.Name)) continue; - CopyRecursive(dir, destination.CreateSubdirectory(dir.Name), false); + CopyRecursive(dir, destination.CreateSubdirectory(dir.Name), false, totalFailedOperations); } } @@ -118,8 +132,7 @@ namespace osu.Game.IO /// /// The action to perform. /// The number of attempts (250ms wait between each). - /// Whether to throw an exception on failure. If false, will silently fail. - protected static bool AttemptOperation(Action action, int attempts = 10, bool throwOnFailure = true) + protected static bool AttemptOperation(Action action, int attempts = 10) { while (true) { @@ -131,12 +144,7 @@ namespace osu.Game.IO catch (Exception) { if (attempts-- == 0) - { - if (throwOnFailure) - throw; - return false; - } } Thread.Sleep(250); From 47860bb96606644cfadd5d80eaad7a2245647583 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Mon, 1 Aug 2022 16:33:59 +0900 Subject: [PATCH 215/278] Remove unused using --- osu.Game.Tests/Skins/SkinDeserialisationTest.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game.Tests/Skins/SkinDeserialisationTest.cs b/osu.Game.Tests/Skins/SkinDeserialisationTest.cs index 9181dc80f3..53639deac3 100644 --- a/osu.Game.Tests/Skins/SkinDeserialisationTest.cs +++ b/osu.Game.Tests/Skins/SkinDeserialisationTest.cs @@ -7,7 +7,6 @@ using System.Linq; using NUnit.Framework; using osu.Framework.Audio.Sample; using osu.Framework.Bindables; -using osu.Framework.Graphics; using osu.Framework.Graphics.OpenGL.Textures; using osu.Framework.Graphics.Textures; using osu.Framework.IO.Stores; From 2519706ad612e0297be4b5c8f742150784cf018a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 1 Aug 2022 16:53:47 +0900 Subject: [PATCH 216/278] Add test coverage of editor crash --- .../Editing/TestSceneEditorBeatmapCreation.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs b/osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs index 6ad6f0b299..4baa4af8dd 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs @@ -136,6 +136,20 @@ namespace osu.Game.Tests.Visual.Editing AddAssert("track is not virtual", () => Beatmap.Value.Track is not TrackVirtual); AddAssert("track length changed", () => Beatmap.Value.Track.Length > 60000); + + AddStep("test play", () => Editor.TestGameplay()); + + AddUntilStep("wait for dialog", () => DialogOverlay.CurrentDialog != null); + AddStep("confirm save", () => InputManager.Key(Key.Number1)); + + AddUntilStep("wait for return to editor", () => Editor.IsCurrentScreen()); + + AddAssert("track is still not virtual", () => Beatmap.Value.Track is not TrackVirtual); + AddAssert("track length correct", () => Beatmap.Value.Track.Length > 60000); + + AddUntilStep("track not playing", () => !EditorClock.IsRunning); + AddStep("play track", () => InputManager.Key(Key.Space)); + AddUntilStep("wait for track playing", () => EditorClock.IsRunning); } [Test] From 2f60f91a0ed2173282e1b97c68c76d76a476597d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 1 Aug 2022 16:30:45 +0900 Subject: [PATCH 217/278] Fix editor potentially using a track post-disposal This changes the editor to track the current track as it is *loaded* by `MusicController`, rather than haphazardly following the current global `WorkingBeatmap` (with a potentially unloaded track) or relying on local immediate-load behaviour (as implemented in `ResourcesSection`). --- osu.Game/Overlays/MusicController.cs | 6 +++++- osu.Game/Screens/Edit/Editor.cs | 17 +++++++++++++---- osu.Game/Screens/Edit/Setup/ResourcesSection.cs | 2 -- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 8af295dfe8..da87336039 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -70,7 +70,11 @@ namespace osu.Game.Overlays /// /// Forcefully reload the current 's track from disk. /// - public void ReloadCurrentTrack() => changeTrack(); + public void ReloadCurrentTrack() + { + changeTrack(); + TrackChanged?.Invoke(current, TrackChangeDirection.None); + } /// /// Returns whether the beatmap track is playing. diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index 3e3940c5ba..9e9cd8e3b7 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -329,6 +329,9 @@ namespace osu.Game.Screens.Edit changeHandler?.CanRedo.BindValueChanged(v => redoMenuItem.Action.Disabled = !v.NewValue, true); } + [Resolved] + private MusicController musicController { get; set; } + protected override void LoadComplete() { base.LoadComplete(); @@ -336,12 +339,18 @@ namespace osu.Game.Screens.Edit Mode.Value = isNewBeatmap ? EditorScreenMode.SongSetup : EditorScreenMode.Compose; Mode.BindValueChanged(onModeChanged, true); + + musicController.TrackChanged += onTrackChanged; } - /// - /// If the beatmap's track has changed, this method must be called to keep the editor in a valid state. - /// - public void UpdateClockSource() => clock.ChangeSource(Beatmap.Value.Track); + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + + musicController.TrackChanged -= onTrackChanged; + } + + private void onTrackChanged(WorkingBeatmap working, TrackChangeDirection direction) => clock.ChangeSource(working.Track); /// /// Creates an instance representing the current state of the editor. diff --git a/osu.Game/Screens/Edit/Setup/ResourcesSection.cs b/osu.Game/Screens/Edit/Setup/ResourcesSection.cs index 1f8381e1ed..44bc2126fb 100644 --- a/osu.Game/Screens/Edit/Setup/ResourcesSection.cs +++ b/osu.Game/Screens/Edit/Setup/ResourcesSection.cs @@ -118,8 +118,6 @@ namespace osu.Game.Screens.Edit.Setup working.Value.Metadata.AudioFile = destination.Name; music.ReloadCurrentTrack(); - - editor?.UpdateClockSource(); return true; } From 6e7c298aaf6380032d344474863b73cabaf9342e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 1 Aug 2022 16:36:12 +0900 Subject: [PATCH 218/278] Fix changes to audio / background not triggering an editor state change --- osu.Game/Screens/Edit/Setup/ResourcesSection.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Edit/Setup/ResourcesSection.cs b/osu.Game/Screens/Edit/Setup/ResourcesSection.cs index 44bc2126fb..8c14feebbc 100644 --- a/osu.Game/Screens/Edit/Setup/ResourcesSection.cs +++ b/osu.Game/Screens/Edit/Setup/ResourcesSection.cs @@ -30,8 +30,8 @@ namespace osu.Game.Screens.Edit.Setup [Resolved] private IBindable working { get; set; } - [Resolved(canBeNull: true)] - private Editor editor { get; set; } + [Resolved] + private EditorBeatmap editorBeatmap { get; set; } [Resolved] private SetupScreenHeader header { get; set; } @@ -88,6 +88,8 @@ namespace osu.Game.Screens.Edit.Setup beatmaps.AddFile(set, stream, destination.Name); } + editorBeatmap.SaveState(); + working.Value.Metadata.BackgroundFile = destination.Name; header.Background.UpdateBackground(); @@ -117,7 +119,9 @@ namespace osu.Game.Screens.Edit.Setup working.Value.Metadata.AudioFile = destination.Name; + editorBeatmap.SaveState(); music.ReloadCurrentTrack(); + return true; } From 59210ecc9df96119f70004f68c06f96e9d734e8f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 1 Aug 2022 16:57:50 +0900 Subject: [PATCH 219/278] Revert "Fix migration failing on single file copy failure" This reverts commit fc8835d43a71b6c1f43eb434eeb60bb850f31913. --- osu.Game/IO/MigratableStorage.cs | 34 ++++++++++++-------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/osu.Game/IO/MigratableStorage.cs b/osu.Game/IO/MigratableStorage.cs index 4bc729f429..30e74adca4 100644 --- a/osu.Game/IO/MigratableStorage.cs +++ b/osu.Game/IO/MigratableStorage.cs @@ -7,7 +7,6 @@ using System; using System.IO; using System.Linq; using System.Threading; -using osu.Framework.Logging; using osu.Framework.Platform; namespace osu.Game.IO @@ -17,12 +16,6 @@ namespace osu.Game.IO /// public abstract class MigratableStorage : WrappedStorage { - /// - /// The number of file copy failures before actually bailing on migration. - /// This allows some lenience to cover things like temporary files which could not be copied but are also not too important. - /// - private const int allowed_failures = 10; - /// /// A relative list of directory paths which should not be migrated. /// @@ -80,7 +73,7 @@ namespace osu.Game.IO if (topLevelExcludes && IgnoreFiles.Contains(fi.Name)) continue; - allFilesDeleted &= AttemptOperation(() => fi.Delete()); + allFilesDeleted &= AttemptOperation(() => fi.Delete(), throwOnFailure: false); } foreach (DirectoryInfo dir in target.GetDirectories()) @@ -88,16 +81,16 @@ namespace osu.Game.IO if (topLevelExcludes && IgnoreDirectories.Contains(dir.Name)) continue; - allFilesDeleted &= AttemptOperation(() => dir.Delete(true)); + allFilesDeleted &= AttemptOperation(() => dir.Delete(true), throwOnFailure: false); } if (target.GetFiles().Length == 0 && target.GetDirectories().Length == 0) - allFilesDeleted &= AttemptOperation(target.Delete); + allFilesDeleted &= AttemptOperation(target.Delete, throwOnFailure: false); return allFilesDeleted; } - protected void CopyRecursive(DirectoryInfo source, DirectoryInfo destination, bool topLevelExcludes = true, int totalFailedOperations = 0) + protected void CopyRecursive(DirectoryInfo source, DirectoryInfo destination, bool topLevelExcludes = true) { // based off example code https://docs.microsoft.com/en-us/dotnet/api/system.io.directoryinfo if (!destination.Exists) @@ -108,14 +101,7 @@ namespace osu.Game.IO if (topLevelExcludes && IgnoreFiles.Contains(fi.Name)) continue; - if (!AttemptOperation(() => fi.CopyTo(Path.Combine(destination.FullName, fi.Name), false))) - { - Logger.Log($"Failed to copy file {fi.Name} during folder migration"); - totalFailedOperations++; - - if (totalFailedOperations > allowed_failures) - throw new Exception("Aborting due to too many file copy failures during data migration"); - } + AttemptOperation(() => fi.CopyTo(Path.Combine(destination.FullName, fi.Name), true)); } foreach (DirectoryInfo dir in source.GetDirectories()) @@ -123,7 +109,7 @@ namespace osu.Game.IO if (topLevelExcludes && IgnoreDirectories.Contains(dir.Name)) continue; - CopyRecursive(dir, destination.CreateSubdirectory(dir.Name), false, totalFailedOperations); + CopyRecursive(dir, destination.CreateSubdirectory(dir.Name), false); } } @@ -132,7 +118,8 @@ namespace osu.Game.IO /// /// The action to perform. /// The number of attempts (250ms wait between each). - protected static bool AttemptOperation(Action action, int attempts = 10) + /// Whether to throw an exception on failure. If false, will silently fail. + protected static bool AttemptOperation(Action action, int attempts = 10, bool throwOnFailure = true) { while (true) { @@ -144,7 +131,12 @@ namespace osu.Game.IO catch (Exception) { if (attempts-- == 0) + { + if (throwOnFailure) + throw; + return false; + } } Thread.Sleep(250); From cc8a71b65d52d9fe849fc02434fce58c3be4326d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 1 Aug 2022 17:01:19 +0900 Subject: [PATCH 220/278] Re-query file existence before failing a recursive copy operation during migration --- osu.Game/IO/MigratableStorage.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/osu.Game/IO/MigratableStorage.cs b/osu.Game/IO/MigratableStorage.cs index 30e74adca4..7cd409c04c 100644 --- a/osu.Game/IO/MigratableStorage.cs +++ b/osu.Game/IO/MigratableStorage.cs @@ -96,12 +96,22 @@ namespace osu.Game.IO if (!destination.Exists) Directory.CreateDirectory(destination.FullName); - foreach (System.IO.FileInfo fi in source.GetFiles()) + foreach (System.IO.FileInfo fileInfo in source.GetFiles()) { - if (topLevelExcludes && IgnoreFiles.Contains(fi.Name)) + if (topLevelExcludes && IgnoreFiles.Contains(fileInfo.Name)) continue; - AttemptOperation(() => fi.CopyTo(Path.Combine(destination.FullName, fi.Name), true)); + AttemptOperation(() => + { + fileInfo.Refresh(); + + // A temporary file may have been deleted since the initial GetFiles operation. + // We don't want the whole migration process to fail in such a case. + if (!fileInfo.Exists) + return; + + fileInfo.CopyTo(Path.Combine(destination.FullName, fileInfo.Name), true); + }); } foreach (DirectoryInfo dir in source.GetDirectories()) From ee681139131b1690772e2801b243baeaa8ba8e87 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 1 Aug 2022 17:06:45 +0900 Subject: [PATCH 221/278] Add more missing realm `Refresh()` calls to new beatmap import tests As noticed at https://github.com/ppy/osu/runs/7605101313?check_suite_focus=true --- osu.Game.Tests/Database/BeatmapImporterTests.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/osu.Game.Tests/Database/BeatmapImporterTests.cs b/osu.Game.Tests/Database/BeatmapImporterTests.cs index 0546d3e912..56964aa8b2 100644 --- a/osu.Game.Tests/Database/BeatmapImporterTests.cs +++ b/osu.Game.Tests/Database/BeatmapImporterTests.cs @@ -702,6 +702,8 @@ namespace osu.Game.Tests.Database var firstImport = await importer.Import(new ImportTask(pathMissingOneBeatmap)); Assert.That(firstImport, Is.Not.Null); + realm.Run(r => r.Refresh()); + Assert.That(realm.Realm.All().Where(s => !s.DeletePending), Has.Count.EqualTo(1)); Assert.That(realm.Realm.All().First(s => !s.DeletePending).Beatmaps, Has.Count.EqualTo(11)); @@ -709,6 +711,8 @@ namespace osu.Game.Tests.Database var secondImport = await importer.Import(new ImportTask(pathOriginal)); Assert.That(secondImport, Is.Not.Null); + realm.Run(r => r.Refresh()); + Assert.That(realm.Realm.All(), Has.Count.EqualTo(23)); Assert.That(realm.Realm.All(), Has.Count.EqualTo(2)); From c65747d1b88ee677b6f04e3bb0d36b7cc798539c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gutyina=20Gerg=C5=91?= Date: Mon, 1 Aug 2022 10:36:06 +0200 Subject: [PATCH 222/278] Use masking instead of scrollable container to prevent tags overflow --- osu.Game/Overlays/BeatmapSet/Info.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/BeatmapSet/Info.cs b/osu.Game/Overlays/BeatmapSet/Info.cs index 5517e51515..08423f2aa7 100644 --- a/osu.Game/Overlays/BeatmapSet/Info.cs +++ b/osu.Game/Overlays/BeatmapSet/Info.cs @@ -9,7 +9,6 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Game.Graphics; -using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; using osu.Game.Online.API.Requests.Responses; @@ -63,7 +62,7 @@ namespace osu.Game.Overlays.BeatmapSet Child = new MetadataSection(MetadataType.Description), }, }, - new OsuScrollContainer + new Container { Anchor = Anchor.TopRight, Origin = Anchor.TopRight, @@ -71,6 +70,7 @@ namespace osu.Game.Overlays.BeatmapSet Width = metadata_width, Padding = new MarginPadding { Horizontal = 10 }, Margin = new MarginPadding { Right = BeatmapSetOverlay.RIGHT_WIDTH + spacing }, + Masking = true, Child = new FillFlowContainer { RelativeSizeAxes = Axes.X, From e0940c6c22e28f24d120d764e1c63eb024016f56 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 1 Aug 2022 18:03:32 +0900 Subject: [PATCH 223/278] Update animations to final versions --- .../Skinning/Default/DefaultFollowCircle.cs | 8 +++----- .../Skinning/Legacy/LegacyFollowCircle.cs | 5 +---- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Skinning/Default/DefaultFollowCircle.cs b/osu.Game.Rulesets.Osu/Skinning/Default/DefaultFollowCircle.cs index 3b087245e9..aaace89cd5 100644 --- a/osu.Game.Rulesets.Osu/Skinning/Default/DefaultFollowCircle.cs +++ b/osu.Game.Rulesets.Osu/Skinning/Default/DefaultFollowCircle.cs @@ -59,11 +59,9 @@ namespace osu.Game.Rulesets.Osu.Skinning.Default protected override void OnSliderTick() { - // TODO: Follow circle should bounce on each slider tick. - - // TEMP DUMMY ANIMS - this.ScaleTo(DrawableSliderBall.FOLLOW_AREA * 1.1f) - .ScaleTo(DrawableSliderBall.FOLLOW_AREA, 175f); + this.ScaleTo(DrawableSliderBall.FOLLOW_AREA * 1.08f, 40, Easing.OutQuint) + .Then() + .ScaleTo(DrawableSliderBall.FOLLOW_AREA, 200f, Easing.OutQuint); } protected override void OnSliderBreak() diff --git a/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacyFollowCircle.cs b/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacyFollowCircle.cs index 6d16596ed2..0d12fb01f5 100644 --- a/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacyFollowCircle.cs +++ b/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacyFollowCircle.cs @@ -44,11 +44,8 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy protected override void OnSliderTick() { - // TODO: Follow circle should bounce on each slider tick. - - // TEMP DUMMY ANIMS this.ScaleTo(2.2f) - .ScaleTo(2f, 175f); + .ScaleTo(2f, 200); } protected override void OnSliderBreak() From 3ff0327d91b2217cefe58bd91a1c55ac42b06540 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 1 Aug 2022 14:22:54 +0300 Subject: [PATCH 224/278] Display readable message when reaching download limit --- osu.Game/Database/ModelDownloader.cs | 11 +++++++- .../Database/TooManyDownloadsNotification.cs | 26 +++++++++++++++++++ osu.Game/Localisation/CommonStrings.cs | 7 ++++- 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 osu.Game/Database/TooManyDownloadsNotification.cs diff --git a/osu.Game/Database/ModelDownloader.cs b/osu.Game/Database/ModelDownloader.cs index edb8563c65..5c84e0c308 100644 --- a/osu.Game/Database/ModelDownloader.cs +++ b/osu.Game/Database/ModelDownloader.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net; using System.Threading.Tasks; using Humanizer; using osu.Framework.Logging; @@ -107,7 +108,15 @@ namespace osu.Game.Database notification.State = ProgressNotificationState.Cancelled; if (!(error is OperationCanceledException)) - Logger.Error(error, $"{importer.HumanisedModelName.Titleize()} download failed!"); + { + if (error is WebException webException && webException.Message == @"TooManyRequests") + { + notification.Close(); + PostNotification?.Invoke(new TooManyDownloadsNotification(importer.HumanisedModelName)); + } + else + Logger.Error(error, $"{importer.HumanisedModelName.Titleize()} download failed!"); + } } } diff --git a/osu.Game/Database/TooManyDownloadsNotification.cs b/osu.Game/Database/TooManyDownloadsNotification.cs new file mode 100644 index 0000000000..8adb997999 --- /dev/null +++ b/osu.Game/Database/TooManyDownloadsNotification.cs @@ -0,0 +1,26 @@ +// Copyright (c) ppy Pty Ltd . 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.Sprites; +using osu.Game.Graphics; +using osu.Game.Localisation; +using osu.Game.Overlays.Notifications; + +namespace osu.Game.Database +{ + public class TooManyDownloadsNotification : SimpleNotification + { + public TooManyDownloadsNotification(string humanisedModelName) + { + Text = CommonStrings.TooManyDownloaded(humanisedModelName); + Icon = FontAwesome.Solid.ExclamationCircle; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + IconBackground.Colour = colours.RedDark; + } + } +} diff --git a/osu.Game/Localisation/CommonStrings.cs b/osu.Game/Localisation/CommonStrings.cs index 1ee562e122..7c82ecf926 100644 --- a/osu.Game/Localisation/CommonStrings.cs +++ b/osu.Game/Localisation/CommonStrings.cs @@ -1,4 +1,4 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using osu.Framework.Localisation; @@ -54,6 +54,11 @@ namespace osu.Game.Localisation /// public static LocalisableString Downloading => new TranslatableString(getKey(@"downloading"), @"Downloading..."); + /// + /// "You have downloaded too many {0}s! Please try again later." + /// + public static LocalisableString TooManyDownloaded(string humanisedModelName) => new TranslatableString(getKey(@"too_many_downloaded"), @"You have downloaded too many {0}s! Please try again later.", humanisedModelName); + /// /// "Importing..." /// From 6cccb6b84825dd4f58ddb5d5e8ea679f0a57f4bb Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 1 Aug 2022 19:45:15 +0800 Subject: [PATCH 225/278] Remove `canBeNull: true`. --- osu.Game/Audio/PreviewTrackManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Audio/PreviewTrackManager.cs b/osu.Game/Audio/PreviewTrackManager.cs index a0537d7a4e..b8662b6a4b 100644 --- a/osu.Game/Audio/PreviewTrackManager.cs +++ b/osu.Game/Audio/PreviewTrackManager.cs @@ -87,7 +87,7 @@ namespace osu.Game.Audio public class TrackManagerPreviewTrack : PreviewTrack { - [Resolved(canBeNull: true)] + [Resolved] public IPreviewTrackOwner? Owner { get; private set; } private readonly IBeatmapSetInfo beatmapSetInfo; From a5fac70c3b468b9788d5e783f65fb94ca80fce4e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 1 Aug 2022 23:30:00 +0900 Subject: [PATCH 226/278] Rename variable to not include mode name itself --- osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs index f3d944d55c..3f1c3aa812 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs @@ -27,7 +27,7 @@ namespace osu.Game.Rulesets.Osu.Mods private const int wiggle_duration = 100; // (ms) Higher = fewer wiggles [SettingSource("Strength", "Multiplier applied to the wiggling strength.")] - public BindableDouble WiggleStrength { get; } = new BindableDouble(1) + public BindableDouble Strength { get; } = new BindableDouble(1) { MinValue = 0.1f, MaxValue = 2f, @@ -56,7 +56,7 @@ namespace osu.Game.Rulesets.Osu.Mods void wiggle() { float nextAngle = (float)(objRand.NextDouble() * 2 * Math.PI); - float nextDist = (float)(objRand.NextDouble() * WiggleStrength.Value * 7); + float nextDist = (float)(objRand.NextDouble() * Strength.Value * 7); drawable.MoveTo(new Vector2((float)(nextDist * Math.Cos(nextAngle) + origin.X), (float)(nextDist * Math.Sin(nextAngle) + origin.Y)), wiggle_duration); } From 682192dbd7fc53d8e642d84a3f2c9cf780ec83e4 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 1 Aug 2022 18:43:01 +0300 Subject: [PATCH 227/278] Add failing test case --- .../SongSelect/TestSceneBeatmapCarousel.cs | 53 +++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapCarousel.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapCarousel.cs index 59932f8781..bb9e83a21c 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapCarousel.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapCarousel.cs @@ -486,9 +486,6 @@ namespace osu.Game.Tests.Visual.SongSelect AddAssert("Something is selected", () => carousel.SelectedBeatmapInfo != null); } - /// - /// Test sorting - /// [Test] public void TestSorting() { @@ -517,6 +514,9 @@ namespace osu.Game.Tests.Visual.SongSelect AddAssert($"Check {zzz_string} is at bottom", () => carousel.BeatmapSets.Last().Metadata.Artist == zzz_string); } + /// + /// Ensures stability is maintained on different sort modes for items with equal properties. + /// [Test] public void TestSortingStability() { @@ -549,6 +549,53 @@ namespace osu.Game.Tests.Visual.SongSelect AddAssert("Items reset to original order", () => carousel.BeatmapSets.Select((set, index) => set.OnlineID == idOffset + index).All(b => b)); } + /// + /// Ensures stability is maintained on different sort modes while a new item is added to the carousel. + /// + [Test] + public void TestSortingStabilityWithNewItems() + { + List sets = new List(); + + for (int i = 0; i < 3; i++) + { + var set = TestResources.CreateTestBeatmapSetInfo(3); + + // only need to set the first as they are a shared reference. + var beatmap = set.Beatmaps.First(); + + beatmap.Metadata.Artist = "same artist"; + beatmap.Metadata.Title = "same title"; + + sets.Add(set); + } + + int idOffset = sets.First().OnlineID; + + loadBeatmaps(sets); + + AddStep("Sort by artist", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Artist }, false)); + AddAssert("Items remain in original order", () => carousel.BeatmapSets.Select((set, index) => set.OnlineID == idOffset + index).All(b => b)); + + AddStep("Add new item", () => + { + var set = TestResources.CreateTestBeatmapSetInfo(); + + // only need to set the first as they are a shared reference. + var beatmap = set.Beatmaps.First(); + + beatmap.Metadata.Artist = "same artist"; + beatmap.Metadata.Title = "same title"; + + carousel.UpdateBeatmapSet(set); + }); + + AddAssert("Items remain in original order", () => carousel.BeatmapSets.Select((set, index) => set.OnlineID == idOffset + index).All(b => b)); + + AddStep("Sort by title", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Title }, false)); + AddAssert("Items remain in original order", () => carousel.BeatmapSets.Select((set, index) => set.OnlineID == idOffset + index).All(b => b)); + } + [Test] public void TestSortingWithFiltered() { From 0fcae08d38b055187ccec1ce790f541c2a6411ce Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 1 Aug 2022 23:57:46 +0900 Subject: [PATCH 228/278] Show "locally modified" pill when local modifications have been made --- osu.Game/Beatmaps/BeatmapInfo.cs | 3 ++- osu.Game/Beatmaps/BeatmapManager.cs | 4 ++++ osu.Game/Beatmaps/BeatmapOnlineStatus.cs | 4 ++++ .../Beatmaps/BeatmapUpdaterMetadataLookup.cs | 18 ++++++++++-------- osu.Game/Graphics/OsuColour.cs | 3 +++ 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapInfo.cs b/osu.Game/Beatmaps/BeatmapInfo.cs index f368f369ae..c53c2f67dd 100644 --- a/osu.Game/Beatmaps/BeatmapInfo.cs +++ b/osu.Game/Beatmaps/BeatmapInfo.cs @@ -121,7 +121,8 @@ namespace osu.Game.Beatmaps OnlineID = -1; LastOnlineUpdate = null; OnlineMD5Hash = string.Empty; - Status = BeatmapOnlineStatus.None; + if (Status != BeatmapOnlineStatus.LocallyModified) + Status = BeatmapOnlineStatus.None; } #region Properties we may not want persisted (but also maybe no harm?) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index cf763c53a7..e3d2832108 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -312,6 +312,10 @@ namespace osu.Game.Beatmaps beatmapInfo.MD5Hash = stream.ComputeMD5Hash(); beatmapInfo.Hash = stream.ComputeSHA2Hash(); + beatmapInfo.Status = BeatmapOnlineStatus.LocallyModified; + + if (setInfo.Beatmaps.All(b => b.Status == BeatmapOnlineStatus.LocallyModified)) + setInfo.Status = BeatmapOnlineStatus.LocallyModified; AddFile(setInfo, stream, createBeatmapFilenameFromMetadata(beatmapInfo)); diff --git a/osu.Game/Beatmaps/BeatmapOnlineStatus.cs b/osu.Game/Beatmaps/BeatmapOnlineStatus.cs index ced85e0908..c91b46c92f 100644 --- a/osu.Game/Beatmaps/BeatmapOnlineStatus.cs +++ b/osu.Game/Beatmaps/BeatmapOnlineStatus.cs @@ -3,6 +3,7 @@ #nullable disable +using System.ComponentModel; using osu.Framework.Localisation; using osu.Game.Resources.Localisation.Web; @@ -10,6 +11,9 @@ namespace osu.Game.Beatmaps { public enum BeatmapOnlineStatus { + [Description("Local")] + LocallyModified = -4, + None = -3, [LocalisableDescription(typeof(BeatmapsetsStrings), nameof(BeatmapsetsStrings.ShowStatusGraveyard))] diff --git a/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs b/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs index 02fb69b8f5..f51a8bf7bf 100644 --- a/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs +++ b/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs @@ -89,7 +89,16 @@ namespace osu.Game.Beatmaps if (res != null) { - beatmapInfo.Status = res.Status; + beatmapInfo.OnlineID = res.OnlineID; + beatmapInfo.OnlineMD5Hash = res.MD5Hash; + beatmapInfo.LastOnlineUpdate = res.LastUpdated; + beatmapInfo.Metadata.Author.OnlineID = res.AuthorID; + + // In the case local changes have been applied, don't reset the status. + if (beatmapInfo.MatchesOnlineVersion || beatmapInfo.Status != BeatmapOnlineStatus.LocallyModified) + { + beatmapInfo.Status = res.Status; + } Debug.Assert(beatmapInfo.BeatmapSet != null); @@ -98,13 +107,6 @@ namespace osu.Game.Beatmaps beatmapInfo.BeatmapSet.DateRanked = res.BeatmapSet?.Ranked; beatmapInfo.BeatmapSet.DateSubmitted = res.BeatmapSet?.Submitted; - beatmapInfo.OnlineMD5Hash = res.MD5Hash; - beatmapInfo.LastOnlineUpdate = res.LastUpdated; - - beatmapInfo.OnlineID = res.OnlineID; - - beatmapInfo.Metadata.Author.OnlineID = res.AuthorID; - logForModel(set, $"Online retrieval mapped {beatmapInfo} to {res.OnlineBeatmapSetID} / {res.OnlineID}."); } } diff --git a/osu.Game/Graphics/OsuColour.cs b/osu.Game/Graphics/OsuColour.cs index 0e411876d3..6e2f460930 100644 --- a/osu.Game/Graphics/OsuColour.cs +++ b/osu.Game/Graphics/OsuColour.cs @@ -137,6 +137,9 @@ namespace osu.Game.Graphics { switch (status) { + case BeatmapOnlineStatus.LocallyModified: + return Color4.OrangeRed; + case BeatmapOnlineStatus.Ranked: case BeatmapOnlineStatus.Approved: return Color4Extensions.FromHex(@"b3ff66"); From fc7fc3d673cf0a843d4eeea0225bcde76b987c36 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 1 Aug 2022 19:13:57 +0300 Subject: [PATCH 229/278] Fix newly imported beatmaps not using correct comparer for sorting --- .../Screens/Select/Carousel/CarouselGroup.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/osu.Game/Screens/Select/Carousel/CarouselGroup.cs b/osu.Game/Screens/Select/Carousel/CarouselGroup.cs index 8d141b6f72..9302578038 100644 --- a/osu.Game/Screens/Select/Carousel/CarouselGroup.cs +++ b/osu.Game/Screens/Select/Carousel/CarouselGroup.cs @@ -2,7 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; -using System.Linq; namespace osu.Game.Screens.Select.Carousel { @@ -15,7 +14,7 @@ namespace osu.Game.Screens.Select.Carousel public IReadOnlyList Items => items; - private List items = new List(); + private readonly List items = new List(); /// /// Used to assign a monotonically increasing ID to items as they are added. This member is @@ -24,9 +23,6 @@ namespace osu.Game.Screens.Select.Carousel private ulong currentItemID; private Comparer? criteriaComparer; - - private static readonly Comparer item_id_comparer = Comparer.Create((x, y) => x.ItemID.CompareTo(y.ItemID)); - private FilterCriteria? lastCriteria; protected int GetIndexOfItem(CarouselItem lastSelected) => items.IndexOf(lastSelected); @@ -90,9 +86,16 @@ namespace osu.Game.Screens.Select.Carousel items.ForEach(c => c.Filter(criteria)); - // IEnumerable.OrderBy() is used instead of List.Sort() to ensure sorting stability - criteriaComparer = Comparer.Create((x, y) => x.CompareTo(criteria, y)); - items = items.OrderBy(c => c, criteriaComparer).ThenBy(c => c, item_id_comparer).ToList(); + criteriaComparer = Comparer.Create((x, y) => + { + int comparison = x.CompareTo(criteria, y); + if (comparison != 0) + return comparison; + + return x.ItemID.CompareTo(y.ItemID); + }); + + items.Sort(criteriaComparer); lastCriteria = criteria; } From 1fe7e4d19a51c8cd8a15122ccb8d5b20c0bfb4bd Mon Sep 17 00:00:00 2001 From: andy840119 Date: Tue, 2 Aug 2022 00:45:47 +0800 Subject: [PATCH 230/278] Use non-nullable instead in the catch ruleset. --- osu.Game.Rulesets.Catch/Mods/CatchModFlashlight.cs | 5 ++--- osu.Game.Rulesets.Catch/Mods/CatchModRelax.cs | 5 +---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModFlashlight.cs b/osu.Game.Rulesets.Catch/Mods/CatchModFlashlight.cs index 4824106c55..abe391ba4e 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModFlashlight.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModFlashlight.cs @@ -2,7 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using osu.Framework.Bindables; -using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Game.Configuration; using osu.Game.Rulesets.Catch.Objects; @@ -36,9 +35,9 @@ namespace osu.Game.Rulesets.Catch.Mods public override float DefaultFlashlightSize => 350; - protected override Flashlight CreateFlashlight() => new CatchFlashlight(this, playfield.AsNonNull()); + protected override Flashlight CreateFlashlight() => new CatchFlashlight(this, playfield); - private CatchPlayfield? playfield; + private CatchPlayfield playfield = null!; public override void ApplyToDrawableRuleset(DrawableRuleset drawableRuleset) { diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModRelax.cs b/osu.Game.Rulesets.Catch/Mods/CatchModRelax.cs index 0ab6da0363..60f1614d98 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModRelax.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModRelax.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Diagnostics; using osu.Framework.Graphics; using osu.Framework.Input; using osu.Framework.Input.Bindings; @@ -19,7 +18,7 @@ namespace osu.Game.Rulesets.Catch.Mods { public override string Description => @"Use the mouse to control the catcher."; - private DrawableRuleset? drawableRuleset; + private DrawableRuleset drawableRuleset = null!; public void ApplyToDrawableRuleset(DrawableRuleset drawableRuleset) { @@ -28,8 +27,6 @@ namespace osu.Game.Rulesets.Catch.Mods public void ApplyToPlayer(Player player) { - Debug.Assert(drawableRuleset != null); - if (!drawableRuleset.HasReplayLoaded.Value) drawableRuleset.Cursor.Add(new MouseInputHelper((CatchPlayfield)drawableRuleset.Playfield)); } From b1d320bf6700285957102206ade738b3a6b1d318 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Tue, 2 Aug 2022 00:48:23 +0800 Subject: [PATCH 231/278] Use non-nullable instead in the taiko ruleset. --- osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs | 5 ++--- osu.Game.Rulesets.Taiko/Mods/TaikoModHidden.cs | 4 +--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs index 8872de4d7a..66616486df 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs @@ -2,7 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using osu.Framework.Bindables; -using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Framework.Layout; using osu.Game.Configuration; @@ -37,9 +36,9 @@ namespace osu.Game.Rulesets.Taiko.Mods public override float DefaultFlashlightSize => 250; - protected override Flashlight CreateFlashlight() => new TaikoFlashlight(this, playfield.AsNonNull()); + protected override Flashlight CreateFlashlight() => new TaikoFlashlight(this, playfield); - private TaikoPlayfield? playfield; + private TaikoPlayfield playfield = null!; public override void ApplyToDrawableRuleset(DrawableRuleset drawableRuleset) { diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModHidden.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModHidden.cs index dab2279351..ec39a2b2e5 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModHidden.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModHidden.cs @@ -31,7 +31,7 @@ namespace osu.Game.Rulesets.Taiko.Mods /// private const float fade_out_duration = 0.375f; - private DrawableTaikoRuleset? drawableRuleset; + private DrawableTaikoRuleset drawableRuleset = null!; public void ApplyToDrawableRuleset(DrawableRuleset drawableRuleset) { @@ -45,8 +45,6 @@ namespace osu.Game.Rulesets.Taiko.Mods protected override void ApplyNormalVisibilityState(DrawableHitObject hitObject, ArmedState state) { - Debug.Assert(drawableRuleset != null); - switch (hitObject) { case DrawableDrumRollTick: From 6686b095492abdd1eb0909eea6b57a6c33513b93 Mon Sep 17 00:00:00 2001 From: notmyname <50967056+naipofo@users.noreply.github.com> Date: Mon, 1 Aug 2022 18:54:00 +0200 Subject: [PATCH 232/278] Hide F rank from beatmap overlay --- osu.Game/Overlays/BeatmapListing/BeatmapSearchScoreFilterRow.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Overlays/BeatmapListing/BeatmapSearchScoreFilterRow.cs b/osu.Game/Overlays/BeatmapListing/BeatmapSearchScoreFilterRow.cs index 118ddfb060..09b44be6c9 100644 --- a/osu.Game/Overlays/BeatmapListing/BeatmapSearchScoreFilterRow.cs +++ b/osu.Game/Overlays/BeatmapListing/BeatmapSearchScoreFilterRow.cs @@ -25,7 +25,7 @@ namespace osu.Game.Overlays.BeatmapListing { protected override MultipleSelectionFilterTabItem CreateTabItem(ScoreRank value) => new RankItem(value); - protected override IEnumerable GetValues() => base.GetValues().Reverse(); + protected override IEnumerable GetValues() => base.GetValues().Where(r => r > ScoreRank.F).Reverse(); } private class RankItem : MultipleSelectionFilterTabItem From c851e3d8f3150dc965be7e0c5d20a25a1da44d8e Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 1 Aug 2022 20:08:18 +0300 Subject: [PATCH 233/278] Fix playlist settings reference leak due to unsafe callback binding --- .../OnlinePlay/Playlists/PlaylistsRoomSettingsOverlay.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSettingsOverlay.cs b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSettingsOverlay.cs index 9c6a2a5e0b..a59d37dc8b 100644 --- a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSettingsOverlay.cs +++ b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSettingsOverlay.cs @@ -78,6 +78,8 @@ namespace osu.Game.Screens.OnlinePlay.Playlists [Resolved] private IAPIProvider api { get; set; } + private IBindable localUser; + private readonly Room room; public MatchSettings(Room room) @@ -304,7 +306,8 @@ namespace osu.Game.Screens.OnlinePlay.Playlists MaxAttempts.BindValueChanged(count => MaxAttemptsField.Text = count.NewValue?.ToString(), true); Duration.BindValueChanged(duration => DurationField.Current.Value = duration.NewValue ?? TimeSpan.FromMinutes(30), true); - api.LocalUser.BindValueChanged(populateDurations, true); + localUser = api.LocalUser.GetBoundCopy(); + localUser.BindValueChanged(populateDurations, true); playlist.Items.BindTo(Playlist); Playlist.BindCollectionChanged(onPlaylistChanged, true); From 7e9d11ee2486e04b06f92d3edeb19088ffcf3e68 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 1 Aug 2022 20:15:08 +0300 Subject: [PATCH 234/278] Enable NRT on playlists settings overlay --- .../Playlists/PlaylistsRoomSettingsOverlay.cs | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSettingsOverlay.cs b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSettingsOverlay.cs index a59d37dc8b..cd52981528 100644 --- a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSettingsOverlay.cs +++ b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSettingsOverlay.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Collections.Specialized; using System.Linq; @@ -29,9 +27,9 @@ namespace osu.Game.Screens.OnlinePlay.Playlists { public class PlaylistsRoomSettingsOverlay : RoomSettingsOverlay { - public Action EditPlaylist; + public Action? EditPlaylist; - private MatchSettings settings; + private MatchSettings settings = null!; protected override OsuButton SubmitButton => settings.ApplyButton; @@ -55,30 +53,30 @@ namespace osu.Game.Screens.OnlinePlay.Playlists { private const float disabled_alpha = 0.2f; - public Action EditPlaylist; + public Action? EditPlaylist; - public OsuTextBox NameField, MaxParticipantsField, MaxAttemptsField; - public OsuDropdown DurationField; - public RoomAvailabilityPicker AvailabilityPicker; - public TriangleButton ApplyButton; + public OsuTextBox NameField = null!, MaxParticipantsField = null!, MaxAttemptsField = null!; + public OsuDropdown DurationField = null!; + public RoomAvailabilityPicker AvailabilityPicker = null!; + public TriangleButton ApplyButton = null!; public bool IsLoading => loadingLayer.State.Value == Visibility.Visible; - public OsuSpriteText ErrorText; + public OsuSpriteText ErrorText = null!; - private LoadingLayer loadingLayer; - private DrawableRoomPlaylist playlist; - private OsuSpriteText playlistLength; + private LoadingLayer loadingLayer = null!; + private DrawableRoomPlaylist playlist = null!; + private OsuSpriteText playlistLength = null!; - private PurpleTriangleButton editPlaylistButton; - - [Resolved(CanBeNull = true)] - private IRoomManager manager { get; set; } + private PurpleTriangleButton editPlaylistButton = null!; [Resolved] - private IAPIProvider api { get; set; } + private IRoomManager? manager { get; set; } - private IBindable localUser; + [Resolved] + private IAPIProvider api { get; set; } = null!; + + private IBindable localUser = null!; private readonly Room room; From 7354f9e6ba3c28a27c646409c3a06213155e328e Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 1 Aug 2022 22:05:52 +0300 Subject: [PATCH 235/278] Remove localisation for now --- osu.Game/Database/TooManyDownloadsNotification.cs | 3 +-- osu.Game/Localisation/CommonStrings.cs | 5 ----- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/osu.Game/Database/TooManyDownloadsNotification.cs b/osu.Game/Database/TooManyDownloadsNotification.cs index 8adb997999..c07584c6ec 100644 --- a/osu.Game/Database/TooManyDownloadsNotification.cs +++ b/osu.Game/Database/TooManyDownloadsNotification.cs @@ -4,7 +4,6 @@ using osu.Framework.Allocation; using osu.Framework.Graphics.Sprites; using osu.Game.Graphics; -using osu.Game.Localisation; using osu.Game.Overlays.Notifications; namespace osu.Game.Database @@ -13,7 +12,7 @@ namespace osu.Game.Database { public TooManyDownloadsNotification(string humanisedModelName) { - Text = CommonStrings.TooManyDownloaded(humanisedModelName); + Text = $"You have downloaded too many {humanisedModelName}s! Please try again later."; Icon = FontAwesome.Solid.ExclamationCircle; } diff --git a/osu.Game/Localisation/CommonStrings.cs b/osu.Game/Localisation/CommonStrings.cs index 7c82ecf926..1ffcdc0db2 100644 --- a/osu.Game/Localisation/CommonStrings.cs +++ b/osu.Game/Localisation/CommonStrings.cs @@ -54,11 +54,6 @@ namespace osu.Game.Localisation /// public static LocalisableString Downloading => new TranslatableString(getKey(@"downloading"), @"Downloading..."); - /// - /// "You have downloaded too many {0}s! Please try again later." - /// - public static LocalisableString TooManyDownloaded(string humanisedModelName) => new TranslatableString(getKey(@"too_many_downloaded"), @"You have downloaded too many {0}s! Please try again later.", humanisedModelName); - /// /// "Importing..." /// From 923d9a4e5f19aa10273f99a058b51fcecf5b4757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 1 Aug 2022 22:04:14 +0200 Subject: [PATCH 236/278] Add failing assertions to demonstrate autosize failure --- .../UserInterface/TestSceneShearedButtons.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneShearedButtons.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneShearedButtons.cs index ba9e1c6366..6c485aff34 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneShearedButtons.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneShearedButtons.cs @@ -3,9 +3,13 @@ #nullable disable +using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Graphics; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Testing; +using osu.Framework.Utils; using osu.Game.Graphics.UserInterface; using osu.Game.Overlays; using osuTK.Input; @@ -99,7 +103,10 @@ namespace osu.Game.Tests.Visual.UserInterface Origin = Anchor.Centre, Text = "Fixed width" }); + AddAssert("draw width is 200", () => toggleButton.DrawWidth, () => Is.EqualTo(200).Within(Precision.FLOAT_EPSILON)); + AddStep("change text", () => toggleButton.Text = "New text"); + AddAssert("draw width is 200", () => toggleButton.DrawWidth, () => Is.EqualTo(200).Within(Precision.FLOAT_EPSILON)); AddStep("create auto-sizing button", () => Child = toggleButton = new ShearedToggleButton { @@ -107,7 +114,14 @@ namespace osu.Game.Tests.Visual.UserInterface Origin = Anchor.Centre, Text = "This button autosizes to its text!" }); + AddAssert("button is wider than text", () => toggleButton.DrawWidth, () => Is.GreaterThan(toggleButton.ChildrenOfType().Single().DrawWidth)); + + float originalDrawWidth = 0; + AddStep("store button width", () => originalDrawWidth = toggleButton.DrawWidth); + AddStep("change text", () => toggleButton.Text = "New text"); + AddAssert("button is wider than text", () => toggleButton.DrawWidth, () => Is.GreaterThan(toggleButton.ChildrenOfType().Single().DrawWidth)); + AddAssert("button width decreased", () => toggleButton.DrawWidth, () => Is.LessThan(originalDrawWidth)); } [Test] From 298efa5391734206c8c8d896beb02a940b2b28d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 22 Jul 2022 21:40:24 +0200 Subject: [PATCH 237/278] Fix broken `ShearedButton` autosizing logic --- osu.Game/Graphics/UserInterface/ShearedButton.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/osu.Game/Graphics/UserInterface/ShearedButton.cs b/osu.Game/Graphics/UserInterface/ShearedButton.cs index 259c0646f3..0c25d06cd4 100644 --- a/osu.Game/Graphics/UserInterface/ShearedButton.cs +++ b/osu.Game/Graphics/UserInterface/ShearedButton.cs @@ -97,7 +97,7 @@ namespace osu.Game.Graphics.UserInterface { backgroundLayer = new Container { - RelativeSizeAxes = Axes.Both, + RelativeSizeAxes = Axes.Y, CornerRadius = corner_radius, Masking = true, BorderThickness = 2, @@ -128,10 +128,12 @@ namespace osu.Game.Graphics.UserInterface if (width != null) { Width = width.Value; + backgroundLayer.RelativeSizeAxes = Axes.Both; } else { AutoSizeAxes = Axes.X; + backgroundLayer.AutoSizeAxes = Axes.X; text.Margin = new MarginPadding { Horizontal = 15 }; } } From eb73f9e88c2616bc42ff81a2b5f0e7729a798e9f Mon Sep 17 00:00:00 2001 From: andy840119 Date: Tue, 2 Aug 2022 10:23:52 +0800 Subject: [PATCH 238/278] Remove un-need using. --- osu.Game.Rulesets.Taiko/Mods/TaikoModHidden.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModHidden.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModHidden.cs index ec39a2b2e5..4c802978e3 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModHidden.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModHidden.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Diagnostics; using osu.Framework.Graphics; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Objects; From 4adc8375e927fe0258c64a174ef100fc992a5317 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 2 Aug 2022 12:12:02 +0900 Subject: [PATCH 239/278] Add more xmldoc and avoid `BeatmapSet` status being set when it shouldn't be --- osu.Game/Beatmaps/BeatmapOnlineStatus.cs | 4 ++++ osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapOnlineStatus.cs b/osu.Game/Beatmaps/BeatmapOnlineStatus.cs index c91b46c92f..b78c42022a 100644 --- a/osu.Game/Beatmaps/BeatmapOnlineStatus.cs +++ b/osu.Game/Beatmaps/BeatmapOnlineStatus.cs @@ -11,6 +11,10 @@ namespace osu.Game.Beatmaps { public enum BeatmapOnlineStatus { + /// + /// This is a special status given when local changes are made via the editor. + /// Once in this state, online status changes should be ignored unless the beatmap is reverted or submitted. + /// [Description("Local")] LocallyModified = -4, diff --git a/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs b/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs index f51a8bf7bf..2228281ed3 100644 --- a/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs +++ b/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs @@ -51,6 +51,9 @@ namespace osu.Game.Beatmaps /// /// Queue an update for a beatmap set. /// + /// + /// This may happen during initial import, or at a later stage in response to a user action or server event. + /// /// The beatmap set to update. Updates will be applied directly (so a transaction should be started if this instance is managed). /// Whether metadata from an online source should be preferred. If true, the local cache will be skipped to ensure the freshest data state possible. public void Update(BeatmapSetInfo beatmapSet, bool preferOnlineFetch) @@ -94,15 +97,15 @@ namespace osu.Game.Beatmaps beatmapInfo.LastOnlineUpdate = res.LastUpdated; beatmapInfo.Metadata.Author.OnlineID = res.AuthorID; + Debug.Assert(beatmapInfo.BeatmapSet != null); + // In the case local changes have been applied, don't reset the status. if (beatmapInfo.MatchesOnlineVersion || beatmapInfo.Status != BeatmapOnlineStatus.LocallyModified) { beatmapInfo.Status = res.Status; + beatmapInfo.BeatmapSet.Status = res.BeatmapSet?.Status ?? BeatmapOnlineStatus.None; } - Debug.Assert(beatmapInfo.BeatmapSet != null); - - beatmapInfo.BeatmapSet.Status = res.BeatmapSet?.Status ?? BeatmapOnlineStatus.None; beatmapInfo.BeatmapSet.OnlineID = res.OnlineBeatmapSetID; beatmapInfo.BeatmapSet.DateRanked = res.BeatmapSet?.Ranked; beatmapInfo.BeatmapSet.DateSubmitted = res.BeatmapSet?.Submitted; From 34ffc51c5195196873aefda972549e20b5e1a1f5 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 2 Aug 2022 13:56:02 +0900 Subject: [PATCH 240/278] Avoid clearing chat overlay textbox when pressing "back" key binding Generally this is expected behaviour for usages of focused text boxes (ie. to clear search content), but not so much here. Addresses https://github.com/ppy/osu/discussions/19403#discussioncomment-3230395. --- osu.Game/Graphics/UserInterface/FocusedTextBox.cs | 7 ++++++- osu.Game/Overlays/Chat/ChatTextBox.cs | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/osu.Game/Graphics/UserInterface/FocusedTextBox.cs b/osu.Game/Graphics/UserInterface/FocusedTextBox.cs index fce4221c87..230d921c68 100644 --- a/osu.Game/Graphics/UserInterface/FocusedTextBox.cs +++ b/osu.Game/Graphics/UserInterface/FocusedTextBox.cs @@ -21,6 +21,11 @@ namespace osu.Game.Graphics.UserInterface private bool allowImmediateFocus => host?.OnScreenKeyboardOverlapsGameWindow != true; + /// + /// Whether the content of the text box should be cleared on the first "back" key press. + /// + protected virtual bool ClearTextOnBackKey => true; + public void TakeFocus() { if (!allowImmediateFocus) @@ -78,7 +83,7 @@ namespace osu.Game.Graphics.UserInterface if (!HasFocus) return false; - if (e.Action == GlobalAction.Back) + if (ClearTextOnBackKey && e.Action == GlobalAction.Back) { if (Text.Length > 0) { diff --git a/osu.Game/Overlays/Chat/ChatTextBox.cs b/osu.Game/Overlays/Chat/ChatTextBox.cs index ae8816b009..887eb96c15 100644 --- a/osu.Game/Overlays/Chat/ChatTextBox.cs +++ b/osu.Game/Overlays/Chat/ChatTextBox.cs @@ -13,6 +13,8 @@ namespace osu.Game.Overlays.Chat public override bool HandleLeftRightArrows => !ShowSearch.Value; + protected override bool ClearTextOnBackKey => false; + protected override void LoadComplete() { base.LoadComplete(); From df76f9f4dae2c7cd5842801332bd50b772b3ec2e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 2 Aug 2022 15:49:22 +0900 Subject: [PATCH 241/278] Fix some additional metadata being updated when it shouldn't (with local changes) --- .../Beatmaps/BeatmapUpdaterMetadataLookup.cs | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs b/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs index 2228281ed3..9d17e36812 100644 --- a/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs +++ b/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs @@ -95,20 +95,21 @@ namespace osu.Game.Beatmaps beatmapInfo.OnlineID = res.OnlineID; beatmapInfo.OnlineMD5Hash = res.MD5Hash; beatmapInfo.LastOnlineUpdate = res.LastUpdated; - beatmapInfo.Metadata.Author.OnlineID = res.AuthorID; Debug.Assert(beatmapInfo.BeatmapSet != null); + beatmapInfo.BeatmapSet.OnlineID = res.OnlineBeatmapSetID; - // In the case local changes have been applied, don't reset the status. + // Some metadata should only be applied if there's no local changes. if (beatmapInfo.MatchesOnlineVersion || beatmapInfo.Status != BeatmapOnlineStatus.LocallyModified) { beatmapInfo.Status = res.Status; - beatmapInfo.BeatmapSet.Status = res.BeatmapSet?.Status ?? BeatmapOnlineStatus.None; - } - beatmapInfo.BeatmapSet.OnlineID = res.OnlineBeatmapSetID; - beatmapInfo.BeatmapSet.DateRanked = res.BeatmapSet?.Ranked; - beatmapInfo.BeatmapSet.DateSubmitted = res.BeatmapSet?.Submitted; + beatmapInfo.Metadata.Author.OnlineID = res.AuthorID; + + beatmapInfo.BeatmapSet.Status = res.BeatmapSet?.Status ?? BeatmapOnlineStatus.None; + beatmapInfo.BeatmapSet.DateRanked = res.BeatmapSet?.Ranked; + beatmapInfo.BeatmapSet.DateSubmitted = res.BeatmapSet?.Submitted; + } logForModel(set, $"Online retrieval mapped {beatmapInfo} to {res.OnlineBeatmapSetID} / {res.OnlineID}."); } @@ -209,17 +210,21 @@ namespace osu.Game.Beatmaps beatmapInfo.Status = status; - Debug.Assert(beatmapInfo.BeatmapSet != null); - - beatmapInfo.BeatmapSet.Status = status; - beatmapInfo.BeatmapSet.OnlineID = reader.GetInt32(0); // TODO: DateSubmitted and DateRanked are not provided by local cache. beatmapInfo.OnlineID = reader.GetInt32(1); - beatmapInfo.Metadata.Author.OnlineID = reader.GetInt32(3); - beatmapInfo.OnlineMD5Hash = reader.GetString(4); beatmapInfo.LastOnlineUpdate = reader.GetDateTimeOffset(5); + Debug.Assert(beatmapInfo.BeatmapSet != null); + beatmapInfo.BeatmapSet.OnlineID = reader.GetInt32(0); + + // Some metadata should only be applied if there's no local changes. + if (beatmapInfo.MatchesOnlineVersion || beatmapInfo.Status != BeatmapOnlineStatus.LocallyModified) + { + beatmapInfo.BeatmapSet.Status = status; + beatmapInfo.Metadata.Author.OnlineID = reader.GetInt32(3); + } + logForModel(set, $"Cached local retrieval for {beatmapInfo}."); return true; } From 8cb02f47eb6b8108c9f61de61f0187b80baebb64 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 2 Aug 2022 15:50:16 +0900 Subject: [PATCH 242/278] Mark `BeatmapSet.Status` as modified when any beatmap is modified, rather than all --- osu.Game/Beatmaps/BeatmapManager.cs | 5 ++--- .../Beatmaps/BeatmapUpdaterMetadataLookup.cs | 16 +++++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index e3d2832108..b6bfab32cd 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -312,14 +312,13 @@ namespace osu.Game.Beatmaps beatmapInfo.MD5Hash = stream.ComputeMD5Hash(); beatmapInfo.Hash = stream.ComputeSHA2Hash(); - beatmapInfo.Status = BeatmapOnlineStatus.LocallyModified; - if (setInfo.Beatmaps.All(b => b.Status == BeatmapOnlineStatus.LocallyModified)) - setInfo.Status = BeatmapOnlineStatus.LocallyModified; + beatmapInfo.Status = BeatmapOnlineStatus.LocallyModified; AddFile(setInfo, stream, createBeatmapFilenameFromMetadata(beatmapInfo)); setInfo.Hash = beatmapImporter.ComputeHash(setInfo); + setInfo.Status = BeatmapOnlineStatus.LocallyModified; Realm.Write(r => { diff --git a/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs b/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs index 9d17e36812..3238863700 100644 --- a/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs +++ b/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs @@ -6,6 +6,7 @@ using System; using System.Diagnostics; using System.IO; +using System.Linq; using System.Threading.Tasks; using Microsoft.Data.Sqlite; using osu.Framework.Development; @@ -103,9 +104,11 @@ namespace osu.Game.Beatmaps if (beatmapInfo.MatchesOnlineVersion || beatmapInfo.Status != BeatmapOnlineStatus.LocallyModified) { beatmapInfo.Status = res.Status; - beatmapInfo.Metadata.Author.OnlineID = res.AuthorID; + } + if (beatmapInfo.BeatmapSet.Beatmaps.All(b => b.MatchesOnlineVersion || b.Status != BeatmapOnlineStatus.LocallyModified)) + { beatmapInfo.BeatmapSet.Status = res.BeatmapSet?.Status ?? BeatmapOnlineStatus.None; beatmapInfo.BeatmapSet.DateRanked = res.BeatmapSet?.Ranked; beatmapInfo.BeatmapSet.DateSubmitted = res.BeatmapSet?.Submitted; @@ -208,7 +211,12 @@ namespace osu.Game.Beatmaps { var status = (BeatmapOnlineStatus)reader.GetByte(2); - beatmapInfo.Status = status; + // Some metadata should only be applied if there's no local changes. + if (beatmapInfo.MatchesOnlineVersion || beatmapInfo.Status != BeatmapOnlineStatus.LocallyModified) + { + beatmapInfo.Status = status; + beatmapInfo.Metadata.Author.OnlineID = reader.GetInt32(3); + } // TODO: DateSubmitted and DateRanked are not provided by local cache. beatmapInfo.OnlineID = reader.GetInt32(1); @@ -218,11 +226,9 @@ namespace osu.Game.Beatmaps Debug.Assert(beatmapInfo.BeatmapSet != null); beatmapInfo.BeatmapSet.OnlineID = reader.GetInt32(0); - // Some metadata should only be applied if there's no local changes. - if (beatmapInfo.MatchesOnlineVersion || beatmapInfo.Status != BeatmapOnlineStatus.LocallyModified) + if (beatmapInfo.BeatmapSet.Beatmaps.All(b => b.MatchesOnlineVersion || b.Status != BeatmapOnlineStatus.LocallyModified)) { beatmapInfo.BeatmapSet.Status = status; - beatmapInfo.Metadata.Author.OnlineID = reader.GetInt32(3); } logForModel(set, $"Cached local retrieval for {beatmapInfo}."); From 7022c6382dfd200974d3ef871beb01dab0eeac94 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 2 Aug 2022 16:30:14 +0900 Subject: [PATCH 243/278] Add localisation support for local modification strings --- osu.Game/Beatmaps/BeatmapOnlineStatus.cs | 2 ++ .../Drawables/BeatmapSetOnlineStatusPill.cs | 19 ++++++++++++++- osu.Game/Localisation/SongSelectStrings.cs | 24 +++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 osu.Game/Localisation/SongSelectStrings.cs diff --git a/osu.Game/Beatmaps/BeatmapOnlineStatus.cs b/osu.Game/Beatmaps/BeatmapOnlineStatus.cs index b78c42022a..cdd99d4432 100644 --- a/osu.Game/Beatmaps/BeatmapOnlineStatus.cs +++ b/osu.Game/Beatmaps/BeatmapOnlineStatus.cs @@ -5,6 +5,7 @@ using System.ComponentModel; using osu.Framework.Localisation; +using osu.Game.Localisation; using osu.Game.Resources.Localisation.Web; namespace osu.Game.Beatmaps @@ -16,6 +17,7 @@ namespace osu.Game.Beatmaps /// Once in this state, online status changes should be ignored unless the beatmap is reverted or submitted. /// [Description("Local")] + [LocalisableDescription(typeof(SongSelectStrings), nameof(SongSelectStrings.LocallyModified))] LocallyModified = -4, None = -3, diff --git a/osu.Game/Beatmaps/Drawables/BeatmapSetOnlineStatusPill.cs b/osu.Game/Beatmaps/Drawables/BeatmapSetOnlineStatusPill.cs index 88d4991c5d..23d90ab76e 100644 --- a/osu.Game/Beatmaps/Drawables/BeatmapSetOnlineStatusPill.cs +++ b/osu.Game/Beatmaps/Drawables/BeatmapSetOnlineStatusPill.cs @@ -6,15 +6,18 @@ using osu.Framework.Extensions; using osu.Framework.Extensions.LocalisationExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Shapes; +using osu.Framework.Localisation; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; +using osu.Game.Localisation; using osu.Game.Overlays; using osuTK.Graphics; namespace osu.Game.Beatmaps.Drawables { - public class BeatmapSetOnlineStatusPill : CircularContainer + public class BeatmapSetOnlineStatusPill : CircularContainer, IHasTooltip { private BeatmapOnlineStatus status; @@ -96,5 +99,19 @@ namespace osu.Game.Beatmaps.Drawables background.Colour = OsuColour.ForBeatmapSetOnlineStatus(Status) ?? colourProvider?.Light1 ?? colours.GreySeaFoamLighter; } + + public LocalisableString TooltipText + { + get + { + switch (Status) + { + case BeatmapOnlineStatus.LocallyModified: + return SongSelectStrings.LocallyModifiedTooltip; + } + + return string.Empty; + } + } } } diff --git a/osu.Game/Localisation/SongSelectStrings.cs b/osu.Game/Localisation/SongSelectStrings.cs new file mode 100644 index 0000000000..12f70cd967 --- /dev/null +++ b/osu.Game/Localisation/SongSelectStrings.cs @@ -0,0 +1,24 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Localisation; + +namespace osu.Game.Localisation +{ + public static class SongSelectStrings + { + private const string prefix = @"osu.Game.Resources.Localisation.SongSelect"; + + /// + /// "Local" + /// + public static LocalisableString LocallyModified => new TranslatableString(getKey(@"locally_modified"), @"Local"); + + /// + /// "Has been locally modified" + /// + public static LocalisableString LocallyModifiedTooltip => new TranslatableString(getKey(@"locally_modified_tooltip"), @"Has been locally modified"); + + private static string getKey(string key) => $@"{prefix}:{key}"; + } +} From cc4cde2c7978a4e474eb1a606995cde6b7d28841 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 2 Aug 2022 17:54:42 +0900 Subject: [PATCH 244/278] Improve `IBeatSyncProvider` interface and reduce beatmap track dependence --- osu.Game/Beatmaps/IBeatSyncProvider.cs | 17 ++- .../Containers/BeatSyncedContainer.cs | 23 ++-- osu.Game/OsuGameBase.cs | 2 +- osu.Game/Screens/Edit/Editor.cs | 3 +- osu.Game/Screens/Menu/LogoVisualisation.cs | 111 +++++++++--------- .../Play/MasterGameplayClockContainer.cs | 20 ++-- 6 files changed, 88 insertions(+), 88 deletions(-) diff --git a/osu.Game/Beatmaps/IBeatSyncProvider.cs b/osu.Game/Beatmaps/IBeatSyncProvider.cs index 362f02f2dd..b0b265c228 100644 --- a/osu.Game/Beatmaps/IBeatSyncProvider.cs +++ b/osu.Game/Beatmaps/IBeatSyncProvider.cs @@ -2,7 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using osu.Framework.Allocation; -using osu.Framework.Audio.Track; +using osu.Framework.Audio; using osu.Framework.Timing; using osu.Game.Beatmaps.ControlPoints; using osu.Game.Graphics.Containers; @@ -14,12 +14,21 @@ namespace osu.Game.Beatmaps /// Primarily intended for use with . /// [Cached] - public interface IBeatSyncProvider + public interface IBeatSyncProvider : IHasAmplitudes { + /// + /// Check whether beat sync is currently available. + /// + public bool BeatSyncAvailable => Clock != null; + + /// + /// Access any available control points from a beatmap providing beat sync. If null, no current provider is available. + /// ControlPointInfo? ControlPoints { get; } + /// + /// Access a clock currently responsible for providing beat sync. If null, no current provider is available. + /// IClock? Clock { get; } - - ChannelAmplitudes? Amplitudes { get; } } } diff --git a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs index e1998a1d7f..774468c344 100644 --- a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs +++ b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Diagnostics; using osu.Framework.Allocation; @@ -10,13 +8,12 @@ using osu.Framework.Audio.Track; using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; -using osu.Game.Screens.Play; namespace osu.Game.Graphics.Containers { /// /// A container which fires a callback when a new beat is reached. - /// Consumes a parent or (whichever is first available). + /// Consumes a parent . /// /// /// This container does not set its own clock to the source used for beat matching. @@ -28,8 +25,9 @@ namespace osu.Game.Graphics.Containers public class BeatSyncedContainer : Container { private int lastBeat; - protected TimingControlPoint LastTimingPoint { get; private set; } - protected EffectControlPoint LastEffectPoint { get; private set; } + + protected TimingControlPoint? LastTimingPoint { get; private set; } + protected EffectControlPoint? LastEffectPoint { get; private set; } /// /// The amount of time before a beat we should fire . @@ -71,12 +69,12 @@ namespace osu.Game.Graphics.Containers public double MinimumBeatLength { get; set; } /// - /// Whether this container is currently tracking a beatmap's timing data. + /// Whether this container is currently tracking a beat sync provider. /// protected bool IsBeatSyncedWithTrack { get; private set; } [Resolved] - protected IBeatSyncProvider BeatSyncSource { get; private set; } + protected IBeatSyncProvider BeatSyncSource { get; private set; } = null!; protected virtual void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, ChannelAmplitudes amplitudes) { @@ -87,19 +85,18 @@ namespace osu.Game.Graphics.Containers TimingControlPoint timingPoint; EffectControlPoint effectPoint; - IsBeatSyncedWithTrack = BeatSyncSource.Clock?.IsRunning == true && BeatSyncSource.ControlPoints != null; + IsBeatSyncedWithTrack = BeatSyncSource.BeatSyncAvailable && BeatSyncSource.Clock?.IsRunning == true; double currentTrackTime; if (IsBeatSyncedWithTrack) { - Debug.Assert(BeatSyncSource.ControlPoints != null); Debug.Assert(BeatSyncSource.Clock != null); currentTrackTime = BeatSyncSource.Clock.CurrentTime + EarlyActivationMilliseconds; - timingPoint = BeatSyncSource.ControlPoints.TimingPointAt(currentTrackTime); - effectPoint = BeatSyncSource.ControlPoints.EffectPointAt(currentTrackTime); + timingPoint = BeatSyncSource.ControlPoints?.TimingPointAt(currentTrackTime) ?? TimingControlPoint.DEFAULT; + effectPoint = BeatSyncSource.ControlPoints?.EffectPointAt(currentTrackTime) ?? EffectControlPoint.DEFAULT; } else { @@ -136,7 +133,7 @@ namespace osu.Game.Graphics.Containers if (AllowMistimedEventFiring || Math.Abs(TimeSinceLastBeat) < MISTIMED_ALLOWANCE) { using (BeginDelayedSequence(-TimeSinceLastBeat)) - OnNewBeat(beatIndex, timingPoint, effectPoint, BeatSyncSource.Amplitudes ?? ChannelAmplitudes.Empty); + OnNewBeat(beatIndex, timingPoint, effectPoint, BeatSyncSource.CurrentAmplitudes); } lastBeat = beatIndex; diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 97d15ae6ad..f62349c447 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -588,6 +588,6 @@ namespace osu.Game ControlPointInfo IBeatSyncProvider.ControlPoints => Beatmap.Value.BeatmapLoaded ? Beatmap.Value.Beatmap.ControlPointInfo : null; IClock IBeatSyncProvider.Clock => Beatmap.Value.TrackLoaded ? Beatmap.Value.Track : (IClock)null; - ChannelAmplitudes? IBeatSyncProvider.Amplitudes => Beatmap.Value.TrackLoaded ? Beatmap.Value.Track.CurrentAmplitudes : null; + ChannelAmplitudes IHasAmplitudes.CurrentAmplitudes => Beatmap.Value.TrackLoaded ? Beatmap.Value.Track.CurrentAmplitudes : ChannelAmplitudes.Empty; } } diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index 9e9cd8e3b7..89f9aec5ee 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -10,6 +10,7 @@ using System.Linq; using JetBrains.Annotations; using osu.Framework; using osu.Framework.Allocation; +using osu.Framework.Audio; using osu.Framework.Audio.Track; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -949,7 +950,7 @@ namespace osu.Game.Screens.Edit ControlPointInfo IBeatSyncProvider.ControlPoints => editorBeatmap.ControlPointInfo; IClock IBeatSyncProvider.Clock => clock; - ChannelAmplitudes? IBeatSyncProvider.Amplitudes => Beatmap.Value.TrackLoaded ? Beatmap.Value.Track.CurrentAmplitudes : null; + ChannelAmplitudes IHasAmplitudes.CurrentAmplitudes => Beatmap.Value.TrackLoaded ? Beatmap.Value.Track.CurrentAmplitudes : ChannelAmplitudes.Empty; private class BeatmapEditorToast : Toast { diff --git a/osu.Game/Screens/Menu/LogoVisualisation.cs b/osu.Game/Screens/Menu/LogoVisualisation.cs index c66bd3639a..c238bf8a21 100644 --- a/osu.Game/Screens/Menu/LogoVisualisation.cs +++ b/osu.Game/Screens/Menu/LogoVisualisation.cs @@ -1,10 +1,12 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - -using osuTK; -using osuTK.Graphics; +using System; +using System.Collections.Generic; +using osu.Framework.Allocation; +using osu.Framework.Audio; +using osu.Framework.Audio.Track; +using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Batches; using osu.Framework.Graphics.Colour; @@ -12,16 +14,10 @@ using osu.Framework.Graphics.OpenGL.Vertices; using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Shaders; using osu.Framework.Graphics.Textures; -using osu.Game.Beatmaps; -using System; -using System.Collections.Generic; -using JetBrains.Annotations; -using osu.Framework.Allocation; -using osu.Framework.Audio; -using osu.Framework.Audio.Track; -using osu.Framework.Bindables; using osu.Framework.Utils; -using osu.Framework.Extensions.Color4Extensions; +using osu.Game.Beatmaps; +using osuTK; +using osuTK.Graphics; namespace osu.Game.Screens.Menu { @@ -30,8 +26,6 @@ namespace osu.Game.Screens.Menu /// public class LogoVisualisation : Drawable { - private readonly IBindable beatmap = new Bindable(); - /// /// The number of bars to jump each update iteration. /// @@ -76,7 +70,8 @@ namespace osu.Game.Screens.Menu private readonly float[] frequencyAmplitudes = new float[256]; - private IShader shader; + private IShader shader = null!; + private readonly Texture texture; public LogoVisualisation() @@ -93,32 +88,35 @@ namespace osu.Game.Screens.Menu } [BackgroundDependencyLoader] - private void load(ShaderManager shaders, IBindable beatmap) + private void load(ShaderManager shaders) { - this.beatmap.BindTo(beatmap); shader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, FragmentShaderDescriptor.TEXTURE_ROUNDED); } private readonly float[] temporalAmplitudes = new float[ChannelAmplitudes.AMPLITUDES_SIZE]; + [Resolved] + private IBeatSyncProvider beatSyncProvider { get; set; } = null!; + private void updateAmplitudes() { - var effect = beatmap.Value.BeatmapLoaded && beatmap.Value.TrackLoaded - ? beatmap.Value.Beatmap?.ControlPointInfo.EffectPointAt(beatmap.Value.Track.CurrentTime) - : null; + bool isKiaiTime = false; for (int i = 0; i < temporalAmplitudes.Length; i++) temporalAmplitudes[i] = 0; - if (beatmap.Value.TrackLoaded) - addAmplitudesFromSource(beatmap.Value.Track); + if (beatSyncProvider.Clock != null) + { + isKiaiTime = beatSyncProvider.ControlPoints?.EffectPointAt(beatSyncProvider.Clock.CurrentTime).KiaiMode ?? false; + addAmplitudesFromSource(beatSyncProvider); + } foreach (var source in amplitudeSources) addAmplitudesFromSource(source); for (int i = 0; i < bars_per_visualiser; i++) { - float targetAmplitude = (temporalAmplitudes[(i + indexOffset) % bars_per_visualiser]) * (effect?.KiaiMode == true ? 1 : 0.5f); + float targetAmplitude = (temporalAmplitudes[(i + indexOffset) % bars_per_visualiser]) * (isKiaiTime ? 1 : 0.5f); if (targetAmplitude > frequencyAmplitudes[i]) frequencyAmplitudes[i] = targetAmplitude; } @@ -153,7 +151,7 @@ namespace osu.Game.Screens.Menu protected override DrawNode CreateDrawNode() => new VisualisationDrawNode(this); - private void addAmplitudesFromSource([NotNull] IHasAmplitudes source) + private void addAmplitudesFromSource(IHasAmplitudes source) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -170,8 +168,8 @@ namespace osu.Game.Screens.Menu { protected new LogoVisualisation Source => (LogoVisualisation)base.Source; - private IShader shader; - private Texture texture; + private IShader shader = null!; + private Texture texture = null!; // Assuming the logo is a circle, we don't need a second dimension. private float size; @@ -209,43 +207,40 @@ namespace osu.Game.Screens.Menu ColourInfo colourInfo = DrawColourInfo.Colour; colourInfo.ApplyChild(transparent_white); - if (audioData != null) + for (int j = 0; j < visualiser_rounds; j++) { - for (int j = 0; j < visualiser_rounds; j++) + for (int i = 0; i < bars_per_visualiser; i++) { - for (int i = 0; i < bars_per_visualiser; i++) - { - if (audioData[i] < amplitude_dead_zone) - continue; + if (audioData[i] < amplitude_dead_zone) + continue; - float rotation = MathUtils.DegreesToRadians(i / (float)bars_per_visualiser * 360 + j * 360 / visualiser_rounds); - float rotationCos = MathF.Cos(rotation); - float rotationSin = MathF.Sin(rotation); - // taking the cos and sin to the 0..1 range - var barPosition = new Vector2(rotationCos / 2 + 0.5f, rotationSin / 2 + 0.5f) * size; + float rotation = MathUtils.DegreesToRadians(i / (float)bars_per_visualiser * 360 + j * 360 / visualiser_rounds); + float rotationCos = MathF.Cos(rotation); + float rotationSin = MathF.Sin(rotation); + // taking the cos and sin to the 0..1 range + var barPosition = new Vector2(rotationCos / 2 + 0.5f, rotationSin / 2 + 0.5f) * size; - var barSize = new Vector2(size * MathF.Sqrt(2 * (1 - MathF.Cos(MathUtils.DegreesToRadians(360f / bars_per_visualiser)))) / 2f, bar_length * audioData[i]); - // The distance between the position and the sides of the bar. - var bottomOffset = new Vector2(-rotationSin * barSize.X / 2, rotationCos * barSize.X / 2); - // The distance between the bottom side of the bar and the top side. - var amplitudeOffset = new Vector2(rotationCos * barSize.Y, rotationSin * barSize.Y); + var barSize = new Vector2(size * MathF.Sqrt(2 * (1 - MathF.Cos(MathUtils.DegreesToRadians(360f / bars_per_visualiser)))) / 2f, bar_length * audioData[i]); + // The distance between the position and the sides of the bar. + var bottomOffset = new Vector2(-rotationSin * barSize.X / 2, rotationCos * barSize.X / 2); + // The distance between the bottom side of the bar and the top side. + var amplitudeOffset = new Vector2(rotationCos * barSize.Y, rotationSin * barSize.Y); - var rectangle = new Quad( - Vector2Extensions.Transform(barPosition - bottomOffset, DrawInfo.Matrix), - Vector2Extensions.Transform(barPosition - bottomOffset + amplitudeOffset, DrawInfo.Matrix), - Vector2Extensions.Transform(barPosition + bottomOffset, DrawInfo.Matrix), - Vector2Extensions.Transform(barPosition + bottomOffset + amplitudeOffset, DrawInfo.Matrix) - ); + var rectangle = new Quad( + Vector2Extensions.Transform(barPosition - bottomOffset, DrawInfo.Matrix), + Vector2Extensions.Transform(barPosition - bottomOffset + amplitudeOffset, DrawInfo.Matrix), + Vector2Extensions.Transform(barPosition + bottomOffset, DrawInfo.Matrix), + Vector2Extensions.Transform(barPosition + bottomOffset + amplitudeOffset, DrawInfo.Matrix) + ); - DrawQuad( - texture, - rectangle, - colourInfo, - null, - vertexBatch.AddAction, - // barSize by itself will make it smooth more in the X axis than in the Y axis, this reverts that. - Vector2.Divide(inflation, barSize.Yx)); - } + DrawQuad( + texture, + rectangle, + colourInfo, + null, + vertexBatch.AddAction, + // barSize by itself will make it smooth more in the X axis than in the Y axis, this reverts that. + Vector2.Divide(inflation, barSize.Yx)); } } diff --git a/osu.Game/Screens/Play/MasterGameplayClockContainer.cs b/osu.Game/Screens/Play/MasterGameplayClockContainer.cs index cd37c541ec..d7f6992fee 100644 --- a/osu.Game/Screens/Play/MasterGameplayClockContainer.cs +++ b/osu.Game/Screens/Play/MasterGameplayClockContainer.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Collections.Generic; using System.Linq; @@ -53,21 +51,21 @@ namespace osu.Game.Screens.Play private readonly WorkingBeatmap beatmap; - private HardwareCorrectionOffsetClock userGlobalOffsetClock; - private HardwareCorrectionOffsetClock userBeatmapOffsetClock; - private HardwareCorrectionOffsetClock platformOffsetClock; - private MasterGameplayClock masterGameplayClock; - private Bindable userAudioOffset; + private HardwareCorrectionOffsetClock userGlobalOffsetClock = null!; + private HardwareCorrectionOffsetClock userBeatmapOffsetClock = null!; + private HardwareCorrectionOffsetClock platformOffsetClock = null!; + private MasterGameplayClock masterGameplayClock = null!; + private Bindable userAudioOffset = null!; - private IDisposable beatmapOffsetSubscription; + private IDisposable? beatmapOffsetSubscription; private readonly double skipTargetTime; [Resolved] - private RealmAccess realm { get; set; } + private RealmAccess realm { get; set; } = null!; [Resolved] - private OsuConfigManager config { get; set; } + private OsuConfigManager config { get; set; } = null!; /// /// Create a new master gameplay clock container. @@ -255,7 +253,7 @@ namespace osu.Game.Screens.Play ControlPointInfo IBeatSyncProvider.ControlPoints => beatmap.Beatmap.ControlPointInfo; IClock IBeatSyncProvider.Clock => GameplayClock; - ChannelAmplitudes? IBeatSyncProvider.Amplitudes => beatmap.TrackLoaded ? beatmap.Track.CurrentAmplitudes : null; + ChannelAmplitudes IHasAmplitudes.CurrentAmplitudes => beatmap.TrackLoaded ? beatmap.Track.CurrentAmplitudes : ChannelAmplitudes.Empty; private class HardwareCorrectionOffsetClock : FramedOffsetClock { From 258ad7c6b90dbe06f8d4e6c6ae5e28ca2d6a5b40 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 2 Aug 2022 18:18:40 +0900 Subject: [PATCH 245/278] Tidy up kiai time access --- osu.Game/Beatmaps/IBeatSyncProvider.cs | 5 +++++ .../Graphics/Containers/BeatSyncedContainer.cs | 14 +++++++++----- osu.Game/Screens/Menu/LogoVisualisation.cs | 7 +------ osu.Game/Screens/Menu/OsuLogo.cs | 2 +- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/osu.Game/Beatmaps/IBeatSyncProvider.cs b/osu.Game/Beatmaps/IBeatSyncProvider.cs index b0b265c228..485497a8f0 100644 --- a/osu.Game/Beatmaps/IBeatSyncProvider.cs +++ b/osu.Game/Beatmaps/IBeatSyncProvider.cs @@ -21,6 +21,11 @@ namespace osu.Game.Beatmaps /// public bool BeatSyncAvailable => Clock != null; + /// + /// Whether the beat sync provider is currently in a kiai section. Should make everything more epic. + /// + public bool IsKiaiTime => Clock != null && (ControlPoints?.EffectPointAt(Clock.CurrentTime).KiaiMode ?? false); + /// /// Access any available control points from a beatmap providing beat sync. If null, no current provider is available. /// diff --git a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs index 774468c344..c8ea21e139 100644 --- a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs +++ b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs @@ -26,8 +26,10 @@ namespace osu.Game.Graphics.Containers { private int lastBeat; - protected TimingControlPoint? LastTimingPoint { get; private set; } - protected EffectControlPoint? LastEffectPoint { get; private set; } + private TimingControlPoint? lastTimingPoint { get; set; } + private EffectControlPoint? lastEffectPoint { get; set; } + + public bool IsKiaiTime { get; private set; } /// /// The amount of time before a beat we should fire . @@ -125,7 +127,7 @@ namespace osu.Game.Graphics.Containers TimeSinceLastBeat = beatLength - TimeUntilNextBeat; - if (ReferenceEquals(timingPoint, LastTimingPoint) && beatIndex == lastBeat) + if (ReferenceEquals(timingPoint, lastTimingPoint) && beatIndex == lastBeat) return; // as this event is sometimes used for sound triggers where `BeginDelayedSequence` has no effect, avoid firing it if too far away from the beat. @@ -137,8 +139,10 @@ namespace osu.Game.Graphics.Containers } lastBeat = beatIndex; - LastTimingPoint = timingPoint; - LastEffectPoint = effectPoint; + lastTimingPoint = timingPoint; + lastEffectPoint = effectPoint; + + IsKiaiTime = lastEffectPoint?.KiaiMode ?? false; } } } diff --git a/osu.Game/Screens/Menu/LogoVisualisation.cs b/osu.Game/Screens/Menu/LogoVisualisation.cs index c238bf8a21..e9f52e0b9f 100644 --- a/osu.Game/Screens/Menu/LogoVisualisation.cs +++ b/osu.Game/Screens/Menu/LogoVisualisation.cs @@ -100,23 +100,18 @@ namespace osu.Game.Screens.Menu private void updateAmplitudes() { - bool isKiaiTime = false; - for (int i = 0; i < temporalAmplitudes.Length; i++) temporalAmplitudes[i] = 0; if (beatSyncProvider.Clock != null) - { - isKiaiTime = beatSyncProvider.ControlPoints?.EffectPointAt(beatSyncProvider.Clock.CurrentTime).KiaiMode ?? false; addAmplitudesFromSource(beatSyncProvider); - } foreach (var source in amplitudeSources) addAmplitudesFromSource(source); for (int i = 0; i < bars_per_visualiser; i++) { - float targetAmplitude = (temporalAmplitudes[(i + indexOffset) % bars_per_visualiser]) * (isKiaiTime ? 1 : 0.5f); + float targetAmplitude = (temporalAmplitudes[(i + indexOffset) % bars_per_visualiser]) * (beatSyncProvider.IsKiaiTime ? 1 : 0.5f); if (targetAmplitude > frequencyAmplitudes[i]) frequencyAmplitudes[i] = targetAmplitude; } diff --git a/osu.Game/Screens/Menu/OsuLogo.cs b/osu.Game/Screens/Menu/OsuLogo.cs index 0909f615f2..e9b50f94f7 100644 --- a/osu.Game/Screens/Menu/OsuLogo.cs +++ b/osu.Game/Screens/Menu/OsuLogo.cs @@ -353,7 +353,7 @@ namespace osu.Game.Screens.Menu float maxAmplitude = lastBeatIndex >= 0 ? musicController.CurrentTrack.CurrentAmplitudes.Maximum : 0; logoAmplitudeContainer.Scale = new Vector2((float)Interpolation.Damp(logoAmplitudeContainer.Scale.X, 1 - Math.Max(0, maxAmplitude - scale_adjust_cutoff) * 0.04f, 0.9f, Time.Elapsed)); - triangles.Velocity = (float)Interpolation.Damp(triangles.Velocity, triangles_paused_velocity * (LastEffectPoint.KiaiMode ? 4 : 2), 0.995f, Time.Elapsed); + triangles.Velocity = (float)Interpolation.Damp(triangles.Velocity, triangles_paused_velocity * (IsKiaiTime ? 4 : 2), 0.995f, Time.Elapsed); } else { From 78cc28d75f49eb7f7b6007278169d39473e37272 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Tue, 2 Aug 2022 22:23:54 +0800 Subject: [PATCH 246/278] Remove nullable disable annotation and fix the api broken. --- osu.Desktop/DiscordRichPresence.cs | 14 ++++++-------- .../LegacyIpcDifficultyCalculationRequest.cs | 2 -- .../LegacyIpcDifficultyCalculationResponse.cs | 2 -- osu.Desktop/LegacyIpc/LegacyIpcMessage.cs | 2 -- osu.Desktop/Program.cs | 4 +--- osu.Desktop/Security/ElevatedPrivilegesChecker.cs | 4 +--- osu.Desktop/Updater/SquirrelUpdateManager.cs | 12 +++++------- osu.Desktop/Windows/GameplayWinKeyBlocker.cs | 10 ++++------ osu.Desktop/Windows/WindowsKey.cs | 4 +--- 9 files changed, 18 insertions(+), 36 deletions(-) diff --git a/osu.Desktop/DiscordRichPresence.cs b/osu.Desktop/DiscordRichPresence.cs index d0b6953c30..13c6440599 100644 --- a/osu.Desktop/DiscordRichPresence.cs +++ b/osu.Desktop/DiscordRichPresence.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Text; using DiscordRPC; @@ -26,15 +24,15 @@ namespace osu.Desktop { private const string client_id = "367827983903490050"; - private DiscordRpcClient client; + private DiscordRpcClient client = null!; [Resolved] - private IBindable ruleset { get; set; } + private IBindable ruleset { get; set; } = null!; - private IBindable user; + private IBindable user = null!; [Resolved] - private IAPIProvider api { get; set; } + private IAPIProvider api { get; set; } = null!; private readonly IBindable status = new Bindable(); private readonly IBindable activity = new Bindable(); @@ -130,7 +128,7 @@ namespace osu.Desktop presence.Assets.LargeImageText = string.Empty; else { - if (user.Value.RulesetsStatistics != null && user.Value.RulesetsStatistics.TryGetValue(ruleset.Value.ShortName, out UserStatistics statistics)) + if (user.Value.RulesetsStatistics != null && user.Value.RulesetsStatistics.TryGetValue(ruleset.Value.ShortName, out UserStatistics? statistics)) presence.Assets.LargeImageText = $"{user.Value.Username}" + (statistics.GlobalRank > 0 ? $" (rank #{statistics.GlobalRank:N0})" : string.Empty); else presence.Assets.LargeImageText = $"{user.Value.Username}" + (user.Value.Statistics?.GlobalRank > 0 ? $" (rank #{user.Value.Statistics.GlobalRank:N0})" : string.Empty); @@ -164,7 +162,7 @@ namespace osu.Desktop }); } - private IBeatmapInfo getBeatmap(UserActivity activity) + private IBeatmapInfo? getBeatmap(UserActivity activity) { switch (activity) { diff --git a/osu.Desktop/LegacyIpc/LegacyIpcDifficultyCalculationRequest.cs b/osu.Desktop/LegacyIpc/LegacyIpcDifficultyCalculationRequest.cs index 7b0bd69363..d6ef390a8f 100644 --- a/osu.Desktop/LegacyIpc/LegacyIpcDifficultyCalculationRequest.cs +++ b/osu.Desktop/LegacyIpc/LegacyIpcDifficultyCalculationRequest.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - namespace osu.Desktop.LegacyIpc { /// diff --git a/osu.Desktop/LegacyIpc/LegacyIpcDifficultyCalculationResponse.cs b/osu.Desktop/LegacyIpc/LegacyIpcDifficultyCalculationResponse.cs index 6d36cbc4b6..7b9fae5797 100644 --- a/osu.Desktop/LegacyIpc/LegacyIpcDifficultyCalculationResponse.cs +++ b/osu.Desktop/LegacyIpc/LegacyIpcDifficultyCalculationResponse.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - namespace osu.Desktop.LegacyIpc { /// diff --git a/osu.Desktop/LegacyIpc/LegacyIpcMessage.cs b/osu.Desktop/LegacyIpc/LegacyIpcMessage.cs index 4df477191d..0fa60e2068 100644 --- a/osu.Desktop/LegacyIpc/LegacyIpcMessage.cs +++ b/osu.Desktop/LegacyIpc/LegacyIpcMessage.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Platform; using Newtonsoft.Json.Linq; diff --git a/osu.Desktop/Program.cs b/osu.Desktop/Program.cs index c7505e624c..5a1373e040 100644 --- a/osu.Desktop/Program.cs +++ b/osu.Desktop/Program.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.IO; using System.Runtime.Versioning; @@ -27,7 +25,7 @@ namespace osu.Desktop private const string base_game_name = @"osu"; #endif - private static LegacyTcpIpcProvider legacyIpc; + private static LegacyTcpIpcProvider? legacyIpc; [STAThread] public static void Main(string[] args) diff --git a/osu.Desktop/Security/ElevatedPrivilegesChecker.cs b/osu.Desktop/Security/ElevatedPrivilegesChecker.cs index f0d95ba194..9959b24b35 100644 --- a/osu.Desktop/Security/ElevatedPrivilegesChecker.cs +++ b/osu.Desktop/Security/ElevatedPrivilegesChecker.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Security.Principal; using osu.Framework; @@ -21,7 +19,7 @@ namespace osu.Desktop.Security public class ElevatedPrivilegesChecker : Component { [Resolved] - private INotificationOverlay notifications { get; set; } + private INotificationOverlay notifications { get; set; } = null!; private bool elevated; diff --git a/osu.Desktop/Updater/SquirrelUpdateManager.cs b/osu.Desktop/Updater/SquirrelUpdateManager.cs index 4e5f8d37b1..64872de3f1 100644 --- a/osu.Desktop/Updater/SquirrelUpdateManager.cs +++ b/osu.Desktop/Updater/SquirrelUpdateManager.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Runtime.Versioning; using System.Threading.Tasks; @@ -26,8 +24,8 @@ namespace osu.Desktop.Updater [SupportedOSPlatform("windows")] public class SquirrelUpdateManager : osu.Game.Updater.UpdateManager { - private UpdateManager updateManager; - private INotificationOverlay notificationOverlay; + private UpdateManager? updateManager; + private INotificationOverlay notificationOverlay = null!; public Task PrepareUpdateAsync() => UpdateManager.RestartAppWhenExited(); @@ -50,12 +48,12 @@ namespace osu.Desktop.Updater protected override async Task PerformUpdateCheck() => await checkForUpdateAsync().ConfigureAwait(false); - private async Task checkForUpdateAsync(bool useDeltaPatching = true, UpdateProgressNotification notification = null) + private async Task checkForUpdateAsync(bool useDeltaPatching = true, UpdateProgressNotification? notification = null) { // should we schedule a retry on completion of this check? bool scheduleRecheck = true; - const string github_token = null; // TODO: populate. + const string? github_token = null; // TODO: populate. try { @@ -145,7 +143,7 @@ namespace osu.Desktop.Updater private class UpdateCompleteNotification : ProgressCompletionNotification { [Resolved] - private OsuGame game { get; set; } + private OsuGame game { get; set; } = null!; public UpdateCompleteNotification(SquirrelUpdateManager updateManager) { diff --git a/osu.Desktop/Windows/GameplayWinKeyBlocker.cs b/osu.Desktop/Windows/GameplayWinKeyBlocker.cs index 0cb4ba9c04..284d25306d 100644 --- a/osu.Desktop/Windows/GameplayWinKeyBlocker.cs +++ b/osu.Desktop/Windows/GameplayWinKeyBlocker.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -14,12 +12,12 @@ namespace osu.Desktop.Windows { public class GameplayWinKeyBlocker : Component { - private Bindable disableWinKey; - private IBindable localUserPlaying; - private IBindable isActive; + private Bindable disableWinKey = null!; + private IBindable localUserPlaying = null!; + private IBindable isActive = null!; [Resolved] - private GameHost host { get; set; } + private GameHost host { get; set; } = null!; [BackgroundDependencyLoader] private void load(ILocalUserPlayInfo localUserInfo, OsuConfigManager config) diff --git a/osu.Desktop/Windows/WindowsKey.cs b/osu.Desktop/Windows/WindowsKey.cs index c69cce6200..1051e61f2f 100644 --- a/osu.Desktop/Windows/WindowsKey.cs +++ b/osu.Desktop/Windows/WindowsKey.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Runtime.InteropServices; @@ -21,7 +19,7 @@ namespace osu.Desktop.Windows private const int wm_syskeyup = 261; //Resharper disable once NotAccessedField.Local - private static LowLevelKeyboardProcDelegate keyboardHookDelegate; // keeping a reference alive for the GC + private static LowLevelKeyboardProcDelegate? keyboardHookDelegate; // keeping a reference alive for the GC private static IntPtr keyHook; [StructLayout(LayoutKind.Explicit)] From 11a4bb58335a15b236a3f12c6bd44982a9ef6d20 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Tue, 2 Aug 2022 22:24:22 +0800 Subject: [PATCH 247/278] Prevent return the null value. --- osu.Desktop/DiscordRichPresence.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Desktop/DiscordRichPresence.cs b/osu.Desktop/DiscordRichPresence.cs index 13c6440599..9cf68d88d9 100644 --- a/osu.Desktop/DiscordRichPresence.cs +++ b/osu.Desktop/DiscordRichPresence.cs @@ -181,10 +181,10 @@ namespace osu.Desktop switch (activity) { case UserActivity.InGame game: - return game.BeatmapInfo.ToString(); + return game.BeatmapInfo.ToString() ?? string.Empty; case UserActivity.Editing edit: - return edit.BeatmapInfo.ToString(); + return edit.BeatmapInfo.ToString() ?? string.Empty; case UserActivity.InLobby lobby: return privacyMode.Value == DiscordRichPresenceMode.Limited ? string.Empty : lobby.Room.Name.Value; From 13b2441c5145504b21c3e8038f0f7c38763b6670 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Tue, 2 Aug 2022 22:29:27 +0800 Subject: [PATCH 248/278] give the field a default value. --- osu.Desktop/LegacyIpc/LegacyIpcDifficultyCalculationRequest.cs | 2 +- osu.Desktop/LegacyIpc/LegacyIpcMessage.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Desktop/LegacyIpc/LegacyIpcDifficultyCalculationRequest.cs b/osu.Desktop/LegacyIpc/LegacyIpcDifficultyCalculationRequest.cs index d6ef390a8f..0ad68919a2 100644 --- a/osu.Desktop/LegacyIpc/LegacyIpcDifficultyCalculationRequest.cs +++ b/osu.Desktop/LegacyIpc/LegacyIpcDifficultyCalculationRequest.cs @@ -11,7 +11,7 @@ namespace osu.Desktop.LegacyIpc /// public class LegacyIpcDifficultyCalculationRequest { - public string BeatmapFile { get; set; } + public string BeatmapFile { get; set; } = string.Empty; public int RulesetId { get; set; } public int Mods { get; set; } } diff --git a/osu.Desktop/LegacyIpc/LegacyIpcMessage.cs b/osu.Desktop/LegacyIpc/LegacyIpcMessage.cs index 0fa60e2068..865d1aa60c 100644 --- a/osu.Desktop/LegacyIpc/LegacyIpcMessage.cs +++ b/osu.Desktop/LegacyIpc/LegacyIpcMessage.cs @@ -46,7 +46,7 @@ namespace osu.Desktop.LegacyIpc public class Data { - public string MessageType { get; set; } + public string MessageType { get; set; } = string.Empty; public object MessageData { get; set; } } } From c8c2758d63fc13e6eedfeab60798fa4e6feff7a9 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Tue, 2 Aug 2022 23:02:14 +0800 Subject: [PATCH 249/278] give the object a default value(null). --- osu.Desktop/LegacyIpc/LegacyIpcMessage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Desktop/LegacyIpc/LegacyIpcMessage.cs b/osu.Desktop/LegacyIpc/LegacyIpcMessage.cs index 865d1aa60c..76eb6cdbd1 100644 --- a/osu.Desktop/LegacyIpc/LegacyIpcMessage.cs +++ b/osu.Desktop/LegacyIpc/LegacyIpcMessage.cs @@ -47,7 +47,7 @@ namespace osu.Desktop.LegacyIpc public class Data { public string MessageType { get; set; } = string.Empty; - public object MessageData { get; set; } + public object MessageData { get; set; } = default!; } } } From 8d175bc40201efeb34b907f2d3e950c1bcce2a1a Mon Sep 17 00:00:00 2001 From: andy840119 Date: Tue, 2 Aug 2022 23:13:50 +0800 Subject: [PATCH 250/278] Remove the null check. --- osu.Desktop/Updater/SquirrelUpdateManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Desktop/Updater/SquirrelUpdateManager.cs b/osu.Desktop/Updater/SquirrelUpdateManager.cs index 64872de3f1..d53db6c516 100644 --- a/osu.Desktop/Updater/SquirrelUpdateManager.cs +++ b/osu.Desktop/Updater/SquirrelUpdateManager.cs @@ -152,7 +152,7 @@ namespace osu.Desktop.Updater Activated = () => { updateManager.PrepareUpdateAsync() - .ContinueWith(_ => updateManager.Schedule(() => game?.AttemptExit())); + .ContinueWith(_ => updateManager.Schedule(() => game.AttemptExit())); return true; }; } From 085080576a2ce78b0f0547fc45fa52f2ece37a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 22 Jul 2022 21:17:27 +0200 Subject: [PATCH 251/278] Add button for creating new mod presets --- .../UserInterface/ShearedToggleButton.cs | 6 +-- osu.Game/Overlays/Mods/AddPresetButton.cs | 38 +++++++++++++++++++ osu.Game/Overlays/Mods/ModPresetColumn.cs | 9 ++++- osu.Game/Overlays/Mods/ModSelectPanel.cs | 3 +- 4 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 osu.Game/Overlays/Mods/AddPresetButton.cs diff --git a/osu.Game/Graphics/UserInterface/ShearedToggleButton.cs b/osu.Game/Graphics/UserInterface/ShearedToggleButton.cs index 0bbcb2b976..9ef09d799e 100644 --- a/osu.Game/Graphics/UserInterface/ShearedToggleButton.cs +++ b/osu.Game/Graphics/UserInterface/ShearedToggleButton.cs @@ -49,15 +49,15 @@ namespace osu.Game.Graphics.UserInterface Active.BindDisabledChanged(disabled => Action = disabled ? null : Active.Toggle, true); Active.BindValueChanged(_ => { - updateActiveState(); + UpdateActiveState(); playSample(); }); - updateActiveState(); + UpdateActiveState(); base.LoadComplete(); } - private void updateActiveState() + protected virtual void UpdateActiveState() { DarkerColour = Active.Value ? ColourProvider.Highlight1 : ColourProvider.Background3; LighterColour = Active.Value ? ColourProvider.Colour0 : ColourProvider.Background1; diff --git a/osu.Game/Overlays/Mods/AddPresetButton.cs b/osu.Game/Overlays/Mods/AddPresetButton.cs new file mode 100644 index 0000000000..e73ee3956a --- /dev/null +++ b/osu.Game/Overlays/Mods/AddPresetButton.cs @@ -0,0 +1,38 @@ +// Copyright (c) ppy Pty Ltd . 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.Game.Graphics; +using osu.Game.Graphics.UserInterface; +using osuTK; + +namespace osu.Game.Overlays.Mods +{ + public class AddPresetButton : ShearedToggleButton + { + [Resolved] + private OsuColour colours { get; set; } = null!; + + public AddPresetButton() + : base(1) + { + RelativeSizeAxes = Axes.X; + Height = ModSelectPanel.HEIGHT; + + // shear will be applied at a higher level in `ModPresetColumn`. + Content.Shear = Vector2.Zero; + Padding = new MarginPadding(); + + Text = "+"; + TextSize = 30; + } + + protected override void UpdateActiveState() + { + DarkerColour = Active.Value ? colours.Orange1 : ColourProvider.Background3; + LighterColour = Active.Value ? colours.Orange0 : ColourProvider.Background1; + TextColour = Active.Value ? ColourProvider.Background6 : ColourProvider.Content1; + } + } +} diff --git a/osu.Game/Overlays/Mods/ModPresetColumn.cs b/osu.Game/Overlays/Mods/ModPresetColumn.cs index bed4cff0ea..7f453637e7 100644 --- a/osu.Game/Overlays/Mods/ModPresetColumn.cs +++ b/osu.Game/Overlays/Mods/ModPresetColumn.cs @@ -31,6 +31,10 @@ namespace osu.Game.Overlays.Mods { AccentColour = colours.Orange1; HeaderText = ModSelectOverlayStrings.PersonalPresets; + + AddPresetButton addPresetButton; + ItemsFlow.Add(addPresetButton = new AddPresetButton()); + ItemsFlow.SetLayoutPosition(addPresetButton, float.PositiveInfinity); } protected override void LoadComplete() @@ -64,7 +68,7 @@ namespace osu.Game.Overlays.Mods if (!presets.Any()) { - ItemsFlow.Clear(); + ItemsFlow.RemoveAll(panel => panel is ModPresetPanel); return; } @@ -77,7 +81,8 @@ namespace osu.Game.Overlays.Mods latestLoadTask = loadTask = LoadComponentsAsync(panels, loaded => { - ItemsFlow.ChildrenEnumerable = loaded; + ItemsFlow.RemoveAll(panel => panel is ModPresetPanel); + ItemsFlow.AddRange(loaded); }, (cancellationTokenSource = new CancellationTokenSource()).Token); loadTask.ContinueWith(_ => { diff --git a/osu.Game/Overlays/Mods/ModSelectPanel.cs b/osu.Game/Overlays/Mods/ModSelectPanel.cs index abf327a388..b3df00f8f9 100644 --- a/osu.Game/Overlays/Mods/ModSelectPanel.cs +++ b/osu.Game/Overlays/Mods/ModSelectPanel.cs @@ -43,8 +43,7 @@ namespace osu.Game.Overlays.Mods } public const float CORNER_RADIUS = 7; - - protected const float HEIGHT = 42; + public const float HEIGHT = 42; protected virtual float IdleSwitchWidth => 14; protected virtual float ExpandedSwitchWidth => 30; From 1b3074d0981a38b87a10215c048faa5d4e1a4472 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 22 Jul 2022 21:42:42 +0200 Subject: [PATCH 252/278] Implement popover for creating mod presets --- .../UserInterface/TestSceneModPresetColumn.cs | 32 ++++---- osu.Game/Overlays/Mods/AddPresetButton.cs | 75 ++++++++++++++++++- 2 files changed, 90 insertions(+), 17 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs index 593c8abac4..d76ff3f332 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs @@ -9,6 +9,7 @@ using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Testing; +using osu.Framework.Graphics.Cursor; using osu.Game.Overlays; using osu.Game.Overlays.Mods; using osu.Game.Rulesets; @@ -22,6 +23,9 @@ namespace osu.Game.Tests.Visual.UserInterface { protected override bool UseFreshStoragePerRun => true; + private Container content = null!; + protected override Container Content => content; + private RulesetStore rulesets = null!; [Cached] @@ -32,6 +36,12 @@ namespace osu.Game.Tests.Visual.UserInterface { Dependencies.Cache(rulesets = new RealmRulesetStore(Realm)); Dependencies.Cache(Realm); + + base.Content.Add(content = new PopoverContainer + { + RelativeSizeAxes = Axes.Both, + Padding = new MarginPadding(30), + }); } [SetUpSteps] @@ -57,15 +67,10 @@ namespace osu.Game.Tests.Visual.UserInterface public void TestBasicOperation() { AddStep("set osu! ruleset", () => Ruleset.Value = rulesets.GetRuleset(0)); - AddStep("create content", () => Child = new Container + AddStep("create content", () => Child = new ModPresetColumn { - RelativeSizeAxes = Axes.Both, - Padding = new MarginPadding(30), - Child = new ModPresetColumn - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - } + Anchor = Anchor.Centre, + Origin = Anchor.Centre, }); AddUntilStep("3 panels visible", () => this.ChildrenOfType().Count() == 3); @@ -112,15 +117,10 @@ namespace osu.Game.Tests.Visual.UserInterface public void TestSoftDeleteSupport() { AddStep("set osu! ruleset", () => Ruleset.Value = rulesets.GetRuleset(0)); - AddStep("create content", () => Child = new Container + AddStep("create content", () => Child = new ModPresetColumn { - RelativeSizeAxes = Axes.Both, - Padding = new MarginPadding(30), - Child = new ModPresetColumn - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - } + Anchor = Anchor.Centre, + Origin = Anchor.Centre, }); AddUntilStep("3 panels visible", () => this.ChildrenOfType().Count() == 3); diff --git a/osu.Game/Overlays/Mods/AddPresetButton.cs b/osu.Game/Overlays/Mods/AddPresetButton.cs index e73ee3956a..00343ac851 100644 --- a/osu.Game/Overlays/Mods/AddPresetButton.cs +++ b/osu.Game/Overlays/Mods/AddPresetButton.cs @@ -2,14 +2,20 @@ // See the LICENCE file in the repository root for full licence text. using osu.Framework.Allocation; +using osu.Framework.Bindables; +using osu.Framework.Extensions; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Cursor; +using osu.Framework.Graphics.UserInterface; using osu.Game.Graphics; using osu.Game.Graphics.UserInterface; +using osu.Game.Graphics.UserInterfaceV2; using osuTK; namespace osu.Game.Overlays.Mods { - public class AddPresetButton : ShearedToggleButton + public class AddPresetButton : ShearedToggleButton, IHasPopover { [Resolved] private OsuColour colours { get; set; } = null!; @@ -33,6 +39,73 @@ namespace osu.Game.Overlays.Mods DarkerColour = Active.Value ? colours.Orange1 : ColourProvider.Background3; LighterColour = Active.Value ? colours.Orange0 : ColourProvider.Background1; TextColour = Active.Value ? ColourProvider.Background6 : ColourProvider.Content1; + + if (Active.Value) + this.ShowPopover(); + else + this.HidePopover(); + } + + public Popover GetPopover() => new AddPresetPopover(this); + + private class AddPresetPopover : OsuPopover + { + private readonly AddPresetButton button; + + private readonly LabelledTextBox nameTextBox; + private readonly LabelledTextBox descriptionTextBox; + private readonly ShearedButton createButton; + + public AddPresetPopover(AddPresetButton addPresetButton) + { + button = addPresetButton; + + Child = new FillFlowContainer + { + Width = 300, + AutoSizeAxes = Axes.Y, + Spacing = new Vector2(7), + Children = new Drawable[] + { + nameTextBox = new LabelledTextBox + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Label = "Name", + TabbableContentContainer = this + }, + descriptionTextBox = new LabelledTextBox + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Label = "Description", + TabbableContentContainer = this + }, + createButton = new ShearedButton + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Text = "Create preset", + Action = this.HidePopover + } + } + }; + } + + [BackgroundDependencyLoader] + private void load(OverlayColourProvider colourProvider, OsuColour colours) + { + createButton.DarkerColour = colours.Orange1; + createButton.LighterColour = colours.Orange0; + createButton.TextColour = colourProvider.Background6; + } + + protected override void UpdateState(ValueChangedEvent state) + { + base.UpdateState(state); + if (state.NewValue == Visibility.Hidden) + button.Active.Value = false; + } } } } From 059a465fe82fb0b5fe85c0fd83bda741c381addd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sat, 23 Jul 2022 16:22:09 +0200 Subject: [PATCH 253/278] Add border to popover for better visual contrast --- osu.Game/Overlays/Mods/AddPresetButton.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game/Overlays/Mods/AddPresetButton.cs b/osu.Game/Overlays/Mods/AddPresetButton.cs index 00343ac851..0141f3fa2b 100644 --- a/osu.Game/Overlays/Mods/AddPresetButton.cs +++ b/osu.Game/Overlays/Mods/AddPresetButton.cs @@ -95,6 +95,9 @@ namespace osu.Game.Overlays.Mods [BackgroundDependencyLoader] private void load(OverlayColourProvider colourProvider, OsuColour colours) { + Body.BorderThickness = 3; + Body.BorderColour = colours.Orange1; + createButton.DarkerColour = colours.Orange1; createButton.LighterColour = colours.Orange0; createButton.TextColour = colourProvider.Background6; From 7251389e4302be835b14f064aa50c0677c5d9400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 22 Jul 2022 21:49:51 +0200 Subject: [PATCH 254/278] Add localisations for add preset button --- osu.Game/Localisation/CommonStrings.cs | 14 ++++++++++++-- osu.Game/Localisation/ModSelectOverlayStrings.cs | 5 +++++ osu.Game/Overlays/Mods/AddPresetButton.cs | 7 ++++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/osu.Game/Localisation/CommonStrings.cs b/osu.Game/Localisation/CommonStrings.cs index 1ee562e122..f2dcd57742 100644 --- a/osu.Game/Localisation/CommonStrings.cs +++ b/osu.Game/Localisation/CommonStrings.cs @@ -1,4 +1,4 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using osu.Framework.Localisation; @@ -89,6 +89,16 @@ namespace osu.Game.Localisation /// public static LocalisableString Collections => new TranslatableString(getKey(@"collections"), @"Collections"); + /// + /// "Name" + /// + public static LocalisableString Name => new TranslatableString(getKey(@"name"), @"Name"); + + /// + /// "Description" + /// + public static LocalisableString Description => new TranslatableString(getKey(@"description"), @"Description"); + private static string getKey(string key) => $@"{prefix}:{key}"; } -} +} \ No newline at end of file diff --git a/osu.Game/Localisation/ModSelectOverlayStrings.cs b/osu.Game/Localisation/ModSelectOverlayStrings.cs index 3696b1f2cd..d6a01c4794 100644 --- a/osu.Game/Localisation/ModSelectOverlayStrings.cs +++ b/osu.Game/Localisation/ModSelectOverlayStrings.cs @@ -29,6 +29,11 @@ namespace osu.Game.Localisation /// public static LocalisableString PersonalPresets => new TranslatableString(getKey(@"personal_presets"), @"Personal Presets"); + /// + /// "Add preset" + /// + public static LocalisableString AddPreset => new TranslatableString(getKey(@"add_preset"), @"Add preset"); + private static string getKey(string key) => $@"{prefix}:{key}"; } } diff --git a/osu.Game/Overlays/Mods/AddPresetButton.cs b/osu.Game/Overlays/Mods/AddPresetButton.cs index 0141f3fa2b..44bdaeb9ac 100644 --- a/osu.Game/Overlays/Mods/AddPresetButton.cs +++ b/osu.Game/Overlays/Mods/AddPresetButton.cs @@ -12,6 +12,7 @@ using osu.Game.Graphics; using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterfaceV2; using osuTK; +using osu.Game.Localisation; namespace osu.Game.Overlays.Mods { @@ -71,21 +72,21 @@ namespace osu.Game.Overlays.Mods { Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, - Label = "Name", + Label = CommonStrings.Name, TabbableContentContainer = this }, descriptionTextBox = new LabelledTextBox { Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, - Label = "Description", + Label = CommonStrings.Description, TabbableContentContainer = this }, createButton = new ShearedButton { Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, - Text = "Create preset", + Text = ModSelectOverlayStrings.AddPreset, Action = this.HidePopover } } From add2971eb4a055f8560fe538f854fda346a5e20b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 22 Jul 2022 22:11:45 +0200 Subject: [PATCH 255/278] Implement preset creation flow with test coverage --- .../UserInterface/TestSceneModPresetColumn.cs | 61 ++++++++++++++++++- osu.Game/Overlays/Mods/AddPresetButton.cs | 51 +++++++++++++++- 2 files changed, 110 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs index d76ff3f332..05ed03f01d 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . 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; @@ -10,16 +11,19 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Testing; using osu.Framework.Graphics.Cursor; +using osu.Game.Graphics.UserInterface; +using osu.Game.Graphics.UserInterfaceV2; using osu.Game.Overlays; using osu.Game.Overlays.Mods; using osu.Game.Rulesets; using osu.Game.Rulesets.Mania.Mods; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Osu.Mods; +using osuTK.Input; namespace osu.Game.Tests.Visual.UserInterface { - public class TestSceneModPresetColumn : OsuTestScene + public class TestSceneModPresetColumn : OsuManualInputManagerTestScene { protected override bool UseFreshStoragePerRun => true; @@ -146,6 +150,61 @@ namespace osu.Game.Tests.Visual.UserInterface AddUntilStep("3 panels visible", () => this.ChildrenOfType().Count() == 3); } + [Test] + public void TestAddingFlow() + { + ModPresetColumn modPresetColumn = null!; + + AddStep("clear mods", () => SelectedMods.Value = Array.Empty()); + AddStep("create content", () => Child = modPresetColumn = new ModPresetColumn + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + }); + + AddUntilStep("items loaded", () => modPresetColumn.IsLoaded && modPresetColumn.ItemsLoaded); + AddAssert("add preset button disabled", () => !this.ChildrenOfType().Single().Enabled.Value); + + AddStep("set mods", () => SelectedMods.Value = new Mod[] { new OsuModDaycore(), new OsuModClassic() }); + AddAssert("add preset button enabled", () => this.ChildrenOfType().Single().Enabled.Value); + + AddStep("click add preset button", () => + { + InputManager.MoveMouseTo(this.ChildrenOfType().Single()); + InputManager.Click(MouseButton.Left); + }); + + OsuPopover? popover = null; + AddUntilStep("wait for popover", () => (popover = this.ChildrenOfType().FirstOrDefault()) != null); + AddStep("attempt preset creation", () => + { + InputManager.MoveMouseTo(popover.ChildrenOfType().Single()); + InputManager.Click(MouseButton.Left); + }); + AddWaitStep("wait some", 3); + AddAssert("preset creation did not occur", () => this.ChildrenOfType().Count() == 3); + AddUntilStep("popover is unchanged", () => this.ChildrenOfType().FirstOrDefault() == popover); + + AddStep("fill preset name", () => popover.ChildrenOfType().First().Current.Value = "new preset"); + AddStep("attempt preset creation", () => + { + InputManager.MoveMouseTo(popover.ChildrenOfType().Single()); + InputManager.Click(MouseButton.Left); + }); + AddUntilStep("popover closed", () => !this.ChildrenOfType().Any()); + AddUntilStep("preset creation occurred", () => this.ChildrenOfType().Count() == 4); + + AddStep("click add preset button", () => + { + InputManager.MoveMouseTo(this.ChildrenOfType().Single()); + InputManager.Click(MouseButton.Left); + }); + + AddUntilStep("wait for popover", () => (popover = this.ChildrenOfType().FirstOrDefault()) != null); + AddStep("clear mods", () => SelectedMods.Value = Array.Empty()); + AddUntilStep("popover closed", () => !this.ChildrenOfType().Any()); + } + private ICollection createTestPresets() => new[] { new ModPreset diff --git a/osu.Game/Overlays/Mods/AddPresetButton.cs b/osu.Game/Overlays/Mods/AddPresetButton.cs index 44bdaeb9ac..e3aeb21f1d 100644 --- a/osu.Game/Overlays/Mods/AddPresetButton.cs +++ b/osu.Game/Overlays/Mods/AddPresetButton.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Collections.Generic; +using System.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Extensions; @@ -8,9 +10,13 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.UserInterface; +using osu.Game.Database; +using osu.Game.Extensions; using osu.Game.Graphics; using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterfaceV2; +using osu.Game.Rulesets; +using osu.Game.Rulesets.Mods; using osuTK; using osu.Game.Localisation; @@ -21,6 +27,9 @@ namespace osu.Game.Overlays.Mods [Resolved] private OsuColour colours { get; set; } = null!; + [Resolved] + private Bindable> selectedMods { get; set; } = null!; + public AddPresetButton() : base(1) { @@ -35,6 +44,18 @@ namespace osu.Game.Overlays.Mods TextSize = 30; } + protected override void LoadComplete() + { + base.LoadComplete(); + + selectedMods.BindValueChanged(val => Enabled.Value = val.NewValue.Any(), true); + Enabled.BindValueChanged(val => + { + if (!val.NewValue) + Active.Value = false; + }); + } + protected override void UpdateActiveState() { DarkerColour = Active.Value ? colours.Orange1 : ColourProvider.Background3; @@ -57,6 +78,15 @@ namespace osu.Game.Overlays.Mods private readonly LabelledTextBox descriptionTextBox; private readonly ShearedButton createButton; + [Resolved] + private Bindable ruleset { get; set; } = null!; + + [Resolved] + private Bindable> selectedMods { get; set; } = null!; + + [Resolved] + private RealmAccess realm { get; set; } = null!; + public AddPresetPopover(AddPresetButton addPresetButton) { button = addPresetButton; @@ -87,7 +117,7 @@ namespace osu.Game.Overlays.Mods Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, Text = ModSelectOverlayStrings.AddPreset, - Action = this.HidePopover + Action = tryCreatePreset } } }; @@ -104,6 +134,25 @@ namespace osu.Game.Overlays.Mods createButton.TextColour = colourProvider.Background6; } + private void tryCreatePreset() + { + if (string.IsNullOrWhiteSpace(nameTextBox.Current.Value)) + { + Body.Shake(); + return; + } + + realm.Write(r => r.Add(new ModPreset + { + Name = nameTextBox.Current.Value, + Description = descriptionTextBox.Current.Value, + Mods = selectedMods.Value.ToArray(), + Ruleset = r.Find(ruleset.Value.ShortName) + })); + + this.HidePopover(); + } + protected override void UpdateState(ValueChangedEvent state) { base.UpdateState(state); From f743dc623f6337fd80259de8768776e9ba59db3d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 3 Aug 2022 17:37:30 +0900 Subject: [PATCH 256/278] Change migration logic to ignore realm pipe files regardless of database filename --- osu.Game/IO/MigratableStorage.cs | 17 +++++++++++++++++ osu.Game/IO/OsuStorage.cs | 11 ++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/osu.Game/IO/MigratableStorage.cs b/osu.Game/IO/MigratableStorage.cs index 7cd409c04c..14a3c5a43c 100644 --- a/osu.Game/IO/MigratableStorage.cs +++ b/osu.Game/IO/MigratableStorage.cs @@ -26,6 +26,11 @@ namespace osu.Game.IO /// public virtual string[] IgnoreFiles => Array.Empty(); + /// + /// A list of file/directory suffixes which should not be migrated. + /// + public virtual string[] IgnoreSuffixes => Array.Empty(); + protected MigratableStorage(Storage storage, string subPath = null) : base(storage, subPath) { @@ -73,6 +78,9 @@ namespace osu.Game.IO if (topLevelExcludes && IgnoreFiles.Contains(fi.Name)) continue; + if (IgnoreSuffixes.Any(suffix => fi.Name.EndsWith(suffix, StringComparison.Ordinal))) + continue; + allFilesDeleted &= AttemptOperation(() => fi.Delete(), throwOnFailure: false); } @@ -81,6 +89,9 @@ namespace osu.Game.IO if (topLevelExcludes && IgnoreDirectories.Contains(dir.Name)) continue; + if (IgnoreSuffixes.Any(suffix => dir.Name.EndsWith(suffix, StringComparison.Ordinal))) + continue; + allFilesDeleted &= AttemptOperation(() => dir.Delete(true), throwOnFailure: false); } @@ -101,6 +112,9 @@ namespace osu.Game.IO if (topLevelExcludes && IgnoreFiles.Contains(fileInfo.Name)) continue; + if (IgnoreSuffixes.Any(suffix => fileInfo.Name.EndsWith(suffix, StringComparison.Ordinal))) + continue; + AttemptOperation(() => { fileInfo.Refresh(); @@ -119,6 +133,9 @@ namespace osu.Game.IO if (topLevelExcludes && IgnoreDirectories.Contains(dir.Name)) continue; + if (IgnoreSuffixes.Any(suffix => dir.Name.EndsWith(suffix, StringComparison.Ordinal))) + continue; + CopyRecursive(dir, destination.CreateSubdirectory(dir.Name), false); } } diff --git a/osu.Game/IO/OsuStorage.cs b/osu.Game/IO/OsuStorage.cs index 368ac56850..f4c55e4b0e 100644 --- a/osu.Game/IO/OsuStorage.cs +++ b/osu.Game/IO/OsuStorage.cs @@ -38,15 +38,20 @@ namespace osu.Game.IO public override string[] IgnoreDirectories => new[] { "cache", - $"{OsuGameBase.CLIENT_DATABASE_FILENAME}.management", }; public override string[] IgnoreFiles => new[] { "framework.ini", "storage.ini", - $"{OsuGameBase.CLIENT_DATABASE_FILENAME}.note", - $"{OsuGameBase.CLIENT_DATABASE_FILENAME}.lock", + }; + + public override string[] IgnoreSuffixes => new[] + { + // Realm pipe files don't play well with copy operations + ".note", + ".lock", + ".management", }; public OsuStorage(GameHost host, Storage defaultStorage) From 6ad6561e1cd8c73f9ad7237ce1c51ed389e24656 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 3 Aug 2022 17:42:27 +0900 Subject: [PATCH 257/278] Fix `LegacySongProgress` incorrectly blocking mouse input from gameplay Closes #19555. --- osu.Game/Screens/Play/HUD/DefaultSongProgress.cs | 2 -- osu.Game/Screens/Play/HUD/SongProgress.cs | 6 ++++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs b/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs index 96a6c56860..659984682e 100644 --- a/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs +++ b/osu.Game/Screens/Play/HUD/DefaultSongProgress.cs @@ -40,8 +40,6 @@ namespace osu.Game.Screens.Play.HUD public override bool HandleNonPositionalInput => AllowSeeking.Value; public override bool HandlePositionalInput => AllowSeeking.Value; - protected override bool BlockScrollInput => false; - [Resolved] private Player? player { get; set; } diff --git a/osu.Game/Screens/Play/HUD/SongProgress.cs b/osu.Game/Screens/Play/HUD/SongProgress.cs index 702d2f7c6f..09afd7a9d3 100644 --- a/osu.Game/Screens/Play/HUD/SongProgress.cs +++ b/osu.Game/Screens/Play/HUD/SongProgress.cs @@ -14,6 +14,12 @@ namespace osu.Game.Screens.Play.HUD { public abstract class SongProgress : OverlayContainer, ISkinnableDrawable { + // Some implementations of this element allow seeking during gameplay playback. + // Set a sane default of never handling input to override the behaviour provided by OverlayContainer. + public override bool HandleNonPositionalInput => false; + public override bool HandlePositionalInput => false; + protected override bool BlockScrollInput => false; + public bool UsesFixedAnchor { get; set; } [Resolved] From 16ff8d5c38354e914d30366f4a322dfda35acc2d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 3 Aug 2022 17:47:32 +0900 Subject: [PATCH 258/278] Use different variable source --- osu.Game/Graphics/Containers/BeatSyncedContainer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs index c8ea21e139..6dd5d61cc9 100644 --- a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs +++ b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs @@ -29,7 +29,7 @@ namespace osu.Game.Graphics.Containers private TimingControlPoint? lastTimingPoint { get; set; } private EffectControlPoint? lastEffectPoint { get; set; } - public bool IsKiaiTime { get; private set; } + protected bool IsKiaiTime { get; private set; } /// /// The amount of time before a beat we should fire . @@ -142,7 +142,7 @@ namespace osu.Game.Graphics.Containers lastTimingPoint = timingPoint; lastEffectPoint = effectPoint; - IsKiaiTime = lastEffectPoint?.KiaiMode ?? false; + IsKiaiTime = effectPoint?.KiaiMode ?? false; } } } From 24d84890e4869ac12437291eaa82ccb3f11114a1 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 3 Aug 2022 20:03:05 +0900 Subject: [PATCH 259/278] Change all filter control button state test to until steps There's multiple schedules at play which could be adding multi-frame delays. let's play it safe and try and fix flaky tests. Example of `Schedule` which could cause an issue: https://github.com/ppy/osu/blob/392cb352cc71da8b0f82aa0877ea6a7febfc54b1/osu.Game/Collections/CollectionDropdown.cs#L77-L78 Example of test failure: https://github.com/ppy/osu/runs/7648118894?check_suite_focus=true --- .../Visual/SongSelect/TestSceneFilterControl.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs index d0523b58fa..99afe5a2f7 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs @@ -150,13 +150,14 @@ namespace osu.Game.Tests.Visual.SongSelect AddStep("add collection", () => writeAndRefresh(r => r.Add(new BeatmapCollection(name: "1")))); assertCollectionDropdownContains("1"); - AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusSquare)); + + assertFirstButtonIs(FontAwesome.Solid.PlusSquare); AddStep("add beatmap to collection", () => writeAndRefresh(r => getFirstCollection().BeatmapMD5Hashes.Add(Beatmap.Value.BeatmapInfo.MD5Hash))); - AddAssert("button is minus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.MinusSquare)); + assertFirstButtonIs(FontAwesome.Solid.MinusSquare); AddStep("remove beatmap from collection", () => writeAndRefresh(r => getFirstCollection().BeatmapMD5Hashes.Clear())); - AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusSquare)); + assertFirstButtonIs(FontAwesome.Solid.PlusSquare); } [Test] @@ -168,15 +169,15 @@ namespace osu.Game.Tests.Visual.SongSelect AddStep("add collection", () => writeAndRefresh(r => r.Add(new BeatmapCollection(name: "1")))); assertCollectionDropdownContains("1"); - AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusSquare)); + assertFirstButtonIs(FontAwesome.Solid.PlusSquare); addClickAddOrRemoveButtonStep(1); AddAssert("collection contains beatmap", () => getFirstCollection().BeatmapMD5Hashes.Contains(Beatmap.Value.BeatmapInfo.MD5Hash)); - AddAssert("button is minus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.MinusSquare)); + assertFirstButtonIs(FontAwesome.Solid.MinusSquare); addClickAddOrRemoveButtonStep(1); AddAssert("collection does not contain beatmap", () => !getFirstCollection().BeatmapMD5Hashes.Contains(Beatmap.Value.BeatmapInfo.MD5Hash)); - AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusSquare)); + assertFirstButtonIs(FontAwesome.Solid.PlusSquare); } [Test] @@ -226,6 +227,8 @@ namespace osu.Game.Tests.Visual.SongSelect => AddUntilStep($"collection dropdown header displays '{collectionName}'", () => shouldDisplay == (control.ChildrenOfType().Single().ChildrenOfType().First().Text == collectionName)); + private void assertFirstButtonIs(IconUsage icon) => AddUntilStep($"button is {icon.ToString()}", () => getAddOrRemoveButton(1).Icon.Equals(icon)); + private void assertCollectionDropdownContains(string collectionName, bool shouldContain = true) => AddUntilStep($"collection dropdown {(shouldContain ? "contains" : "does not contain")} '{collectionName}'", // A bit of a roundabout way of going about this, see: https://github.com/ppy/osu-framework/issues/3871 + https://github.com/ppy/osu-framework/issues/3872 From a32149fda125c207575fc6dc1fc30450d5eee556 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 3 Aug 2022 20:07:54 +0900 Subject: [PATCH 260/278] Convert interface methods to extension methods --- .../Beatmaps/BeatSyncProviderExtensions.cs | 18 ++++++++++++++++++ osu.Game/Beatmaps/IBeatSyncProvider.cs | 10 ---------- .../Graphics/Containers/BeatSyncedContainer.cs | 6 ++---- osu.Game/Screens/Menu/LogoVisualisation.cs | 2 +- 4 files changed, 21 insertions(+), 15 deletions(-) create mode 100644 osu.Game/Beatmaps/BeatSyncProviderExtensions.cs diff --git a/osu.Game/Beatmaps/BeatSyncProviderExtensions.cs b/osu.Game/Beatmaps/BeatSyncProviderExtensions.cs new file mode 100644 index 0000000000..117b4d23b0 --- /dev/null +++ b/osu.Game/Beatmaps/BeatSyncProviderExtensions.cs @@ -0,0 +1,18 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +namespace osu.Game.Beatmaps +{ + public static class BeatSyncProviderExtensions + { + /// + /// Check whether beat sync is currently available. + /// + public static bool CheckBeatSyncAvailable(this IBeatSyncProvider provider) => provider.Clock != null; + + /// + /// Whether the beat sync provider is currently in a kiai section. Should make everything more epic. + /// + public static bool CheckIsKiaiTime(this IBeatSyncProvider provider) => provider.Clock != null && (provider.ControlPoints?.EffectPointAt(provider.Clock.CurrentTime).KiaiMode ?? false); + } +} diff --git a/osu.Game/Beatmaps/IBeatSyncProvider.cs b/osu.Game/Beatmaps/IBeatSyncProvider.cs index 485497a8f0..9ee19e720d 100644 --- a/osu.Game/Beatmaps/IBeatSyncProvider.cs +++ b/osu.Game/Beatmaps/IBeatSyncProvider.cs @@ -16,16 +16,6 @@ namespace osu.Game.Beatmaps [Cached] public interface IBeatSyncProvider : IHasAmplitudes { - /// - /// Check whether beat sync is currently available. - /// - public bool BeatSyncAvailable => Clock != null; - - /// - /// Whether the beat sync provider is currently in a kiai section. Should make everything more epic. - /// - public bool IsKiaiTime => Clock != null && (ControlPoints?.EffectPointAt(Clock.CurrentTime).KiaiMode ?? false); - /// /// Access any available control points from a beatmap providing beat sync. If null, no current provider is available. /// diff --git a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs index 6dd5d61cc9..00fea601c6 100644 --- a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs +++ b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs @@ -27,7 +27,6 @@ namespace osu.Game.Graphics.Containers private int lastBeat; private TimingControlPoint? lastTimingPoint { get; set; } - private EffectControlPoint? lastEffectPoint { get; set; } protected bool IsKiaiTime { get; private set; } @@ -87,7 +86,7 @@ namespace osu.Game.Graphics.Containers TimingControlPoint timingPoint; EffectControlPoint effectPoint; - IsBeatSyncedWithTrack = BeatSyncSource.BeatSyncAvailable && BeatSyncSource.Clock?.IsRunning == true; + IsBeatSyncedWithTrack = BeatSyncSource.CheckBeatSyncAvailable() && BeatSyncSource.Clock?.IsRunning == true; double currentTrackTime; @@ -140,9 +139,8 @@ namespace osu.Game.Graphics.Containers lastBeat = beatIndex; lastTimingPoint = timingPoint; - lastEffectPoint = effectPoint; - IsKiaiTime = effectPoint?.KiaiMode ?? false; + IsKiaiTime = effectPoint.KiaiMode; } } } diff --git a/osu.Game/Screens/Menu/LogoVisualisation.cs b/osu.Game/Screens/Menu/LogoVisualisation.cs index e9f52e0b9f..1c5fd341b0 100644 --- a/osu.Game/Screens/Menu/LogoVisualisation.cs +++ b/osu.Game/Screens/Menu/LogoVisualisation.cs @@ -111,7 +111,7 @@ namespace osu.Game.Screens.Menu for (int i = 0; i < bars_per_visualiser; i++) { - float targetAmplitude = (temporalAmplitudes[(i + indexOffset) % bars_per_visualiser]) * (beatSyncProvider.IsKiaiTime ? 1 : 0.5f); + float targetAmplitude = (temporalAmplitudes[(i + indexOffset) % bars_per_visualiser]) * (beatSyncProvider.CheckIsKiaiTime() ? 1 : 0.5f); if (targetAmplitude > frequencyAmplitudes[i]) frequencyAmplitudes[i] = targetAmplitude; } From d3954fc583ad5ec1de1a240261664d0112fa2a7a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 3 Aug 2022 20:15:42 +0900 Subject: [PATCH 261/278] Use existing localised error message --- osu.Game/Database/ModelDownloader.cs | 2 +- osu.Game/Database/TooManyDownloadsNotification.cs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/osu.Game/Database/ModelDownloader.cs b/osu.Game/Database/ModelDownloader.cs index 5c84e0c308..a3678602d1 100644 --- a/osu.Game/Database/ModelDownloader.cs +++ b/osu.Game/Database/ModelDownloader.cs @@ -112,7 +112,7 @@ namespace osu.Game.Database if (error is WebException webException && webException.Message == @"TooManyRequests") { notification.Close(); - PostNotification?.Invoke(new TooManyDownloadsNotification(importer.HumanisedModelName)); + PostNotification?.Invoke(new TooManyDownloadsNotification()); } else Logger.Error(error, $"{importer.HumanisedModelName.Titleize()} download failed!"); diff --git a/osu.Game/Database/TooManyDownloadsNotification.cs b/osu.Game/Database/TooManyDownloadsNotification.cs index c07584c6ec..aa88fed43c 100644 --- a/osu.Game/Database/TooManyDownloadsNotification.cs +++ b/osu.Game/Database/TooManyDownloadsNotification.cs @@ -5,14 +5,15 @@ using osu.Framework.Allocation; using osu.Framework.Graphics.Sprites; using osu.Game.Graphics; using osu.Game.Overlays.Notifications; +using osu.Game.Resources.Localisation.Web; namespace osu.Game.Database { public class TooManyDownloadsNotification : SimpleNotification { - public TooManyDownloadsNotification(string humanisedModelName) + public TooManyDownloadsNotification() { - Text = $"You have downloaded too many {humanisedModelName}s! Please try again later."; + Text = BeatmapsetsStrings.DownloadLimitExceeded; Icon = FontAwesome.Solid.ExclamationCircle; } From bacbf5b7f0cb87e334d64c6f98af3afc6a298427 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 3 Aug 2022 20:20:06 +0900 Subject: [PATCH 262/278] Update existing test expectations --- osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs b/osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs index 4baa4af8dd..a21f66a7cb 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs @@ -294,7 +294,7 @@ namespace osu.Game.Tests.Visual.Editing AddAssert("approach rate correctly copied", () => EditorBeatmap.Difficulty.ApproachRate == 4); AddAssert("combo colours correctly copied", () => EditorBeatmap.BeatmapSkin.AsNonNull().ComboColours.Count == 2); - AddAssert("status not copied", () => EditorBeatmap.BeatmapInfo.Status == BeatmapOnlineStatus.None); + AddAssert("status is modified", () => EditorBeatmap.BeatmapInfo.Status == BeatmapOnlineStatus.LocallyModified); AddAssert("online ID not copied", () => EditorBeatmap.BeatmapInfo.OnlineID == -1); AddStep("save beatmap", () => Editor.Save()); From 7022d9e5f81c23730b3db690dbfb288238508129 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 3 Aug 2022 21:13:49 +0900 Subject: [PATCH 263/278] Fix test step names being too long --- osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs index 99afe5a2f7..dadcd43db5 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs @@ -227,7 +227,7 @@ namespace osu.Game.Tests.Visual.SongSelect => AddUntilStep($"collection dropdown header displays '{collectionName}'", () => shouldDisplay == (control.ChildrenOfType().Single().ChildrenOfType().First().Text == collectionName)); - private void assertFirstButtonIs(IconUsage icon) => AddUntilStep($"button is {icon.ToString()}", () => getAddOrRemoveButton(1).Icon.Equals(icon)); + private void assertFirstButtonIs(IconUsage icon) => AddUntilStep($"button is {icon.Icon.ToString()}", () => getAddOrRemoveButton(1).Icon.Equals(icon)); private void assertCollectionDropdownContains(string collectionName, bool shouldContain = true) => AddUntilStep($"collection dropdown {(shouldContain ? "contains" : "does not contain")} '{collectionName}'", From 8b02c955d838541cb782596457f184b3f50d45fb Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 3 Aug 2022 23:17:09 +0800 Subject: [PATCH 264/278] Give this class a constructor to make sure that message data will always assigned. --- osu.Desktop/LegacyIpc/LegacyIpcMessage.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/osu.Desktop/LegacyIpc/LegacyIpcMessage.cs b/osu.Desktop/LegacyIpc/LegacyIpcMessage.cs index 76eb6cdbd1..54198ef605 100644 --- a/osu.Desktop/LegacyIpc/LegacyIpcMessage.cs +++ b/osu.Desktop/LegacyIpc/LegacyIpcMessage.cs @@ -37,17 +37,19 @@ namespace osu.Desktop.LegacyIpc public new object Value { get => base.Value; - set => base.Value = new Data - { - MessageType = value.GetType().Name, - MessageData = value - }; + set => base.Value = new Data(value.GetType().Name, value); } public class Data { - public string MessageType { get; set; } = string.Empty; - public object MessageData { get; set; } = default!; + public Data(string messageType, object messageData) + { + MessageType = messageType; + MessageData = messageData; + } + + public string MessageType { get; set; } + public object MessageData { get; set; } } } } From 844430502b548747b0ed4867e8a2bb230c031d7a Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Wed, 3 Aug 2022 20:11:08 +0300 Subject: [PATCH 265/278] Replace parantheses with nullable-bool equality operation --- osu.Game/Beatmaps/BeatSyncProviderExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Beatmaps/BeatSyncProviderExtensions.cs b/osu.Game/Beatmaps/BeatSyncProviderExtensions.cs index 117b4d23b0..767aa5df73 100644 --- a/osu.Game/Beatmaps/BeatSyncProviderExtensions.cs +++ b/osu.Game/Beatmaps/BeatSyncProviderExtensions.cs @@ -13,6 +13,6 @@ namespace osu.Game.Beatmaps /// /// Whether the beat sync provider is currently in a kiai section. Should make everything more epic. /// - public static bool CheckIsKiaiTime(this IBeatSyncProvider provider) => provider.Clock != null && (provider.ControlPoints?.EffectPointAt(provider.Clock.CurrentTime).KiaiMode ?? false); + public static bool CheckIsKiaiTime(this IBeatSyncProvider provider) => provider.Clock != null && provider.ControlPoints?.EffectPointAt(provider.Clock.CurrentTime).KiaiMode == true; } } From b00c3a4d6d9fd725b428f36155bb47c641697127 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Wed, 3 Aug 2022 20:31:51 +0300 Subject: [PATCH 266/278] Move properties and mark as get-only --- osu.Desktop/LegacyIpc/LegacyIpcMessage.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/osu.Desktop/LegacyIpc/LegacyIpcMessage.cs b/osu.Desktop/LegacyIpc/LegacyIpcMessage.cs index 54198ef605..8d0add32d1 100644 --- a/osu.Desktop/LegacyIpc/LegacyIpcMessage.cs +++ b/osu.Desktop/LegacyIpc/LegacyIpcMessage.cs @@ -42,14 +42,15 @@ namespace osu.Desktop.LegacyIpc public class Data { + public string MessageType { get; } + + public object MessageData { get; } + public Data(string messageType, object messageData) { MessageType = messageType; MessageData = messageData; } - - public string MessageType { get; set; } - public object MessageData { get; set; } } } } From 82d3fbd51b0b49fa003b961aa06c2093f061b303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 3 Aug 2022 21:22:55 +0200 Subject: [PATCH 267/278] Split `AddPresetPopover` to separate file --- osu.Game/Overlays/Mods/AddPresetButton.cs | 97 ------------------ osu.Game/Overlays/Mods/AddPresetPopover.cs | 113 +++++++++++++++++++++ 2 files changed, 113 insertions(+), 97 deletions(-) create mode 100644 osu.Game/Overlays/Mods/AddPresetPopover.cs diff --git a/osu.Game/Overlays/Mods/AddPresetButton.cs b/osu.Game/Overlays/Mods/AddPresetButton.cs index e3aeb21f1d..375987e474 100644 --- a/osu.Game/Overlays/Mods/AddPresetButton.cs +++ b/osu.Game/Overlays/Mods/AddPresetButton.cs @@ -7,18 +7,12 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Extensions; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.UserInterface; -using osu.Game.Database; -using osu.Game.Extensions; using osu.Game.Graphics; using osu.Game.Graphics.UserInterface; -using osu.Game.Graphics.UserInterfaceV2; -using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; using osuTK; -using osu.Game.Localisation; namespace osu.Game.Overlays.Mods { @@ -69,96 +63,5 @@ namespace osu.Game.Overlays.Mods } public Popover GetPopover() => new AddPresetPopover(this); - - private class AddPresetPopover : OsuPopover - { - private readonly AddPresetButton button; - - private readonly LabelledTextBox nameTextBox; - private readonly LabelledTextBox descriptionTextBox; - private readonly ShearedButton createButton; - - [Resolved] - private Bindable ruleset { get; set; } = null!; - - [Resolved] - private Bindable> selectedMods { get; set; } = null!; - - [Resolved] - private RealmAccess realm { get; set; } = null!; - - public AddPresetPopover(AddPresetButton addPresetButton) - { - button = addPresetButton; - - Child = new FillFlowContainer - { - Width = 300, - AutoSizeAxes = Axes.Y, - Spacing = new Vector2(7), - Children = new Drawable[] - { - nameTextBox = new LabelledTextBox - { - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, - Label = CommonStrings.Name, - TabbableContentContainer = this - }, - descriptionTextBox = new LabelledTextBox - { - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, - Label = CommonStrings.Description, - TabbableContentContainer = this - }, - createButton = new ShearedButton - { - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, - Text = ModSelectOverlayStrings.AddPreset, - Action = tryCreatePreset - } - } - }; - } - - [BackgroundDependencyLoader] - private void load(OverlayColourProvider colourProvider, OsuColour colours) - { - Body.BorderThickness = 3; - Body.BorderColour = colours.Orange1; - - createButton.DarkerColour = colours.Orange1; - createButton.LighterColour = colours.Orange0; - createButton.TextColour = colourProvider.Background6; - } - - private void tryCreatePreset() - { - if (string.IsNullOrWhiteSpace(nameTextBox.Current.Value)) - { - Body.Shake(); - return; - } - - realm.Write(r => r.Add(new ModPreset - { - Name = nameTextBox.Current.Value, - Description = descriptionTextBox.Current.Value, - Mods = selectedMods.Value.ToArray(), - Ruleset = r.Find(ruleset.Value.ShortName) - })); - - this.HidePopover(); - } - - protected override void UpdateState(ValueChangedEvent state) - { - base.UpdateState(state); - if (state.NewValue == Visibility.Hidden) - button.Active.Value = false; - } - } } } diff --git a/osu.Game/Overlays/Mods/AddPresetPopover.cs b/osu.Game/Overlays/Mods/AddPresetPopover.cs new file mode 100644 index 0000000000..a7c77b7d83 --- /dev/null +++ b/osu.Game/Overlays/Mods/AddPresetPopover.cs @@ -0,0 +1,113 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using System.Linq; +using osu.Framework.Allocation; +using osu.Framework.Bindables; +using osu.Framework.Extensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Database; +using osu.Game.Extensions; +using osu.Game.Graphics; +using osu.Game.Graphics.UserInterface; +using osu.Game.Graphics.UserInterfaceV2; +using osu.Game.Localisation; +using osu.Game.Rulesets; +using osu.Game.Rulesets.Mods; +using osuTK; + +namespace osu.Game.Overlays.Mods +{ + internal class AddPresetPopover : OsuPopover + { + private readonly AddPresetButton button; + + private readonly LabelledTextBox nameTextBox; + private readonly LabelledTextBox descriptionTextBox; + private readonly ShearedButton createButton; + + [Resolved] + private Bindable ruleset { get; set; } = null!; + + [Resolved] + private Bindable> selectedMods { get; set; } = null!; + + [Resolved] + private RealmAccess realm { get; set; } = null!; + + public AddPresetPopover(AddPresetButton addPresetButton) + { + button = addPresetButton; + + Child = new FillFlowContainer + { + Width = 300, + AutoSizeAxes = Axes.Y, + Spacing = new Vector2(7), + Children = new Drawable[] + { + nameTextBox = new LabelledTextBox + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Label = CommonStrings.Name, + TabbableContentContainer = this + }, + descriptionTextBox = new LabelledTextBox + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Label = CommonStrings.Description, + TabbableContentContainer = this + }, + createButton = new ShearedButton + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Text = ModSelectOverlayStrings.AddPreset, + Action = tryCreatePreset + } + } + }; + } + + [BackgroundDependencyLoader] + private void load(OverlayColourProvider colourProvider, OsuColour colours) + { + Body.BorderThickness = 3; + Body.BorderColour = colours.Orange1; + + createButton.DarkerColour = colours.Orange1; + createButton.LighterColour = colours.Orange0; + createButton.TextColour = colourProvider.Background6; + } + + private void tryCreatePreset() + { + if (string.IsNullOrWhiteSpace(nameTextBox.Current.Value)) + { + Body.Shake(); + return; + } + + realm.Write(r => r.Add(new ModPreset + { + Name = nameTextBox.Current.Value, + Description = descriptionTextBox.Current.Value, + Mods = selectedMods.Value.ToArray(), + Ruleset = r.Find(ruleset.Value.ShortName) + })); + + this.HidePopover(); + } + + protected override void UpdateState(ValueChangedEvent state) + { + base.UpdateState(state); + if (state.NewValue == Visibility.Hidden) + button.Active.Value = false; + } + } +} From 159d3b032c2243ce6581dc9f3322925e919dfbbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 3 Aug 2022 21:23:31 +0200 Subject: [PATCH 268/278] Rename locals for legibility --- osu.Game/Overlays/Mods/AddPresetButton.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Overlays/Mods/AddPresetButton.cs b/osu.Game/Overlays/Mods/AddPresetButton.cs index 375987e474..1242088cf5 100644 --- a/osu.Game/Overlays/Mods/AddPresetButton.cs +++ b/osu.Game/Overlays/Mods/AddPresetButton.cs @@ -42,10 +42,10 @@ namespace osu.Game.Overlays.Mods { base.LoadComplete(); - selectedMods.BindValueChanged(val => Enabled.Value = val.NewValue.Any(), true); - Enabled.BindValueChanged(val => + selectedMods.BindValueChanged(mods => Enabled.Value = mods.NewValue.Any(), true); + Enabled.BindValueChanged(enabled => { - if (!val.NewValue) + if (!enabled.NewValue) Active.Value = false; }); } From ca1b4689cb7e6490c302efb19a8becb64c1fe524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 3 Aug 2022 21:26:35 +0200 Subject: [PATCH 269/278] Automatically focus name textbox upon add preset popover open --- osu.Game/Overlays/Mods/AddPresetPopover.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/osu.Game/Overlays/Mods/AddPresetPopover.cs b/osu.Game/Overlays/Mods/AddPresetPopover.cs index a7c77b7d83..8188c98e46 100644 --- a/osu.Game/Overlays/Mods/AddPresetPopover.cs +++ b/osu.Game/Overlays/Mods/AddPresetPopover.cs @@ -84,6 +84,13 @@ namespace osu.Game.Overlays.Mods createButton.TextColour = colourProvider.Background6; } + protected override void LoadComplete() + { + base.LoadComplete(); + + ScheduleAfterChildren(() => GetContainingInputManager().ChangeFocus(nameTextBox)); + } + private void tryCreatePreset() { if (string.IsNullOrWhiteSpace(nameTextBox.Current.Value)) From 6632367c6db4cff221e35386a7447e771ca44c61 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Thu, 4 Aug 2022 14:48:12 +0900 Subject: [PATCH 270/278] Ensure skin samples are looked up in correct order --- .../Skins/TestSceneSkinResources.cs | 69 +++++++++++++++++-- osu.Game/Skinning/Skin.cs | 6 +- 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/osu.Game.Tests/Skins/TestSceneSkinResources.cs b/osu.Game.Tests/Skins/TestSceneSkinResources.cs index 42c1eeb6d1..20f5c3d911 100644 --- a/osu.Game.Tests/Skins/TestSceneSkinResources.cs +++ b/osu.Game.Tests/Skins/TestSceneSkinResources.cs @@ -1,14 +1,25 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading; +using Moq; using NUnit.Framework; using osu.Framework.Allocation; +using osu.Framework.Audio.Sample; +using osu.Framework.Bindables; using osu.Framework.Extensions; +using osu.Framework.Extensions.ObjectExtensions; +using osu.Framework.Graphics.OpenGL.Textures; +using osu.Framework.Graphics.Textures; +using osu.Framework.IO.Stores; using osu.Framework.Testing; using osu.Game.Audio; using osu.Game.Database; +using osu.Game.IO; using osu.Game.Skinning; using osu.Game.Tests.Resources; using osu.Game.Tests.Visual; @@ -19,9 +30,9 @@ namespace osu.Game.Tests.Skins public class TestSceneSkinResources : OsuTestScene { [Resolved] - private SkinManager skins { get; set; } + private SkinManager skins { get; set; } = null!; - private ISkin skin; + private ISkin skin = null!; [BackgroundDependencyLoader] private void load() @@ -32,5 +43,55 @@ namespace osu.Game.Tests.Skins [Test] public void TestRetrieveOggSample() => AddAssert("sample is non-null", () => skin.GetSample(new SampleInfo("sample")) != null); + + [Test] + public void TestSampleRetrievalOrder() + { + Mock mockResourceProvider = null!; + Mock> mockResourceStore = null!; + List lookedUpFileNames = null!; + + AddStep("setup mock providers provider", () => + { + lookedUpFileNames = new List(); + mockResourceProvider = new Mock(); + mockResourceProvider.Setup(m => m.AudioManager).Returns(Audio); + mockResourceStore = new Mock>(); + mockResourceStore.Setup(r => r.Get(It.IsAny())) + .Callback(n => lookedUpFileNames.Add(n)) + .Returns(null); + }); + + AddStep("query sample", () => + { + TestSkin testSkin = new TestSkin(new SkinInfo(), mockResourceProvider.Object, new ResourceStore(mockResourceStore.Object)); + testSkin.GetSample(new SampleInfo()); + }); + + AddAssert("sample lookups were in correct order", () => + { + string[] lookups = lookedUpFileNames.Where(f => f.StartsWith(TestSkin.SAMPLE_NAME, StringComparison.Ordinal)).ToArray(); + return Path.GetExtension(lookups[0]) == string.Empty + && Path.GetExtension(lookups[1]) == ".wav" + && Path.GetExtension(lookups[2]) == ".mp3" + && Path.GetExtension(lookups[3]) == ".ogg"; + }); + } + + private class TestSkin : Skin + { + public const string SAMPLE_NAME = "test-sample"; + + public TestSkin(SkinInfo skin, IStorageResourceProvider? resources, IResourceStore? storage = null, string configurationFilename = "skin.ini") + : base(skin, resources, storage, configurationFilename) + { + } + + public override Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => throw new NotImplementedException(); + + public override IBindable GetConfig(TLookup lookup) => throw new NotImplementedException(); + + public override ISample GetSample(ISampleInfo sampleInfo) => Samples.AsNonNull().Get(SAMPLE_NAME); + } } } diff --git a/osu.Game/Skinning/Skin.cs b/osu.Game/Skinning/Skin.cs index 7d93aeb897..86347d9a3a 100644 --- a/osu.Game/Skinning/Skin.cs +++ b/osu.Game/Skinning/Skin.cs @@ -69,12 +69,14 @@ namespace osu.Game.Skinning storage ??= realmBackedStorage = new RealmBackedResourceStore(SkinInfo, resources.Files, resources.RealmAccess); - (storage as ResourceStore)?.AddExtension("ogg"); - var samples = resources.AudioManager?.GetSampleStore(storage); if (samples != null) samples.PlaybackConcurrency = OsuGameBase.SAMPLE_CONCURRENCY; + // osu-stable performs audio lookups in order of wav -> mp3 -> ogg. + // The GetSampleStore() call above internally adds wav and mp3, so ogg is added at the end to ensure expected ordering. + (storage as ResourceStore)?.AddExtension("ogg"); + Samples = samples; Textures = new TextureStore(resources.CreateTextureLoaderStore(storage)); } From c11a24b3ff541c85133e401f0f02c3057554b607 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Thu, 4 Aug 2022 15:05:52 +0900 Subject: [PATCH 271/278] Remove unused using --- osu.Game.Tests/Skins/TestSceneSkinResources.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game.Tests/Skins/TestSceneSkinResources.cs b/osu.Game.Tests/Skins/TestSceneSkinResources.cs index 20f5c3d911..d1561c84bf 100644 --- a/osu.Game.Tests/Skins/TestSceneSkinResources.cs +++ b/osu.Game.Tests/Skins/TestSceneSkinResources.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Threading; using Moq; using NUnit.Framework; using osu.Framework.Allocation; From 094eaafd43866c395755e86b9d240e938caf5eb2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 4 Aug 2022 17:26:54 +0900 Subject: [PATCH 272/278] Split out common conditional check into local `static` method --- osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs b/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs index 3238863700..f96fcc2630 100644 --- a/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs +++ b/osu.Game/Beatmaps/BeatmapUpdaterMetadataLookup.cs @@ -101,13 +101,13 @@ namespace osu.Game.Beatmaps beatmapInfo.BeatmapSet.OnlineID = res.OnlineBeatmapSetID; // Some metadata should only be applied if there's no local changes. - if (beatmapInfo.MatchesOnlineVersion || beatmapInfo.Status != BeatmapOnlineStatus.LocallyModified) + if (shouldSaveOnlineMetadata(beatmapInfo)) { beatmapInfo.Status = res.Status; beatmapInfo.Metadata.Author.OnlineID = res.AuthorID; } - if (beatmapInfo.BeatmapSet.Beatmaps.All(b => b.MatchesOnlineVersion || b.Status != BeatmapOnlineStatus.LocallyModified)) + if (beatmapInfo.BeatmapSet.Beatmaps.All(shouldSaveOnlineMetadata)) { beatmapInfo.BeatmapSet.Status = res.BeatmapSet?.Status ?? BeatmapOnlineStatus.None; beatmapInfo.BeatmapSet.DateRanked = res.BeatmapSet?.Ranked; @@ -212,7 +212,7 @@ namespace osu.Game.Beatmaps var status = (BeatmapOnlineStatus)reader.GetByte(2); // Some metadata should only be applied if there's no local changes. - if (beatmapInfo.MatchesOnlineVersion || beatmapInfo.Status != BeatmapOnlineStatus.LocallyModified) + if (shouldSaveOnlineMetadata(beatmapInfo)) { beatmapInfo.Status = status; beatmapInfo.Metadata.Author.OnlineID = reader.GetInt32(3); @@ -226,7 +226,7 @@ namespace osu.Game.Beatmaps Debug.Assert(beatmapInfo.BeatmapSet != null); beatmapInfo.BeatmapSet.OnlineID = reader.GetInt32(0); - if (beatmapInfo.BeatmapSet.Beatmaps.All(b => b.MatchesOnlineVersion || b.Status != BeatmapOnlineStatus.LocallyModified)) + if (beatmapInfo.BeatmapSet.Beatmaps.All(shouldSaveOnlineMetadata)) { beatmapInfo.BeatmapSet.Status = status; } @@ -249,6 +249,12 @@ namespace osu.Game.Beatmaps private void logForModel(BeatmapSetInfo set, string message) => RealmArchiveModelImporter.LogForModel(set, $"[{nameof(BeatmapUpdaterMetadataLookup)}] {message}"); + /// + /// Check whether the provided beatmap is in a state where online "ranked" status metadata should be saved against it. + /// Handles the case where a user may have locally modified a beatmap in the editor and expects the local status to stick. + /// + private static bool shouldSaveOnlineMetadata(BeatmapInfo beatmapInfo) => beatmapInfo.MatchesOnlineVersion || beatmapInfo.Status != BeatmapOnlineStatus.LocallyModified; + public void Dispose() { cacheDownloadRequest?.Dispose(); From 8ff7770a71591fc3d014c4033c7e090cd35b23e3 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Thu, 4 Aug 2022 19:11:39 +0900 Subject: [PATCH 273/278] Omit irrelevant data from SoloScoreInfo serialisation --- osu.Game/Online/API/Requests/Responses/SoloScoreInfo.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/osu.Game/Online/API/Requests/Responses/SoloScoreInfo.cs b/osu.Game/Online/API/Requests/Responses/SoloScoreInfo.cs index 6558578023..51b9e601c8 100644 --- a/osu.Game/Online/API/Requests/Responses/SoloScoreInfo.cs +++ b/osu.Game/Online/API/Requests/Responses/SoloScoreInfo.cs @@ -102,6 +102,14 @@ namespace osu.Game.Online.API.Requests.Responses [JsonProperty("pp")] public double? PP { get; set; } + public bool ShouldSerializeID() => false; + public bool ShouldSerializeUser() => false; + public bool ShouldSerializeBeatmap() => false; + public bool ShouldSerializeBeatmapSet() => false; + public bool ShouldSerializePP() => false; + public bool ShouldSerializeOnlineID() => false; + public bool ShouldSerializeHasReplay() => false; + #endregion public override string ToString() => $"score_id: {ID} user_id: {UserID}"; From 2d9da07eb69bfbeb1e9ff65fb50920ee7c6ec0b7 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Thu, 4 Aug 2022 19:27:50 +0900 Subject: [PATCH 274/278] Trim zero values from hit statistics --- osu.Game/Online/API/Requests/Responses/SoloScoreInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Online/API/Requests/Responses/SoloScoreInfo.cs b/osu.Game/Online/API/Requests/Responses/SoloScoreInfo.cs index 51b9e601c8..e2e5ea4239 100644 --- a/osu.Game/Online/API/Requests/Responses/SoloScoreInfo.cs +++ b/osu.Game/Online/API/Requests/Responses/SoloScoreInfo.cs @@ -173,7 +173,7 @@ namespace osu.Game.Online.API.Requests.Responses RulesetID = score.RulesetID, Passed = score.Passed, Mods = score.APIMods, - Statistics = score.Statistics, + Statistics = score.Statistics.Where(kvp => kvp.Value != 0).ToDictionary(kvp => kvp.Key, kvp => kvp.Value), }; public long OnlineID => ID ?? -1; From 786af81274064ea3afa3f40dfd0b6b683db80075 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 5 Aug 2022 14:15:01 +0900 Subject: [PATCH 275/278] Fix `PreviewTrack` not disposing its owned audio `Track` --- osu.Game/Audio/PreviewTrack.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/osu.Game/Audio/PreviewTrack.cs b/osu.Game/Audio/PreviewTrack.cs index 7fb92f9f9d..2409ca6eb6 100644 --- a/osu.Game/Audio/PreviewTrack.cs +++ b/osu.Game/Audio/PreviewTrack.cs @@ -105,5 +105,11 @@ namespace osu.Game.Audio /// Retrieves the audio track. /// protected abstract Track? GetTrack(); + + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + Track?.Dispose(); + } } } From 68232826045bb182f4098496ed497ffcfb2933f6 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 5 Aug 2022 14:15:27 +0900 Subject: [PATCH 276/278] Fix `PlayButton` potentially not disposing an unused `PreviewTrack` during load --- osu.Game/Overlays/BeatmapSet/Buttons/PlayButton.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game/Overlays/BeatmapSet/Buttons/PlayButton.cs b/osu.Game/Overlays/BeatmapSet/Buttons/PlayButton.cs index e840d0e82c..0ce55ce549 100644 --- a/osu.Game/Overlays/BeatmapSet/Buttons/PlayButton.cs +++ b/osu.Game/Overlays/BeatmapSet/Buttons/PlayButton.cs @@ -147,7 +147,10 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons { // beatmapset may have changed. if (Preview != preview) + { + preview?.Dispose(); return; + } AddInternal(preview); loading = false; From 7c952f806969d4b15d6507a54c4d8b55213c2fdf Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 5 Aug 2022 14:25:10 +0900 Subject: [PATCH 277/278] Add more test coverage of locally-modified state change --- .../Visual/Editing/TestSceneEditorBeatmapCreation.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs b/osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs index a21f66a7cb..80a5b4832b 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs @@ -56,8 +56,10 @@ namespace osu.Game.Tests.Visual.Editing [Test] public void TestCreateNewBeatmap() { + AddAssert("status is none", () => EditorBeatmap.BeatmapInfo.Status == BeatmapOnlineStatus.None); AddStep("save beatmap", () => Editor.Save()); AddAssert("new beatmap in database", () => beatmapManager.QueryBeatmapSet(s => s.ID == currentBeatmapSetID)?.Value.DeletePending == false); + AddAssert("status is modified", () => EditorBeatmap.BeatmapInfo.Status == BeatmapOnlineStatus.LocallyModified); } [Test] @@ -208,6 +210,8 @@ namespace osu.Game.Tests.Visual.Editing }); AddAssert("created difficulty has no objects", () => EditorBeatmap.HitObjects.Count == 0); + AddAssert("status is modified", () => EditorBeatmap.BeatmapInfo.Status == BeatmapOnlineStatus.LocallyModified); + AddStep("set unique difficulty name", () => EditorBeatmap.BeatmapInfo.DifficultyName = secondDifficultyName); AddStep("save beatmap", () => Editor.Save()); AddAssert("new beatmap persisted", () => @@ -218,7 +222,7 @@ namespace osu.Game.Tests.Visual.Editing return beatmap != null && beatmap.DifficultyName == secondDifficultyName && set != null - && set.PerformRead(s => s.Beatmaps.Count == 2 && s.Beatmaps.Any(b => b.DifficultyName == secondDifficultyName)); + && set.PerformRead(s => s.Beatmaps.Count == 2 && s.Beatmaps.Any(b => b.DifficultyName == secondDifficultyName) && s.Beatmaps.All(b => s.Status == BeatmapOnlineStatus.LocallyModified)); }); } From 94ec6534201c50a7574f1afeaa651af1d4b7dcc6 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 5 Aug 2022 14:26:01 +0900 Subject: [PATCH 278/278] Add same load-cancel safeties to ensure tracks are disposed in card `PlayButton` --- osu.Game/Beatmaps/Drawables/Cards/Buttons/PlayButton.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game/Beatmaps/Drawables/Cards/Buttons/PlayButton.cs b/osu.Game/Beatmaps/Drawables/Cards/Buttons/PlayButton.cs index 18eab09465..8ab632a757 100644 --- a/osu.Game/Beatmaps/Drawables/Cards/Buttons/PlayButton.cs +++ b/osu.Game/Beatmaps/Drawables/Cards/Buttons/PlayButton.cs @@ -118,7 +118,10 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons // another async load might have completed before this one. // if so, do not make any changes. if (loadedPreview != previewTrack) + { + loadedPreview.Dispose(); return; + } AddInternal(loadedPreview); toggleLoading(false);