// Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; using osu.Framework.Configuration; using osu.Game.Online.Multiplayer.GameTypes; using osu.Game.Users; namespace osu.Game.Online.Multiplayer { public class Room { [JsonProperty("id")] public Bindable RoomID { get; private set; } = new Bindable(); [JsonProperty("name")] public Bindable Name { get; private set; } = new Bindable(); [JsonProperty("host")] public Bindable Host { get; private set; } = new Bindable(); [JsonProperty("playlist")] public BindableCollection Playlist { get; set; } = new BindableCollection(); [JsonProperty("channel_id")] public Bindable ChannelId { get; private set; } = new Bindable(); [JsonIgnore] public Bindable Duration { get; private set; } = new Bindable(TimeSpan.FromMinutes(30)); [JsonIgnore] public Bindable MaxAttempts { get; private set; } = new Bindable(); [JsonIgnore] public Bindable Status { get; private set; } = new Bindable(new RoomStatusOpen()); [JsonIgnore] public Bindable Availability { get; private set; } = new Bindable(); [JsonIgnore] public Bindable Type { get; private set; } = new Bindable(new GameTypeTimeshift()); [JsonIgnore] public Bindable MaxParticipants { get; private set; } = new Bindable(); [JsonIgnore] public Bindable> Participants { get; private set; } = new Bindable>(Enumerable.Empty()); [JsonProperty("participant_count")] public Bindable ParticipantCount { get; private set; } = new Bindable(); [JsonProperty("duration")] private int duration { get => (int)Duration.Value.TotalMinutes; set => Duration.Value = TimeSpan.FromMinutes(value); } // Only supports retrieval for now [JsonProperty("ends_at")] public Bindable EndDate { get; private set; } = new Bindable(); // 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 { get => MaxAttempts; set => MaxAttempts.Value = value; } public void CopyFrom(Room other) { RoomID.Value = other.RoomID; Name.Value = other.Name; if (other.Host.Value != null && Host.Value?.Id != other.Host.Value.Id) Host.Value = other.Host; if (Status.Value.GetType() != other.Status.Value.GetType()) Status.Value = other.Status; Availability.Value = other.Availability; if (Type.Value.GetType() != other.Type.Value.GetType()) Type.Value = other.Type; MaxParticipants.Value = other.MaxParticipants; ParticipantCount.Value = other.ParticipantCount.Value; Participants.Value = other.Participants.Value.ToArray(); EndDate.Value = other.EndDate; // Todo: Temporary, should only remove/add new items (requires framework changes) if (Playlist.Count == 0) Playlist.AddRange(other.Playlist); else if (other.Playlist.Count > 0) Playlist.First().ID = other.Playlist.First().ID; } public bool ShouldSerializeRoomID() => false; public bool ShouldSerializeHost() => false; public bool ShouldSerializeEndDate() => false; } }