From b0e522345cda92b51033c72d9aeeb29a017bc0c2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 May 2017 17:07:46 +0900 Subject: [PATCH 1/8] Combine DrawableHitObject classes into one --- .../Objects/Drawables/DrawableHitObject.cs | 43 +++++++------------ 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs b/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs index 21eca346c4..5622df9d14 100644 --- a/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs +++ b/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using osu.Framework; using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Audio.Sample; @@ -15,9 +14,19 @@ using osu.Game.Audio; namespace osu.Game.Rulesets.Objects.Drawables { - public abstract class DrawableHitObject : Container, IStateful + public abstract class DrawableHitObject : Container + where TObject : HitObject where TJudgement : Judgement { + public event Action> OnJudgement; + + public TObject HitObject; + + /// + /// The colour used for various elements of this DrawableHitObject. + /// + public virtual Color4 AccentColour { get; set; } + public override bool HandleInput => Interactive; public bool Interactive = true; @@ -49,10 +58,6 @@ namespace osu.Game.Rulesets.Objects.Drawables } } - internal DrawableHitObject() - { - } - protected List Samples = new List(); protected void PlaySamples() @@ -60,14 +65,6 @@ namespace osu.Game.Rulesets.Objects.Drawables Samples.ForEach(s => s?.Play()); } - [BackgroundDependencyLoader] - private void load() - { - //we may be setting a custom judgement in test cases or what not. - if (Judgement == null) - Judgement = CreateJudgement(); - } - protected override void LoadComplete() { base.LoadComplete(); @@ -75,20 +72,6 @@ namespace osu.Game.Rulesets.Objects.Drawables //force application of the state that was set before we loaded. UpdateState(State); } - } - - public abstract class DrawableHitObject : DrawableHitObject - where TObject : HitObject - where TJudgement : Judgement - { - public event Action> OnJudgement; - - public TObject HitObject; - - /// - /// The colour used for various elements of this DrawableHitObject. - /// - public virtual Color4 AccentColour { get; set; } protected DrawableHitObject(TObject hitObject) { @@ -170,6 +153,10 @@ namespace osu.Game.Rulesets.Objects.Drawables channel.Volume.Value = sample.Volume; Samples.Add(channel); } + + //we may be setting a custom judgement in test cases or what not. + if (Judgement == null) + Judgement = CreateJudgement(); } private List> nestedHitObjects; From 6fd95e0c5286ff4a1f6ac8321b43ba088bcd975c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 May 2017 17:16:01 +0900 Subject: [PATCH 2/8] Fix post-merge breakage --- osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs b/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs index 07be689446..c5dbc27fd3 100644 --- a/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs +++ b/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs @@ -34,11 +34,6 @@ namespace osu.Game.Rulesets.Objects.Drawables public TJudgement Judgement; - /// - /// Whether this hit object has been judged. - /// - public virtual bool Judged => (Judgement?.Result ?? HitResult.None) != HitResult.None; - protected abstract TJudgement CreateJudgement(); protected abstract void UpdateState(ArmedState state); @@ -82,7 +77,7 @@ namespace osu.Game.Rulesets.Objects.Drawables /// /// Whether this hit object and all of its nested hit objects have been judged. /// - public sealed override bool Judged => base.Judged && (NestedHitObjects?.All(h => h.Judged) ?? true); + public bool Judged => (Judgement?.Result ?? HitResult.None) != HitResult.None && (NestedHitObjects?.All(h => h.Judged) ?? true); protected DrawableHitObject(TObject hitObject) { From 6cc54773e8493b20607a7aa9576a475b2dafc17c Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Thu, 11 May 2017 17:18:22 +0900 Subject: [PATCH 3/8] Fix taiko right background not scaling with the playfield as intended. --- osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs | 42 ++++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs b/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs index 8e6f1c8556..23c7606a15 100644 --- a/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs +++ b/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs @@ -54,33 +54,33 @@ namespace osu.Game.Rulesets.Taiko.UI { AddInternal(new Drawable[] { - rightBackgroundContainer = new Container - { - Name = "Transparent playfield background", - RelativeSizeAxes = Axes.Both, - BorderThickness = 2, - Masking = true, - EdgeEffect = new EdgeEffect - { - Type = EdgeEffectType.Shadow, - Colour = Color4.Black.Opacity(0.2f), - Radius = 5, - }, - Children = new Drawable[] - { - rightBackground = new Box - { - RelativeSizeAxes = Axes.Both, - Alpha = 0.6f - }, - } - }, new ScaleFixContainer { RelativeSizeAxes = Axes.X, Height = DEFAULT_PLAYFIELD_HEIGHT, Children = new[] { + rightBackgroundContainer = new Container + { + Name = "Transparent playfield background", + RelativeSizeAxes = Axes.Both, + BorderThickness = 2, + Masking = true, + EdgeEffect = new EdgeEffect + { + Type = EdgeEffectType.Shadow, + Colour = Color4.Black.Opacity(0.2f), + Radius = 5, + }, + Children = new Drawable[] + { + rightBackground = new Box + { + RelativeSizeAxes = Axes.Both, + Alpha = 0.6f + }, + } + }, new Container { Name = "Transparent playfield elements", From a2f6d8a3e68a2c7b4c014d80e3c5e282cd231c29 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 May 2017 18:14:48 +0900 Subject: [PATCH 4/8] Fix broken test cases, remove some recursive lookup methods. --- osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs | 2 +- osu.Game/Database/BeatmapDatabase.cs | 3 +++ osu.Game/Database/Database.cs | 8 +++----- osu.Game/Screens/Menu/MainMenu.cs | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs b/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs index e259f700b1..0e456941a1 100644 --- a/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs +++ b/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs @@ -142,7 +142,7 @@ namespace osu.Game.Tests.Beatmaps.IO Assert.IsTrue(waitAction.BeginInvoke(null, null).AsyncWaitHandle.WaitOne(timeout), @"Beatmaps did not import to the database in allocated time"); - var set = host.Dependencies.Get().GetChildren(resultSets.First(), true); + var set = host.Dependencies.Get().GetChildren(resultSets.First()); Assert.IsTrue(set.Beatmaps.Count == resultBeatmaps.Count(), $@"Incorrect database beatmap count post-import ({resultBeatmaps.Count()} but should be {set.Beatmaps.Count})."); diff --git a/osu.Game/Database/BeatmapDatabase.cs b/osu.Game/Database/BeatmapDatabase.cs index 760b7ae353..de570d3e7e 100644 --- a/osu.Game/Database/BeatmapDatabase.cs +++ b/osu.Game/Database/BeatmapDatabase.cs @@ -267,6 +267,9 @@ namespace osu.Game.Database public WorkingBeatmap GetWorkingBeatmap(BeatmapInfo beatmapInfo, WorkingBeatmap previous = null, bool withStoryboard = false) { + if (beatmapInfo.BeatmapSet == null) + beatmapInfo = GetChildren(beatmapInfo, true); + if (beatmapInfo.BeatmapSet == null) throw new InvalidOperationException($@"Beatmap set {beatmapInfo.BeatmapSetInfoID} is not in the local database."); diff --git a/osu.Game/Database/Database.cs b/osu.Game/Database/Database.cs index 9b49583875..a55c0f570b 100644 --- a/osu.Game/Database/Database.cs +++ b/osu.Game/Database/Database.cs @@ -48,11 +48,9 @@ namespace osu.Game.Database return Connection.Table(); } - public T GetWithChildren(object id, bool recursive = false) where T : class - { - return Connection.GetWithChildren(id, recursive); - } - + /// + /// This is expensive. Use with caution. + /// public List GetAllWithChildren(Expression> filter = null, bool recursive = true) where T : class { diff --git a/osu.Game/Screens/Menu/MainMenu.cs b/osu.Game/Screens/Menu/MainMenu.cs index f8b8882d3d..c8a00e0671 100644 --- a/osu.Game/Screens/Menu/MainMenu.cs +++ b/osu.Game/Screens/Menu/MainMenu.cs @@ -79,7 +79,7 @@ namespace osu.Game.Screens.Menu if (count > 0) { var beatmap = query.ElementAt(RNG.Next(0, count - 1)); - beatmaps.GetChildren(beatmap, true); + beatmaps.GetChildren(beatmap); Beatmap = beatmaps.GetWorkingBeatmap(beatmap.Beatmaps[0]); } } From b258109a9ee1c9e98299a0543a7e99bfec18d2fe Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 May 2017 18:27:14 +0900 Subject: [PATCH 5/8] Fix chat input box not always keeping focus as expected --- osu.Game/Overlays/ChatOverlay.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/osu.Game/Overlays/ChatOverlay.cs b/osu.Game/Overlays/ChatOverlay.cs index 457611dfab..dc586bd363 100644 --- a/osu.Game/Overlays/ChatOverlay.cs +++ b/osu.Game/Overlays/ChatOverlay.cs @@ -110,12 +110,18 @@ namespace osu.Game.Overlays { MoveToY(0, transition_length, EasingTypes.OutQuint); FadeIn(transition_length, EasingTypes.OutQuint); + + inputTextBox.HoldFocus = true; + base.PopIn(); } protected override void PopOut() { MoveToY(DrawSize.Y, transition_length, EasingTypes.InSine); FadeOut(transition_length, EasingTypes.InSine); + + inputTextBox.HoldFocus = false; + base.PopOut(); } [BackgroundDependencyLoader] From 7d221802a2fa0dc81f78204c644a6b861f23c746 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 May 2017 19:27:02 +0900 Subject: [PATCH 6/8] Fix refresh tokens not working correctly Turns out there's plenty of slashes in refresh tokens. --- osu.Game/Online/API/OAuthToken.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Online/API/OAuthToken.cs b/osu.Game/Online/API/OAuthToken.cs index 4085e5602a..328888ab8a 100644 --- a/osu.Game/Online/API/OAuthToken.cs +++ b/osu.Game/Online/API/OAuthToken.cs @@ -41,13 +41,13 @@ namespace osu.Game.Online.API [JsonProperty(@"refresh_token")] public string RefreshToken; - public override string ToString() => $@"{AccessToken}/{AccessTokenExpiry.ToString(NumberFormatInfo.InvariantInfo)}/{RefreshToken}"; + public override string ToString() => $@"{AccessToken}|{AccessTokenExpiry.ToString(NumberFormatInfo.InvariantInfo)}|{RefreshToken}"; public static OAuthToken Parse(string value) { try { - string[] parts = value.Split('/'); + string[] parts = value.Split('|'); return new OAuthToken { AccessToken = parts[0], From 4e881644f60995a90325d99f77d00a99fad354a9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 May 2017 19:35:07 +0900 Subject: [PATCH 7/8] Add thread-safety on access token validation logic. --- osu.Game/Online/API/OAuth.cs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/osu.Game/Online/API/OAuth.cs b/osu.Game/Online/API/OAuth.cs index 0ee7e0e030..2f841b67b1 100644 --- a/osu.Game/Online/API/OAuth.cs +++ b/osu.Game/Online/API/OAuth.cs @@ -72,21 +72,28 @@ namespace osu.Game.Online.API } } + private static readonly object access_token_retrieval_lock = new object(); + /// /// Should be run before any API request to make sure we have a valid key. /// private bool ensureAccessToken() { - //todo: we need to mutex this to ensure only one authentication request is running at a time. - - //If we already have a valid access token, let's use it. + // if we already have a valid access token, let's use it. if (accessTokenValid) return true; - //If not, let's try using our refresh token to request a new access token. - if (!string.IsNullOrEmpty(Token?.RefreshToken)) - AuthenticateWithRefresh(Token.RefreshToken); + // we want to ensure only a single authentication update is happening at once. + lock (access_token_retrieval_lock) + { + // re-check if valid, in case another requrest completed and revalidated our access. + if (accessTokenValid) return true; - return accessTokenValid; + // if not, let's try using our refresh token to request a new access token. + if (!string.IsNullOrEmpty(Token?.RefreshToken)) + AuthenticateWithRefresh(Token.RefreshToken); + + return accessTokenValid; + } } private bool accessTokenValid => Token?.IsValid ?? false; From c3d2cdd2f2ab15c353a08f403fc1a55de06a71f6 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 May 2017 19:49:28 +0900 Subject: [PATCH 8/8] Fix typo --- osu.Game/Online/API/OAuth.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Online/API/OAuth.cs b/osu.Game/Online/API/OAuth.cs index 2f841b67b1..c96b21a855 100644 --- a/osu.Game/Online/API/OAuth.cs +++ b/osu.Game/Online/API/OAuth.cs @@ -85,7 +85,7 @@ namespace osu.Game.Online.API // we want to ensure only a single authentication update is happening at once. lock (access_token_retrieval_lock) { - // re-check if valid, in case another requrest completed and revalidated our access. + // re-check if valid, in case another request completed and revalidated our access. if (accessTokenValid) return true; // if not, let's try using our refresh token to request a new access token.