2019-01-24 08:43:03 +00:00
|
|
|
// 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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2018-12-17 05:45:06 +00:00
|
|
|
using System;
|
2018-12-03 11:50:40 +00:00
|
|
|
using System.Linq;
|
2018-12-12 07:06:56 +00:00
|
|
|
using Newtonsoft.Json;
|
2019-02-05 10:00:01 +00:00
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
using osu.Framework.Bindables;
|
2018-12-26 07:46:50 +00:00
|
|
|
using osu.Game.Online.Multiplayer.GameTypes;
|
2018-12-27 04:30:36 +00:00
|
|
|
using osu.Game.Online.Multiplayer.RoomStatuses;
|
2018-04-13 09:19:50 +00:00
|
|
|
using osu.Game.Users;
|
|
|
|
|
|
|
|
namespace osu.Game.Online.Multiplayer
|
|
|
|
{
|
|
|
|
public class Room
|
|
|
|
{
|
2019-02-05 10:00:01 +00:00
|
|
|
[Cached]
|
2018-12-12 10:04:11 +00:00
|
|
|
[JsonProperty("id")]
|
2018-12-17 05:45:06 +00:00
|
|
|
public Bindable<int?> RoomID { get; private set; } = new Bindable<int?>();
|
2018-12-12 07:06:56 +00:00
|
|
|
|
2019-02-05 10:00:01 +00:00
|
|
|
[Cached]
|
2018-12-12 07:06:56 +00:00
|
|
|
[JsonProperty("name")]
|
2018-12-26 07:11:40 +00:00
|
|
|
public Bindable<string> Name { get; private set; } = new Bindable<string>();
|
2018-12-12 07:06:56 +00:00
|
|
|
|
2019-02-05 10:00:01 +00:00
|
|
|
[Cached]
|
2018-12-12 07:06:56 +00:00
|
|
|
[JsonProperty("host")]
|
2018-12-17 05:45:06 +00:00
|
|
|
public Bindable<User> Host { get; private set; } = new Bindable<User>();
|
2018-12-12 10:04:11 +00:00
|
|
|
|
2019-02-05 10:00:01 +00:00
|
|
|
[Cached]
|
2018-12-12 07:06:56 +00:00
|
|
|
[JsonProperty("playlist")]
|
2019-02-05 10:00:01 +00:00
|
|
|
public BindableList<PlaylistItem> Playlist { get; private set; } = new BindableList<PlaylistItem>();
|
2018-12-12 07:06:56 +00:00
|
|
|
|
2019-02-05 10:00:01 +00:00
|
|
|
[Cached]
|
2018-12-21 05:01:06 +00:00
|
|
|
[JsonProperty("channel_id")]
|
|
|
|
public Bindable<int> ChannelId { get; private set; } = new Bindable<int>();
|
|
|
|
|
2019-02-05 10:00:01 +00:00
|
|
|
[Cached]
|
2018-12-17 05:44:54 +00:00
|
|
|
[JsonIgnore]
|
2018-12-21 04:06:11 +00:00
|
|
|
public Bindable<TimeSpan> Duration { get; private set; } = new Bindable<TimeSpan>(TimeSpan.FromMinutes(30));
|
2018-12-12 10:04:11 +00:00
|
|
|
|
2019-02-05 10:00:01 +00:00
|
|
|
[Cached]
|
2018-12-13 07:06:30 +00:00
|
|
|
[JsonIgnore]
|
2018-12-21 04:06:11 +00:00
|
|
|
public Bindable<int?> MaxAttempts { get; private set; } = new Bindable<int?>();
|
2018-12-13 07:06:30 +00:00
|
|
|
|
2019-02-05 10:00:01 +00:00
|
|
|
[Cached]
|
2018-12-17 05:45:06 +00:00
|
|
|
[JsonIgnore]
|
2018-12-21 04:06:11 +00:00
|
|
|
public Bindable<RoomStatus> Status { get; private set; } = new Bindable<RoomStatus>(new RoomStatusOpen());
|
2018-12-17 05:45:06 +00:00
|
|
|
|
2019-02-05 10:00:01 +00:00
|
|
|
[Cached]
|
2018-12-17 05:45:06 +00:00
|
|
|
[JsonIgnore]
|
2018-12-21 04:06:11 +00:00
|
|
|
public Bindable<RoomAvailability> Availability { get; private set; } = new Bindable<RoomAvailability>();
|
2018-12-17 05:45:06 +00:00
|
|
|
|
2019-02-05 10:00:01 +00:00
|
|
|
[Cached]
|
2018-12-17 05:45:06 +00:00
|
|
|
[JsonIgnore]
|
2018-12-21 04:06:11 +00:00
|
|
|
public Bindable<GameType> Type { get; private set; } = new Bindable<GameType>(new GameTypeTimeshift());
|
2018-12-17 05:45:06 +00:00
|
|
|
|
2019-02-05 10:00:01 +00:00
|
|
|
[Cached]
|
2018-12-17 05:45:06 +00:00
|
|
|
[JsonIgnore]
|
2018-12-21 04:06:11 +00:00
|
|
|
public Bindable<int?> MaxParticipants { get; private set; } = new Bindable<int?>();
|
2018-12-17 05:45:06 +00:00
|
|
|
|
2019-02-05 10:00:01 +00:00
|
|
|
[Cached]
|
2020-02-27 10:24:13 +00:00
|
|
|
[JsonProperty("recent_participants")]
|
2020-02-27 10:42:28 +00:00
|
|
|
public BindableList<User> RecentParticipants { get; private set; } = new BindableList<User>();
|
2018-12-17 05:45:06 +00:00
|
|
|
|
2019-02-05 10:00:01 +00:00
|
|
|
[Cached]
|
2018-12-26 12:58:14 +00:00
|
|
|
public Bindable<int> ParticipantCount { get; private set; } = new Bindable<int>();
|
|
|
|
|
2018-12-26 13:25:15 +00:00
|
|
|
// todo: TEMPORARY
|
|
|
|
[JsonProperty("participant_count")]
|
|
|
|
private int? participantCount
|
|
|
|
{
|
2019-02-21 09:56:34 +00:00
|
|
|
get => ParticipantCount.Value;
|
2018-12-26 13:25:15 +00:00
|
|
|
set => ParticipantCount.Value = value ?? 0;
|
|
|
|
}
|
|
|
|
|
2018-12-17 05:44:54 +00:00
|
|
|
[JsonProperty("duration")]
|
|
|
|
private int duration
|
|
|
|
{
|
|
|
|
get => (int)Duration.Value.TotalMinutes;
|
|
|
|
set => Duration.Value = TimeSpan.FromMinutes(value);
|
|
|
|
}
|
2018-12-17 05:45:06 +00:00
|
|
|
|
2018-12-19 01:52:15 +00:00
|
|
|
// Only supports retrieval for now
|
2019-02-05 10:00:01 +00:00
|
|
|
[Cached]
|
2018-12-19 01:52:15 +00:00
|
|
|
[JsonProperty("ends_at")]
|
2018-12-21 04:06:11 +00:00
|
|
|
public Bindable<DateTimeOffset> EndDate { get; private set; } = new Bindable<DateTimeOffset>();
|
2018-12-19 01:52:15 +00:00
|
|
|
|
2018-12-13 07:06:30 +00:00
|
|
|
// Todo: Find a better way to do this (https://github.com/ppy/osu-framework/issues/1930)
|
|
|
|
[JsonProperty("max_attempts", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
|
|
|
private int? maxAttempts
|
|
|
|
{
|
2019-02-21 09:56:34 +00:00
|
|
|
get => MaxAttempts.Value;
|
2018-12-13 07:06:30 +00:00
|
|
|
set => MaxAttempts.Value = value;
|
|
|
|
}
|
2018-12-12 10:04:11 +00:00
|
|
|
|
2018-12-27 16:45:19 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The position of this <see cref="Room"/> in the list. This is not read from or written to the API.
|
|
|
|
/// </summary>
|
|
|
|
[JsonIgnore]
|
2019-02-05 06:56:18 +00:00
|
|
|
public Bindable<int> Position { get; private set; } = new Bindable<int>(-1);
|
2018-12-27 16:45:19 +00:00
|
|
|
|
2018-12-12 07:06:56 +00:00
|
|
|
public void CopyFrom(Room other)
|
|
|
|
{
|
2019-02-21 09:56:34 +00:00
|
|
|
RoomID.Value = other.RoomID.Value;
|
|
|
|
Name.Value = other.Name.Value;
|
2018-12-25 09:07:50 +00:00
|
|
|
|
|
|
|
if (other.Host.Value != null && Host.Value?.Id != other.Host.Value.Id)
|
2019-02-21 09:56:34 +00:00
|
|
|
Host.Value = other.Host.Value;
|
2018-12-25 09:07:50 +00:00
|
|
|
|
2019-03-07 06:35:57 +00:00
|
|
|
ChannelId.Value = other.ChannelId.Value;
|
2019-02-21 09:56:34 +00:00
|
|
|
Status.Value = other.Status.Value;
|
|
|
|
Availability.Value = other.Availability.Value;
|
|
|
|
Type.Value = other.Type.Value;
|
|
|
|
MaxParticipants.Value = other.MaxParticipants.Value;
|
2018-12-26 12:58:14 +00:00
|
|
|
ParticipantCount.Value = other.ParticipantCount.Value;
|
2019-02-21 09:56:34 +00:00
|
|
|
EndDate.Value = other.EndDate.Value;
|
2018-12-17 02:04:38 +00:00
|
|
|
|
2018-12-27 04:30:36 +00:00
|
|
|
if (DateTimeOffset.Now >= EndDate.Value)
|
|
|
|
Status.Value = new RoomStatusEnded();
|
|
|
|
|
2020-02-16 07:23:46 +00:00
|
|
|
if (!Playlist.SequenceEqual(other.Playlist))
|
|
|
|
{
|
|
|
|
Playlist.Clear();
|
|
|
|
Playlist.AddRange(other.Playlist);
|
|
|
|
}
|
2018-12-27 16:45:19 +00:00
|
|
|
|
2020-02-27 10:42:28 +00:00
|
|
|
if (!RecentParticipants.SequenceEqual(other.RecentParticipants))
|
2020-02-16 07:23:46 +00:00
|
|
|
{
|
2020-02-27 10:42:28 +00:00
|
|
|
RecentParticipants.Clear();
|
|
|
|
RecentParticipants.AddRange(other.RecentParticipants);
|
2020-02-16 07:23:46 +00:00
|
|
|
}
|
2020-02-13 09:59:15 +00:00
|
|
|
|
2018-12-27 16:45:19 +00:00
|
|
|
Position = other.Position;
|
2018-12-12 07:06:56 +00:00
|
|
|
}
|
2018-12-17 02:04:38 +00:00
|
|
|
|
2018-12-17 05:45:06 +00:00
|
|
|
public bool ShouldSerializeRoomID() => false;
|
|
|
|
public bool ShouldSerializeHost() => false;
|
2018-12-19 01:52:15 +00:00
|
|
|
public bool ShouldSerializeEndDate() => false;
|
2018-12-12 07:06:56 +00:00
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|