// 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.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("My awesome room!"); [JsonProperty("host")] public Bindable Host { get; private set; } = new Bindable(); [JsonProperty("playlist")] public readonly BindableCollection Playlist = new BindableCollection(); [JsonIgnore] public readonly Bindable Duration = new Bindable(TimeSpan.FromMinutes(30)); [JsonIgnore] public readonly Bindable MaxAttempts = new Bindable(); [JsonIgnore] public Bindable Status = new Bindable(new RoomStatusOpen()); [JsonIgnore] public Bindable Availability = new Bindable(); [JsonIgnore] public Bindable Type = new Bindable(new GameTypeTimeshift()); [JsonIgnore] public Bindable MaxParticipants = new Bindable(); [JsonIgnore] public Bindable> Participants = new Bindable>(Enumerable.Empty()); [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 = 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; Host.Value = other.Host; Status.Value = other.Status; Availability.Value = other.Availability; Type.Value = other.Type; MaxParticipants.Value = other.MaxParticipants; Participants.Value = other.Participants.Value.ToArray(); EndDate = other.EndDate; Playlist.Clear(); Playlist.AddRange(other.Playlist); } public bool ShouldSerializeRoomID() => false; public bool ShouldSerializeHost() => false; public bool ShouldSerializeEndDate() => false; } }