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-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.Beatmaps;
|
2018-12-12 15:06:56 +08:00
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Game.Users;
|
|
|
|
|
|
|
|
namespace osu.Game.Online.Multiplayer
|
|
|
|
{
|
|
|
|
public class Room
|
|
|
|
{
|
2018-12-12 15:06:56 +08:00
|
|
|
public Bindable<int> RoomID { get; } = new Bindable<int>();
|
|
|
|
|
|
|
|
[JsonProperty("name")]
|
|
|
|
public readonly Bindable<string> Name = new Bindable<string>("My awesome room!");
|
|
|
|
|
|
|
|
[JsonProperty("host")]
|
|
|
|
public readonly Bindable<User> Host = new Bindable<User>();
|
|
|
|
|
|
|
|
[JsonProperty("playlist")]
|
|
|
|
public readonly BindableCollection<PlaylistItem> Playlist = new BindableCollection<PlaylistItem>();
|
|
|
|
|
2018-12-03 17:30:26 +08:00
|
|
|
public Bindable<RoomStatus> Status = new Bindable<RoomStatus>(new RoomStatusOpen());
|
2018-05-22 11:24:39 +08:00
|
|
|
public Bindable<RoomAvailability> Availability = new Bindable<RoomAvailability>();
|
2018-12-04 17:58:45 +08:00
|
|
|
public Bindable<GameType> Type = new Bindable<GameType>(new GameTypeTimeshift());
|
2018-04-13 17:19:50 +08:00
|
|
|
public Bindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
|
|
|
|
public Bindable<int?> MaxParticipants = new Bindable<int?>();
|
2018-12-03 19:50:40 +08:00
|
|
|
public Bindable<IEnumerable<User>> Participants = new Bindable<IEnumerable<User>>(Enumerable.Empty<User>());
|
2018-12-10 17:00:57 +08:00
|
|
|
|
2018-12-12 15:06:56 +08:00
|
|
|
public void CopyFrom(Room other)
|
|
|
|
{
|
|
|
|
Name.Value = other.Name;
|
|
|
|
Host.Value = other.Host;
|
|
|
|
Status.Value = other.Status;
|
|
|
|
Availability.Value = other.Availability;
|
|
|
|
Type.Value = other.Type;
|
|
|
|
Beatmap.Value = other.Beatmap;
|
|
|
|
MaxParticipants.Value = other.MaxParticipants;
|
|
|
|
Participants.Value = other.Participants.Value.ToArray();
|
|
|
|
}
|
|
|
|
|
2018-12-10 17:00:57 +08:00
|
|
|
public Bindable<bool> Created = new Bindable<bool>();
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
2018-12-12 15:06:56 +08:00
|
|
|
|
|
|
|
public class PlaylistItem
|
|
|
|
{
|
|
|
|
[JsonProperty("beatmap")]
|
|
|
|
public BeatmapInfo Beatmap;
|
|
|
|
|
|
|
|
[JsonProperty("ruleset_id")]
|
|
|
|
public int RulesetID { get; set; }
|
|
|
|
|
|
|
|
public readonly BindableCollection<Mod> AllowedMods = new BindableCollection<Mod>();
|
|
|
|
|
|
|
|
public readonly BindableCollection<Mod> RequiredMods = new BindableCollection<Mod>();
|
|
|
|
|
|
|
|
private APIMod[] _allowedMods;
|
|
|
|
|
|
|
|
[JsonProperty("allowed_mods")]
|
|
|
|
private APIMod[] allowedMods
|
|
|
|
{
|
|
|
|
get => AllowedMods.Select(m => new APIMod { Acronym = m.Acronym }).ToArray();
|
|
|
|
set => _allowedMods = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
private APIMod[] _requiredMods;
|
|
|
|
|
|
|
|
[JsonProperty("required_mods")]
|
|
|
|
private APIMod[] requiredMods
|
|
|
|
{
|
|
|
|
get => RequiredMods.Select(m => new APIMod { Acronym = m.Acronym }).ToArray();
|
|
|
|
set => _requiredMods = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
private RulesetInfo ruleset;
|
|
|
|
|
|
|
|
public RulesetInfo Ruleset
|
|
|
|
{
|
|
|
|
get => ruleset;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
ruleset = value;
|
|
|
|
|
|
|
|
if (_allowedMods != null)
|
|
|
|
{
|
|
|
|
AllowedMods.Clear();
|
|
|
|
AllowedMods.AddRange(value.CreateInstance().GetAllMods().Where(mod => _allowedMods.Any(m => m.Acronym == mod.Acronym)));
|
|
|
|
|
|
|
|
_allowedMods = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_requiredMods != null)
|
|
|
|
{
|
|
|
|
RequiredMods.Clear();
|
|
|
|
RequiredMods.AddRange(value.CreateInstance().GetAllMods().Where(mod => _requiredMods.Any(m => m.Acronym == mod.Acronym)));
|
|
|
|
|
|
|
|
_requiredMods = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Todo: Move this elsewhere for reusability
|
|
|
|
private class APIMod : IMod
|
|
|
|
{
|
|
|
|
public string Acronym { get; set; }
|
|
|
|
}
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|