mirror of
https://github.com/ppy/osu.git
synced 2025-03-21 21:47:20 +08:00
Fix playlist deserialisation for creating rooms
This commit is contained in:
parent
983a45c4d8
commit
2fd2425cc4
@ -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
|
||||
|
@ -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<Room>
|
||||
{
|
||||
private readonly Room room;
|
||||
|
Loading…
x
Reference in New Issue
Block a user