From 439d741dee62f95c67547afe116c858d1c28e484 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 12 Dec 2018 16:06:56 +0900 Subject: [PATCH] Implement basic api structure for rooms --- osu.Game/Online/Multiplayer/Room.cs | 92 ++++++++++++++++++++++++++++- osu.Game/Rulesets/Mods/IMod.cs | 3 + 2 files changed, 93 insertions(+), 2 deletions(-) diff --git a/osu.Game/Online/Multiplayer/Room.cs b/osu.Game/Online/Multiplayer/Room.cs index 67ddb60823..71668e4c4b 100644 --- a/osu.Game/Online/Multiplayer/Room.cs +++ b/osu.Game/Online/Multiplayer/Room.cs @@ -3,16 +3,28 @@ using System.Collections.Generic; using System.Linq; +using Newtonsoft.Json; using osu.Framework.Configuration; using osu.Game.Beatmaps; +using osu.Game.Rulesets; +using osu.Game.Rulesets.Mods; using osu.Game.Users; namespace osu.Game.Online.Multiplayer { public class Room { - public Bindable Name = new Bindable("My awesome room!"); - public Bindable Host = new Bindable(); + public Bindable RoomID { get; } = new Bindable(); + + [JsonProperty("name")] + public readonly Bindable Name = new Bindable("My awesome room!"); + + [JsonProperty("host")] + public readonly Bindable Host = new Bindable(); + + [JsonProperty("playlist")] + public readonly BindableCollection Playlist = new BindableCollection(); + public Bindable Status = new Bindable(new RoomStatusOpen()); public Bindable Availability = new Bindable(); public Bindable Type = new Bindable(new GameTypeTimeshift()); @@ -20,6 +32,82 @@ namespace osu.Game.Online.Multiplayer public Bindable MaxParticipants = new Bindable(); public Bindable> Participants = new Bindable>(Enumerable.Empty()); + 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(); + } + public Bindable Created = new Bindable(); } + + public class PlaylistItem + { + [JsonProperty("beatmap")] + public BeatmapInfo Beatmap; + + [JsonProperty("ruleset_id")] + public int RulesetID { get; set; } + + public readonly BindableCollection AllowedMods = new BindableCollection(); + + public readonly BindableCollection RequiredMods = new BindableCollection(); + + 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; } + } + } } diff --git a/osu.Game/Rulesets/Mods/IMod.cs b/osu.Game/Rulesets/Mods/IMod.cs index d0c4ce2f4c..4a95ce8111 100644 --- a/osu.Game/Rulesets/Mods/IMod.cs +++ b/osu.Game/Rulesets/Mods/IMod.cs @@ -1,6 +1,8 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using Newtonsoft.Json; + namespace osu.Game.Rulesets.Mods { public interface IMod @@ -8,6 +10,7 @@ namespace osu.Game.Rulesets.Mods /// /// The shortened name of this mod. /// + [JsonProperty] string Acronym { get; } } }