Fix playlist deserialisation for creating rooms

This commit is contained in:
smoogipoo 2018-12-17 11:04:38 +09:00
parent 983a45c4d8
commit 2fd2425cc4
2 changed files with 45 additions and 34 deletions

View File

@ -59,6 +59,9 @@ namespace osu.Game.Online.Multiplayer
Type.Value = other.Type; Type.Value = other.Type;
MaxParticipants.Value = other.MaxParticipants; MaxParticipants.Value = other.MaxParticipants;
Participants.Value = other.Participants.Value.ToArray(); 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; } public int ID { get; set; }
[JsonProperty("beatmap")] [JsonProperty("beatmap")]
private APIBeatmap beatmap { get; set; } private APIBeatmap apiBeatmap { get; set; }
public bool ShouldSerializebeatmap() => false; public bool ShouldSerializeapiBeatmap() => false;
private BeatmapInfo beatmap;
[JsonIgnore] [JsonIgnore]
public BeatmapInfo Beatmap { get; set; } public BeatmapInfo Beatmap
{
get => beatmap;
set
{
beatmap = value;
BeatmapID = value?.OnlineBeatmapID ?? 0;
}
}
[JsonProperty("beatmap_id")] [JsonProperty("beatmap_id")]
public int BeatmapID => Beatmap.OnlineBeatmapID ?? 0; public int BeatmapID { get; set; }
[JsonProperty("ruleset_id")] [JsonProperty("ruleset_id")]
public int RulesetID { get; set; } public int RulesetID { get; set; }
@ -105,37 +118,31 @@ namespace osu.Game.Online.Multiplayer
set => _requiredMods = value; set => _requiredMods = value;
} }
private RulesetInfo ruleset;
[JsonIgnore] [JsonIgnore]
public RulesetInfo Ruleset public RulesetInfo Ruleset { get; set; }
public void MapObjects(BeatmapManager beatmaps, RulesetStore rulesets)
{ {
get => ruleset; // 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
set // 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 = 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;
}
} }
}
public void SetRulesets(RulesetStore rulesets) if (_requiredMods != null)
{ {
Beatmap = beatmap.ToBeatmap(rulesets); RequiredMods.Clear();
RequiredMods.AddRange(Ruleset.CreateInstance().GetAllMods().Where(mod => _requiredMods.Any(m => m.Acronym == mod.Acronym)));
_requiredMods = null;
}
} }
// Todo: Move this elsewhere for reusability // Todo: Move this elsewhere for reusability

View File

@ -63,11 +63,7 @@ namespace osu.Game.Screens.Multi
{ {
foreach (var r in result) foreach (var r in result)
{ {
foreach (var pi in r.Playlist) processPlaylist(r);
{
pi.Ruleset = rulesets.GetRuleset(pi.RulesetID);
pi.SetRulesets(rulesets);
}
var existing = rooms.FirstOrDefault(e => e.RoomID.Value == r.RoomID.Value); var existing = rooms.FirstOrDefault(e => e.RoomID.Value == r.RoomID.Value);
if (existing == null) if (existing == null)
@ -88,6 +84,8 @@ namespace osu.Game.Screens.Multi
private void addRoom(Room local, Room remote) private void addRoom(Room local, Room remote)
{ {
processPlaylist(remote);
local.CopyFrom(remote); local.CopyFrom(remote);
var existing = rooms.FirstOrDefault(e => e.RoomID.Value == local.RoomID.Value); var existing = rooms.FirstOrDefault(e => e.RoomID.Value == local.RoomID.Value);
@ -96,6 +94,12 @@ namespace osu.Game.Screens.Multi
rooms.Add(local); rooms.Add(local);
} }
private void processPlaylist(Room room)
{
foreach (var pi in room.Playlist)
pi.MapObjects(beatmaps, rulesets);
}
private class CreateRoomRequest : APIRequest<Room> private class CreateRoomRequest : APIRequest<Room>
{ {
private readonly Room room; private readonly Room room;