mirror of
https://github.com/ppy/osu.git
synced 2025-01-07 21:32:57 +08:00
Merge pull request #30805 from smoogipoo/fix-playlists-enter-status
Fix playlist room status resetting on enter
This commit is contained in:
commit
2eef920e70
@ -0,0 +1,41 @@
|
|||||||
|
// 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 NUnit.Framework;
|
||||||
|
using osu.Framework.Screens;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
using osu.Game.Online.Rooms;
|
||||||
|
using osu.Game.Online.Rooms.RoomStatuses;
|
||||||
|
using osu.Game.Screens.OnlinePlay.Playlists;
|
||||||
|
using osu.Game.Tests.Visual.OnlinePlay;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Playlists
|
||||||
|
{
|
||||||
|
public partial class TestScenePlaylistsRoomSubScreen : OnlinePlayTestScene
|
||||||
|
{
|
||||||
|
protected new TestRoomManager RoomManager => (TestRoomManager)base.RoomManager;
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestStatusUpdateOnEnter()
|
||||||
|
{
|
||||||
|
Room room = null!;
|
||||||
|
PlaylistsRoomSubScreen roomScreen = null!;
|
||||||
|
|
||||||
|
AddStep("create room", () =>
|
||||||
|
{
|
||||||
|
RoomManager.AddRoom(room = new Room
|
||||||
|
{
|
||||||
|
Name = @"Test Room",
|
||||||
|
Host = new APIUser { Username = @"Host" },
|
||||||
|
Category = RoomCategory.Normal,
|
||||||
|
EndDate = DateTimeOffset.Now.AddMinutes(-1)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep("push screen", () => LoadScreen(roomScreen = new PlaylistsRoomSubScreen(room)));
|
||||||
|
AddUntilStep("wait for screen load", () => roomScreen.IsCurrentScreen());
|
||||||
|
AddAssert("status is still ended", () => roomScreen.Room.Status, Is.TypeOf<RoomStatusEnded>);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,10 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using osu.Framework.IO.Network;
|
using osu.Framework.IO.Network;
|
||||||
using osu.Game.Extensions;
|
using osu.Game.Extensions;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.Rooms.RoomStatuses;
|
|
||||||
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
||||||
|
|
||||||
namespace osu.Game.Online.Rooms
|
namespace osu.Game.Online.Rooms
|
||||||
@ -35,25 +33,6 @@ namespace osu.Game.Online.Rooms
|
|||||||
return req;
|
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 != null && DateTimeOffset.Now >= room.EndDate)
|
|
||||||
room.Status = new RoomStatusEnded();
|
|
||||||
else if (room.HasPassword)
|
|
||||||
room.Status = new RoomStatusOpenPrivate();
|
|
||||||
else
|
|
||||||
room.Status = new RoomStatusOpen();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override string Target => "rooms";
|
protected override string Target => "rooms";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using osu.Game.IO.Serialization.Converters;
|
using osu.Game.IO.Serialization.Converters;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
@ -264,6 +265,18 @@ namespace osu.Game.Online.Rooms
|
|||||||
set => SetField(ref availability, value);
|
set => SetField(ref availability, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[OnDeserialized]
|
||||||
|
private void onDeserialised(StreamingContext context)
|
||||||
|
{
|
||||||
|
// API doesn't populate status so let's do it here.
|
||||||
|
if (EndDate != null && DateTimeOffset.Now >= EndDate)
|
||||||
|
Status = new RoomStatusEnded();
|
||||||
|
else if (HasPassword)
|
||||||
|
Status = new RoomStatusOpenPrivate();
|
||||||
|
else
|
||||||
|
Status = new RoomStatusOpen();
|
||||||
|
}
|
||||||
|
|
||||||
[JsonProperty("id")]
|
[JsonProperty("id")]
|
||||||
private long? roomId;
|
private long? roomId;
|
||||||
|
|
||||||
|
@ -29,38 +29,28 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
var room = new Room
|
AddRoom(new Room
|
||||||
{
|
{
|
||||||
RoomID = -currentRoomId,
|
|
||||||
Name = $@"Room {currentRoomId}",
|
Name = $@"Room {currentRoomId}",
|
||||||
Host = new APIUser { Username = @"Host" },
|
Host = new APIUser { Username = @"Host" },
|
||||||
Duration = TimeSpan.FromSeconds(10),
|
Duration = TimeSpan.FromSeconds(10),
|
||||||
Category = withSpotlightRooms && i % 2 == 0 ? RoomCategory.Spotlight : RoomCategory.Normal,
|
Category = withSpotlightRooms && i % 2 == 0 ? RoomCategory.Spotlight : RoomCategory.Normal,
|
||||||
};
|
Password = withPassword ? @"password" : null,
|
||||||
|
PlaylistItemStats = ruleset == null
|
||||||
if (withPassword)
|
? null
|
||||||
room.Password = @"password";
|
: new Room.RoomPlaylistItemStats { RulesetIDs = [ruleset.OnlineID] },
|
||||||
|
Playlist = ruleset == null
|
||||||
if (ruleset != null)
|
? Array.Empty<PlaylistItem>()
|
||||||
{
|
: [new PlaylistItem(new BeatmapInfo { Metadata = new BeatmapMetadata() }) { RulesetID = ruleset.OnlineID }]
|
||||||
room.PlaylistItemStats = new Room.RoomPlaylistItemStats
|
});
|
||||||
{
|
|
||||||
RulesetIDs = new[] { ruleset.OnlineID },
|
|
||||||
};
|
|
||||||
|
|
||||||
room.Playlist =
|
|
||||||
[
|
|
||||||
new PlaylistItem(new BeatmapInfo { Metadata = new BeatmapMetadata() })
|
|
||||||
{
|
|
||||||
RulesetID = ruleset.OnlineID,
|
|
||||||
}
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
CreateRoom(room);
|
|
||||||
|
|
||||||
currentRoomId++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddRoom(Room room)
|
||||||
|
{
|
||||||
|
room.RoomID = -currentRoomId;
|
||||||
|
CreateRoom(room);
|
||||||
|
currentRoomId++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user