Move `Room.Status` updates to a common location

This commit is contained in:
Dean Herbert 2024-05-03 17:10:59 +08:00
parent 3840e92576
commit 42e49067e5
No known key found for this signature in database
4 changed files with 25 additions and 15 deletions

View File

@ -1,10 +1,12 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using 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 @@ protected override WebRequest CreateWebRequest()
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";
}
}

View File

@ -111,8 +111,9 @@ private ushort autoStartDuration
[JsonProperty("current_user_score")]
public readonly Bindable<PlaylistAggregateScore> UserScore = new Bindable<PlaylistAggregateScore>();
[Cached]
[JsonProperty("has_password")]
public readonly BindableBool HasPassword = new BindableBool();
public readonly Bindable<bool> HasPassword = new Bindable<bool>();
[Cached]
[JsonProperty("recent_participants")]
@ -201,9 +202,6 @@ public void CopyFrom(Room other)
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))

View File

@ -1,13 +1,11 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using 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 @@ protected override void LoadComplete()
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;
}
}
}

View File

@ -77,6 +77,9 @@ public partial class OnlinePlayComposite : CompositeDrawable
[Resolved(typeof(Room))]
public Bindable<string> Password { get; private set; }
[Resolved(typeof(Room))]
public Bindable<bool> HasPassword { get; private set; }
[Resolved(typeof(Room))]
protected Bindable<TimeSpan?> Duration { get; private set; }