2019-01-24 16:43:03 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-12-17 13:45:06 +08:00
|
|
|
|
2020-02-13 17:48:28 +08:00
|
|
|
using System;
|
2021-12-03 17:14:44 +08:00
|
|
|
using System.Diagnostics;
|
2018-12-17 13:45:06 +08:00
|
|
|
using System.Linq;
|
|
|
|
using Newtonsoft.Json;
|
2020-02-13 17:12:47 +08:00
|
|
|
using osu.Framework.Bindables;
|
2018-12-17 13:45:06 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2020-01-17 12:27:47 +08:00
|
|
|
using osu.Game.Online.API;
|
2021-10-21 15:43:46 +08:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2018-12-17 13:45:06 +08:00
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
|
2020-12-25 12:38:11 +08:00
|
|
|
namespace osu.Game.Online.Rooms
|
2018-12-17 13:45:06 +08:00
|
|
|
{
|
2020-02-13 17:48:28 +08:00
|
|
|
public class PlaylistItem : IEquatable<PlaylistItem>
|
2018-12-17 13:45:06 +08:00
|
|
|
{
|
|
|
|
[JsonProperty("id")]
|
2021-02-16 18:29:40 +08:00
|
|
|
public long ID { get; set; }
|
2018-12-17 13:45:06 +08:00
|
|
|
|
2021-11-25 20:41:03 +08:00
|
|
|
[JsonProperty("owner_id")]
|
|
|
|
public int OwnerID { get; set; }
|
|
|
|
|
2018-12-17 13:45:06 +08:00
|
|
|
[JsonProperty("beatmap_id")]
|
|
|
|
public int BeatmapID { get; set; }
|
|
|
|
|
|
|
|
[JsonProperty("ruleset_id")]
|
|
|
|
public int RulesetID { get; set; }
|
|
|
|
|
2021-02-17 15:44:39 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Whether this <see cref="PlaylistItem"/> is still a valid selection for the <see cref="Room"/>.
|
|
|
|
/// </summary>
|
|
|
|
[JsonProperty("expired")]
|
|
|
|
public bool Expired { get; set; }
|
|
|
|
|
2021-12-03 14:45:13 +08:00
|
|
|
[JsonProperty("playlist_order")]
|
|
|
|
public ushort? PlaylistOrder { get; set; }
|
2021-12-02 18:15:27 +08:00
|
|
|
|
2021-12-03 19:05:25 +08:00
|
|
|
[JsonProperty("played_at")]
|
|
|
|
public DateTimeOffset? PlayedAt { get; set; }
|
|
|
|
|
2021-11-16 16:01:24 +08:00
|
|
|
[JsonIgnore]
|
|
|
|
public IBindable<bool> Valid => valid;
|
|
|
|
|
|
|
|
private readonly Bindable<bool> valid = new BindableBool(true);
|
|
|
|
|
2018-12-17 13:45:06 +08:00
|
|
|
[JsonIgnore]
|
2021-11-04 11:30:19 +08:00
|
|
|
public readonly Bindable<IBeatmapInfo> Beatmap = new Bindable<IBeatmapInfo>();
|
2018-12-17 13:45:06 +08:00
|
|
|
|
|
|
|
[JsonIgnore]
|
2021-11-15 15:13:03 +08:00
|
|
|
public readonly Bindable<IRulesetInfo> Ruleset = new Bindable<IRulesetInfo>();
|
2018-12-17 13:45:06 +08:00
|
|
|
|
|
|
|
[JsonIgnore]
|
2020-02-13 17:12:47 +08:00
|
|
|
public readonly BindableList<Mod> AllowedMods = new BindableList<Mod>();
|
2018-12-17 13:45:06 +08:00
|
|
|
|
|
|
|
[JsonIgnore]
|
2020-02-13 17:12:47 +08:00
|
|
|
public readonly BindableList<Mod> RequiredMods = new BindableList<Mod>();
|
2018-12-17 13:45:06 +08:00
|
|
|
|
|
|
|
[JsonProperty("beatmap")]
|
2021-10-21 15:43:46 +08:00
|
|
|
private APIBeatmap apiBeatmap { get; set; }
|
2018-12-17 13:45:06 +08:00
|
|
|
|
2019-12-11 13:10:35 +08:00
|
|
|
private APIMod[] allowedModsBacking;
|
|
|
|
|
2018-12-17 13:45:06 +08:00
|
|
|
[JsonProperty("allowed_mods")]
|
|
|
|
private APIMod[] allowedMods
|
|
|
|
{
|
2020-01-17 12:27:47 +08:00
|
|
|
get => AllowedMods.Select(m => new APIMod(m)).ToArray();
|
2019-12-11 13:10:35 +08:00
|
|
|
set => allowedModsBacking = value;
|
2018-12-17 13:45:06 +08:00
|
|
|
}
|
|
|
|
|
2019-12-11 13:10:35 +08:00
|
|
|
private APIMod[] requiredModsBacking;
|
|
|
|
|
2018-12-17 13:45:06 +08:00
|
|
|
[JsonProperty("required_mods")]
|
|
|
|
private APIMod[] requiredMods
|
|
|
|
{
|
2020-01-17 12:27:47 +08:00
|
|
|
get => RequiredMods.Select(m => new APIMod(m)).ToArray();
|
2019-12-11 13:10:35 +08:00
|
|
|
set => requiredModsBacking = value;
|
2018-12-17 13:45:06 +08:00
|
|
|
}
|
|
|
|
|
2020-02-13 17:12:47 +08:00
|
|
|
public PlaylistItem()
|
|
|
|
{
|
2021-11-04 11:30:19 +08:00
|
|
|
Beatmap.BindValueChanged(beatmap => BeatmapID = beatmap.NewValue?.OnlineID ?? -1);
|
2021-11-15 15:13:03 +08:00
|
|
|
Ruleset.BindValueChanged(ruleset => RulesetID = ruleset.NewValue?.OnlineID ?? 0);
|
2020-02-13 17:12:47 +08:00
|
|
|
}
|
2018-12-17 13:45:06 +08:00
|
|
|
|
2021-11-16 16:01:24 +08:00
|
|
|
public void MarkInvalid() => valid.Value = false;
|
|
|
|
|
2021-12-03 17:14:44 +08:00
|
|
|
public void MapObjects(IRulesetStore rulesets)
|
2018-12-17 13:45:06 +08:00
|
|
|
{
|
2021-11-04 12:36:32 +08:00
|
|
|
Beatmap.Value ??= apiBeatmap;
|
2020-12-20 23:02:49 +08:00
|
|
|
Ruleset.Value ??= rulesets.GetRuleset(RulesetID);
|
2018-12-17 13:45:06 +08:00
|
|
|
|
2021-12-03 17:14:44 +08:00
|
|
|
Debug.Assert(Ruleset.Value != null);
|
|
|
|
|
2020-02-13 17:12:47 +08:00
|
|
|
Ruleset rulesetInstance = Ruleset.Value.CreateInstance();
|
2020-01-17 12:27:47 +08:00
|
|
|
|
2019-12-11 13:10:35 +08:00
|
|
|
if (allowedModsBacking != null)
|
2018-12-17 13:45:06 +08:00
|
|
|
{
|
|
|
|
AllowedMods.Clear();
|
2020-01-17 12:27:47 +08:00
|
|
|
AllowedMods.AddRange(allowedModsBacking.Select(m => m.ToMod(rulesetInstance)));
|
2018-12-17 13:45:06 +08:00
|
|
|
|
2019-12-11 13:10:35 +08:00
|
|
|
allowedModsBacking = null;
|
2018-12-17 13:45:06 +08:00
|
|
|
}
|
|
|
|
|
2019-12-11 13:10:35 +08:00
|
|
|
if (requiredModsBacking != null)
|
2018-12-17 13:45:06 +08:00
|
|
|
{
|
|
|
|
RequiredMods.Clear();
|
2020-01-17 12:27:47 +08:00
|
|
|
RequiredMods.AddRange(requiredModsBacking.Select(m => m.ToMod(rulesetInstance)));
|
2018-12-17 13:45:06 +08:00
|
|
|
|
2019-12-11 13:10:35 +08:00
|
|
|
requiredModsBacking = null;
|
2018-12-17 13:45:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool ShouldSerializeID() => false;
|
|
|
|
public bool ShouldSerializeapiBeatmap() => false;
|
2020-02-13 17:48:28 +08:00
|
|
|
|
2021-10-29 15:23:10 +08:00
|
|
|
public bool Equals(PlaylistItem other)
|
|
|
|
=> ID == other?.ID
|
|
|
|
&& BeatmapID == other.BeatmapID
|
|
|
|
&& RulesetID == other.RulesetID
|
|
|
|
&& Expired == other.Expired
|
|
|
|
&& allowedMods.SequenceEqual(other.allowedMods)
|
|
|
|
&& requiredMods.SequenceEqual(other.requiredMods);
|
2018-12-17 13:45:06 +08:00
|
|
|
}
|
|
|
|
}
|