From 2fd2425cc40791f7f6e75f6bb4dc3e721acab35b Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 17 Dec 2018 11:04:38 +0900 Subject: [PATCH] Fix playlist deserialisation for creating rooms --- osu.Game/Online/Multiplayer/Room.cs | 65 +++++++++++++++------------ osu.Game/Screens/Multi/RoomManager.cs | 14 +++--- 2 files changed, 45 insertions(+), 34 deletions(-) diff --git a/osu.Game/Online/Multiplayer/Room.cs b/osu.Game/Online/Multiplayer/Room.cs index 5c24827d44..0317b3c3e8 100644 --- a/osu.Game/Online/Multiplayer/Room.cs +++ b/osu.Game/Online/Multiplayer/Room.cs @@ -59,6 +59,9 @@ namespace osu.Game.Online.Multiplayer Type.Value = other.Type; MaxParticipants.Value = other.MaxParticipants; Participants.Value = other.Participants.Value.ToArray(); + + Playlist.Clear(); + Playlist.AddRange(other.Playlist); } } @@ -68,15 +71,25 @@ namespace osu.Game.Online.Multiplayer public int ID { get; set; } [JsonProperty("beatmap")] - private APIBeatmap beatmap { get; set; } + private APIBeatmap apiBeatmap { get; set; } - public bool ShouldSerializebeatmap() => false; + public bool ShouldSerializeapiBeatmap() => false; + + private BeatmapInfo beatmap; [JsonIgnore] - public BeatmapInfo Beatmap { get; set; } + public BeatmapInfo Beatmap + { + get => beatmap; + set + { + beatmap = value; + BeatmapID = value?.OnlineBeatmapID ?? 0; + } + } [JsonProperty("beatmap_id")] - public int BeatmapID => Beatmap.OnlineBeatmapID ?? 0; + public int BeatmapID { get; set; } [JsonProperty("ruleset_id")] public int RulesetID { get; set; } @@ -105,37 +118,31 @@ namespace osu.Game.Online.Multiplayer set => _requiredMods = value; } - private RulesetInfo ruleset; - [JsonIgnore] - public RulesetInfo Ruleset + public RulesetInfo Ruleset { get; set; } + + public void MapObjects(BeatmapManager beatmaps, RulesetStore rulesets) { - get => ruleset; - set + // If we don't have an api beatmap, the request occurred as a result of room creation, so we can query the local beatmap instead + // Todo: Is this a bug? + Beatmap = apiBeatmap == null ? beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == BeatmapID) : apiBeatmap.ToBeatmap(rulesets); + Ruleset = rulesets.GetRuleset(RulesetID); + + if (_allowedMods != null) { - ruleset = value; + AllowedMods.Clear(); + AllowedMods.AddRange(Ruleset.CreateInstance().GetAllMods().Where(mod => _allowedMods.Any(m => m.Acronym == mod.Acronym))); - 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; - } + _allowedMods = null; } - } - public void SetRulesets(RulesetStore rulesets) - { - Beatmap = beatmap.ToBeatmap(rulesets); + if (_requiredMods != null) + { + RequiredMods.Clear(); + RequiredMods.AddRange(Ruleset.CreateInstance().GetAllMods().Where(mod => _requiredMods.Any(m => m.Acronym == mod.Acronym))); + + _requiredMods = null; + } } // Todo: Move this elsewhere for reusability diff --git a/osu.Game/Screens/Multi/RoomManager.cs b/osu.Game/Screens/Multi/RoomManager.cs index fead90f9a2..7e29aacaf4 100644 --- a/osu.Game/Screens/Multi/RoomManager.cs +++ b/osu.Game/Screens/Multi/RoomManager.cs @@ -63,11 +63,7 @@ namespace osu.Game.Screens.Multi { foreach (var r in result) { - foreach (var pi in r.Playlist) - { - pi.Ruleset = rulesets.GetRuleset(pi.RulesetID); - pi.SetRulesets(rulesets); - } + processPlaylist(r); var existing = rooms.FirstOrDefault(e => e.RoomID.Value == r.RoomID.Value); if (existing == null) @@ -88,6 +84,8 @@ namespace osu.Game.Screens.Multi private void addRoom(Room local, Room remote) { + processPlaylist(remote); + local.CopyFrom(remote); var existing = rooms.FirstOrDefault(e => e.RoomID.Value == local.RoomID.Value); @@ -96,6 +94,12 @@ namespace osu.Game.Screens.Multi rooms.Add(local); } + private void processPlaylist(Room room) + { + foreach (var pi in room.Playlist) + pi.MapObjects(beatmaps, rulesets); + } + private class CreateRoomRequest : APIRequest { private readonly Room room;