2019-01-24 08:43:03 +00: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 05:45:06 +00:00
|
|
|
|
2020-02-13 09:48:28 +00:00
|
|
|
using System;
|
2018-12-17 05:45:06 +00:00
|
|
|
using System.Linq;
|
|
|
|
using Newtonsoft.Json;
|
2020-02-13 09:12:47 +00:00
|
|
|
using osu.Framework.Bindables;
|
2018-12-17 05:45:06 +00:00
|
|
|
using osu.Game.Beatmaps;
|
2020-01-17 04:27:47 +00:00
|
|
|
using osu.Game.Online.API;
|
2018-12-17 05:45:06 +00:00
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
|
|
|
|
namespace osu.Game.Online.Multiplayer
|
|
|
|
{
|
2020-02-13 09:48:28 +00:00
|
|
|
public class PlaylistItem : IEquatable<PlaylistItem>
|
2018-12-17 05:45:06 +00:00
|
|
|
{
|
|
|
|
[JsonProperty("id")]
|
|
|
|
public int ID { get; set; }
|
|
|
|
|
|
|
|
[JsonProperty("beatmap_id")]
|
|
|
|
public int BeatmapID { get; set; }
|
|
|
|
|
|
|
|
[JsonProperty("ruleset_id")]
|
|
|
|
public int RulesetID { get; set; }
|
|
|
|
|
|
|
|
[JsonIgnore]
|
2020-02-13 09:12:47 +00:00
|
|
|
public readonly Bindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
|
2018-12-17 05:45:06 +00:00
|
|
|
|
|
|
|
[JsonIgnore]
|
2020-02-13 09:12:47 +00:00
|
|
|
public readonly Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
|
2018-12-17 05:45:06 +00:00
|
|
|
|
|
|
|
[JsonIgnore]
|
2020-02-13 09:12:47 +00:00
|
|
|
public readonly BindableList<Mod> AllowedMods = new BindableList<Mod>();
|
2018-12-17 05:45:06 +00:00
|
|
|
|
|
|
|
[JsonIgnore]
|
2020-02-13 09:12:47 +00:00
|
|
|
public readonly BindableList<Mod> RequiredMods = new BindableList<Mod>();
|
2018-12-17 05:45:06 +00:00
|
|
|
|
|
|
|
[JsonProperty("beatmap")]
|
2020-06-02 05:03:13 +00:00
|
|
|
private APIPlaylistBeatmap apiBeatmap { get; set; }
|
2018-12-17 05:45:06 +00:00
|
|
|
|
2019-12-11 05:10:35 +00:00
|
|
|
private APIMod[] allowedModsBacking;
|
|
|
|
|
2018-12-17 05:45:06 +00:00
|
|
|
[JsonProperty("allowed_mods")]
|
|
|
|
private APIMod[] allowedMods
|
|
|
|
{
|
2020-01-17 04:27:47 +00:00
|
|
|
get => AllowedMods.Select(m => new APIMod(m)).ToArray();
|
2019-12-11 05:10:35 +00:00
|
|
|
set => allowedModsBacking = value;
|
2018-12-17 05:45:06 +00:00
|
|
|
}
|
|
|
|
|
2019-12-11 05:10:35 +00:00
|
|
|
private APIMod[] requiredModsBacking;
|
|
|
|
|
2018-12-17 05:45:06 +00:00
|
|
|
[JsonProperty("required_mods")]
|
|
|
|
private APIMod[] requiredMods
|
|
|
|
{
|
2020-01-17 04:27:47 +00:00
|
|
|
get => RequiredMods.Select(m => new APIMod(m)).ToArray();
|
2019-12-11 05:10:35 +00:00
|
|
|
set => requiredModsBacking = value;
|
2018-12-17 05:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-13 09:12:47 +00:00
|
|
|
public PlaylistItem()
|
|
|
|
{
|
|
|
|
Beatmap.BindValueChanged(beatmap => BeatmapID = beatmap.NewValue?.OnlineBeatmapID ?? 0);
|
|
|
|
Ruleset.BindValueChanged(ruleset => RulesetID = ruleset.NewValue?.ID ?? 0);
|
|
|
|
}
|
2018-12-17 05:45:06 +00:00
|
|
|
|
|
|
|
public void MapObjects(BeatmapManager beatmaps, RulesetStore rulesets)
|
|
|
|
{
|
2020-02-27 07:40:56 +00:00
|
|
|
Beatmap.Value = apiBeatmap.ToBeatmap(rulesets);
|
2020-02-13 09:12:47 +00:00
|
|
|
Ruleset.Value = rulesets.GetRuleset(RulesetID);
|
2018-12-17 05:45:06 +00:00
|
|
|
|
2020-02-13 09:12:47 +00:00
|
|
|
Ruleset rulesetInstance = Ruleset.Value.CreateInstance();
|
2020-01-17 04:27:47 +00:00
|
|
|
|
2019-12-11 05:10:35 +00:00
|
|
|
if (allowedModsBacking != null)
|
2018-12-17 05:45:06 +00:00
|
|
|
{
|
|
|
|
AllowedMods.Clear();
|
2020-01-17 04:27:47 +00:00
|
|
|
AllowedMods.AddRange(allowedModsBacking.Select(m => m.ToMod(rulesetInstance)));
|
2018-12-17 05:45:06 +00:00
|
|
|
|
2019-12-11 05:10:35 +00:00
|
|
|
allowedModsBacking = null;
|
2018-12-17 05:45:06 +00:00
|
|
|
}
|
|
|
|
|
2019-12-11 05:10:35 +00:00
|
|
|
if (requiredModsBacking != null)
|
2018-12-17 05:45:06 +00:00
|
|
|
{
|
|
|
|
RequiredMods.Clear();
|
2020-01-17 04:27:47 +00:00
|
|
|
RequiredMods.AddRange(requiredModsBacking.Select(m => m.ToMod(rulesetInstance)));
|
2018-12-17 05:45:06 +00:00
|
|
|
|
2019-12-11 05:10:35 +00:00
|
|
|
requiredModsBacking = null;
|
2018-12-17 05:45:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool ShouldSerializeID() => false;
|
|
|
|
public bool ShouldSerializeapiBeatmap() => false;
|
2020-02-13 09:48:28 +00:00
|
|
|
|
|
|
|
public bool Equals(PlaylistItem other) => ID == other?.ID && BeatmapID == other.BeatmapID && RulesetID == other.RulesetID;
|
2018-12-17 05:45:06 +00:00
|
|
|
}
|
|
|
|
}
|