1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 09:42:54 +08:00
osu-lazer/osu.Game/Online/Multiplayer/Room.cs

145 lines
4.7 KiB
C#
Raw Normal View History

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