From 42e49067e55ddb232d6fe1af0af44234a772f5fc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 3 May 2024 17:10:59 +0800 Subject: [PATCH] Move `Room.Status` updates to a common location --- osu.Game/Online/Rooms/GetRoomsRequest.cs | 19 +++++++++++++++++++ osu.Game/Online/Rooms/Room.cs | 6 ++---- .../Lounge/Components/RoomStatusPill.cs | 12 +----------- .../Screens/OnlinePlay/OnlinePlayComposite.cs | 3 +++ 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/osu.Game/Online/Rooms/GetRoomsRequest.cs b/osu.Game/Online/Rooms/GetRoomsRequest.cs index 7feb709acb..bfb2629c64 100644 --- a/osu.Game/Online/Rooms/GetRoomsRequest.cs +++ b/osu.Game/Online/Rooms/GetRoomsRequest.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. +using System; using System.Collections.Generic; using osu.Framework.IO.Network; using osu.Game.Extensions; using osu.Game.Online.API; +using osu.Game.Online.Rooms.RoomStatuses; using osu.Game.Screens.OnlinePlay.Lounge.Components; namespace osu.Game.Online.Rooms @@ -33,6 +35,23 @@ namespace osu.Game.Online.Rooms return req; } + protected override void PostProcess() + { + base.PostProcess(); + + if (Response != null) + { + // API doesn't populate status so let's do it here. + foreach (var room in Response) + { + if (room.EndDate.Value != null && DateTimeOffset.Now >= room.EndDate.Value) + room.Status.Value = new RoomStatusEnded(); + else + room.Status.Value = new RoomStatusOpen(); + } + } + } + protected override string Target => "rooms"; } } diff --git a/osu.Game/Online/Rooms/Room.cs b/osu.Game/Online/Rooms/Room.cs index 8f346c4057..23c77f8773 100644 --- a/osu.Game/Online/Rooms/Room.cs +++ b/osu.Game/Online/Rooms/Room.cs @@ -111,8 +111,9 @@ namespace osu.Game.Online.Rooms [JsonProperty("current_user_score")] public readonly Bindable UserScore = new Bindable(); + [Cached] [JsonProperty("has_password")] - public readonly BindableBool HasPassword = new BindableBool(); + public readonly Bindable HasPassword = new Bindable(); [Cached] [JsonProperty("recent_participants")] @@ -201,9 +202,6 @@ namespace osu.Game.Online.Rooms CurrentPlaylistItem.Value = other.CurrentPlaylistItem.Value; AutoSkip.Value = other.AutoSkip.Value; - if (EndDate.Value != null && DateTimeOffset.Now >= EndDate.Value) - Status.Value = new RoomStatusEnded(); - other.RemoveExpiredPlaylistItems(); if (!Playlist.SequenceEqual(other.Playlist)) diff --git a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs index aae82b6721..96d698a184 100644 --- a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs +++ b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.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; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; using osu.Game.Graphics; using osu.Game.Online.Rooms; -using osu.Game.Online.Rooms.RoomStatuses; namespace osu.Game.Screens.OnlinePlay.Lounge.Components { @@ -36,18 +34,10 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components private void updateDisplay() { - RoomStatus status = getDisplayStatus(); + RoomStatus status = Status.Value; Pill.Background.FadeColour(status.GetAppropriateColour(colours), 100); TextFlow.Text = status.Message; } - - private RoomStatus getDisplayStatus() - { - if (EndDate.Value < DateTimeOffset.Now) - return new RoomStatusEnded(); - - return Status.Value; - } } } diff --git a/osu.Game/Screens/OnlinePlay/OnlinePlayComposite.cs b/osu.Game/Screens/OnlinePlay/OnlinePlayComposite.cs index ff536a65c4..83df1c6161 100644 --- a/osu.Game/Screens/OnlinePlay/OnlinePlayComposite.cs +++ b/osu.Game/Screens/OnlinePlay/OnlinePlayComposite.cs @@ -77,6 +77,9 @@ namespace osu.Game.Screens.OnlinePlay [Resolved(typeof(Room))] public Bindable Password { get; private set; } + [Resolved(typeof(Room))] + public Bindable HasPassword { get; private set; } + [Resolved(typeof(Room))] protected Bindable Duration { get; private set; }