2018-04-13 17:19:50 +08:00
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
2018-12-17 13:45:06 +08:00
|
|
|
using System;
|
2018-06-01 17:15:23 +08:00
|
|
|
using System.Collections.Generic;
|
2018-12-03 19:50:40 +08:00
|
|
|
using System.Linq;
|
2018-12-12 15:06:56 +08:00
|
|
|
using Newtonsoft.Json;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Framework.Configuration;
|
|
|
|
using osu.Game.Users;
|
|
|
|
|
|
|
|
namespace osu.Game.Online.Multiplayer
|
|
|
|
{
|
|
|
|
public class Room
|
|
|
|
{
|
2018-12-12 18:04:11 +08:00
|
|
|
[JsonProperty("id")]
|
2018-12-17 13:45:06 +08:00
|
|
|
public Bindable<int?> RoomID { get; private set; } = new Bindable<int?>();
|
2018-12-12 15:06:56 +08:00
|
|
|
|
|
|
|
[JsonProperty("name")]
|
2018-12-17 13:45:06 +08:00
|
|
|
public Bindable<string> Name { get; private set; } = new Bindable<string>("My awesome room!");
|
2018-12-12 15:06:56 +08:00
|
|
|
|
|
|
|
[JsonProperty("host")]
|
2018-12-17 13:45:06 +08:00
|
|
|
public Bindable<User> Host { get; private set; } = new Bindable<User>();
|
2018-12-12 18:04:11 +08:00
|
|
|
|
2018-12-12 15:06:56 +08:00
|
|
|
[JsonProperty("playlist")]
|
|
|
|
public readonly BindableCollection<PlaylistItem> Playlist = new BindableCollection<PlaylistItem>();
|
|
|
|
|
2018-12-17 13:44:54 +08:00
|
|
|
[JsonIgnore]
|
|
|
|
public readonly Bindable<TimeSpan> Duration = new Bindable<TimeSpan>(TimeSpan.FromMinutes(30));
|
2018-12-12 18:04:11 +08:00
|
|
|
|
2018-12-13 15:06:30 +08:00
|
|
|
[JsonIgnore]
|
|
|
|
public readonly Bindable<int?> MaxAttempts = new Bindable<int?>();
|
|
|
|
|
2018-12-17 13:45:06 +08:00
|
|
|
[JsonIgnore]
|
|
|
|
public Bindable<RoomStatus> Status = new Bindable<RoomStatus>(new RoomStatusOpen());
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
public Bindable<RoomAvailability> Availability = new Bindable<RoomAvailability>();
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
public Bindable<GameType> Type = new Bindable<GameType>(new GameTypeTimeshift());
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
public Bindable<int?> MaxParticipants = new Bindable<int?>();
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
public Bindable<IEnumerable<User>> Participants = new Bindable<IEnumerable<User>>(Enumerable.Empty<User>());
|
|
|
|
|
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
|
|
|
|
2018-12-19 09:52:15 +08:00
|
|
|
// Only supports retrieval for now
|
|
|
|
[JsonProperty("ends_at")]
|
|
|
|
public 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
|
|
|
|
{
|
|
|
|
get => MaxAttempts;
|
|
|
|
set => MaxAttempts.Value = value;
|
|
|
|
}
|
2018-12-12 18:04:11 +08:00
|
|
|
|
2018-12-12 15:06:56 +08:00
|
|
|
public void CopyFrom(Room other)
|
|
|
|
{
|
2018-12-12 15:20:11 +08:00
|
|
|
RoomID.Value = other.RoomID;
|
2018-12-12 15:06:56 +08:00
|
|
|
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();
|
2018-12-19 09:52:15 +08:00
|
|
|
EndDate = other.EndDate;
|
2018-12-17 10:04:38 +08:00
|
|
|
|
|
|
|
Playlist.Clear();
|
|
|
|
Playlist.AddRange(other.Playlist);
|
2018-12-12 15:06:56 +08:00
|
|
|
}
|
2018-12-17 10:04:38 +08:00
|
|
|
|
2018-12-17 13:45:06 +08:00
|
|
|
public bool ShouldSerializeRoomID() => false;
|
|
|
|
public bool ShouldSerializeHost() => false;
|
2018-12-19 09:52:15 +08:00
|
|
|
public bool ShouldSerializeEndDate() => false;
|
2018-12-12 15:06:56 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|