2021-10-11 06:25:00 +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.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2022-01-20 07:49:39 +00:00
|
|
|
|
using JetBrains.Annotations;
|
2022-01-20 08:09:31 +00:00
|
|
|
|
using Newtonsoft.Json;
|
2021-10-11 06:25:00 +00:00
|
|
|
|
using osu.Game.Database;
|
2021-11-15 05:35:01 +00:00
|
|
|
|
using osu.Game.Extensions;
|
2021-11-19 10:07:21 +00:00
|
|
|
|
using osu.Game.Models;
|
2021-10-11 06:25:00 +00:00
|
|
|
|
using Realms;
|
|
|
|
|
|
2021-11-19 10:07:21 +00:00
|
|
|
|
namespace osu.Game.Beatmaps
|
2021-10-11 06:25:00 +00:00
|
|
|
|
{
|
2022-07-28 06:41:28 +00:00
|
|
|
|
/// <summary>
|
2022-07-28 07:02:19 +00:00
|
|
|
|
/// A realm model containing metadata for a beatmap set (containing multiple <see cref="BeatmapInfo"/>s).
|
2022-07-28 06:41:28 +00:00
|
|
|
|
/// </summary>
|
2021-10-11 06:25:00 +00:00
|
|
|
|
[MapTo("BeatmapSet")]
|
2021-11-19 10:07:21 +00:00
|
|
|
|
public class BeatmapSetInfo : RealmObject, IHasGuidPrimaryKey, IHasRealmFiles, ISoftDelete, IEquatable<BeatmapSetInfo>, IBeatmapSetInfo
|
2021-10-11 06:25:00 +00:00
|
|
|
|
{
|
|
|
|
|
[PrimaryKey]
|
2022-01-20 07:49:39 +00:00
|
|
|
|
public Guid ID { get; set; }
|
2021-10-11 06:25:00 +00:00
|
|
|
|
|
2021-10-18 06:35:51 +00:00
|
|
|
|
[Indexed]
|
|
|
|
|
public int OnlineID { get; set; } = -1;
|
2021-10-11 06:25:00 +00:00
|
|
|
|
|
|
|
|
|
public DateTimeOffset DateAdded { get; set; }
|
|
|
|
|
|
2022-07-19 10:37:04 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The date this beatmap set was first submitted.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public DateTimeOffset? DateSubmitted { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The date this beatmap set was ranked.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public DateTimeOffset? DateRanked { get; set; }
|
|
|
|
|
|
2022-01-20 08:09:31 +00:00
|
|
|
|
[JsonIgnore]
|
2021-11-19 10:07:21 +00:00
|
|
|
|
public IBeatmapMetadataInfo Metadata => Beatmaps.FirstOrDefault()?.Metadata ?? new BeatmapMetadata();
|
2021-10-11 06:25:00 +00:00
|
|
|
|
|
2021-11-19 10:07:21 +00:00
|
|
|
|
public IList<BeatmapInfo> Beatmaps { get; } = null!;
|
2021-10-11 06:25:00 +00:00
|
|
|
|
|
|
|
|
|
public IList<RealmNamedFileUsage> Files { get; } = null!;
|
|
|
|
|
|
2022-01-18 14:25:30 +00:00
|
|
|
|
[Ignored]
|
2021-11-24 09:45:34 +00:00
|
|
|
|
public BeatmapOnlineStatus Status
|
|
|
|
|
{
|
|
|
|
|
get => (BeatmapOnlineStatus)StatusInt;
|
|
|
|
|
set => StatusInt = (int)value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[MapTo(nameof(Status))]
|
2021-11-24 09:48:12 +00:00
|
|
|
|
public int StatusInt { get; set; } = (int)BeatmapOnlineStatus.None;
|
2021-11-24 09:45:34 +00:00
|
|
|
|
|
2021-10-11 06:25:00 +00:00
|
|
|
|
public bool DeletePending { get; set; }
|
|
|
|
|
|
|
|
|
|
public string Hash { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether deleting this beatmap set should be prohibited (due to it being a system requirement to be present).
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool Protected { get; set; }
|
|
|
|
|
|
2021-12-21 07:37:29 +00:00
|
|
|
|
public double MaxStarDifficulty => Beatmaps.Count == 0 ? 0 : Beatmaps.Max(b => b.StarRating);
|
2021-10-11 06:25:00 +00:00
|
|
|
|
|
2021-12-21 07:37:29 +00:00
|
|
|
|
public double MaxLength => Beatmaps.Count == 0 ? 0 : Beatmaps.Max(b => b.Length);
|
2021-10-11 06:25:00 +00:00
|
|
|
|
|
2021-12-21 07:37:29 +00:00
|
|
|
|
public double MaxBPM => Beatmaps.Count == 0 ? 0 : Beatmaps.Max(b => b.BPM);
|
2021-10-11 06:25:00 +00:00
|
|
|
|
|
2022-01-20 07:49:39 +00:00
|
|
|
|
public BeatmapSetInfo(IEnumerable<BeatmapInfo>? beatmaps = null)
|
|
|
|
|
: this()
|
|
|
|
|
{
|
|
|
|
|
ID = Guid.NewGuid();
|
|
|
|
|
if (beatmaps != null)
|
|
|
|
|
Beatmaps.AddRange(beatmaps);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[UsedImplicitly] // Realm
|
|
|
|
|
private BeatmapSetInfo()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 10:07:21 +00:00
|
|
|
|
public bool Equals(BeatmapSetInfo? other)
|
2021-11-12 09:14:11 +00:00
|
|
|
|
{
|
2021-11-12 09:48:34 +00:00
|
|
|
|
if (ReferenceEquals(this, other)) return true;
|
|
|
|
|
if (other == null) return false;
|
2021-11-12 09:14:11 +00:00
|
|
|
|
|
2021-11-12 09:48:34 +00:00
|
|
|
|
return ID == other.ID;
|
2021-11-12 09:14:11 +00:00
|
|
|
|
}
|
2021-10-11 06:25:00 +00:00
|
|
|
|
|
2021-11-24 06:01:45 +00:00
|
|
|
|
public override string ToString() => Metadata.GetDisplayString();
|
2021-11-12 09:14:11 +00:00
|
|
|
|
|
2021-11-19 10:07:21 +00:00
|
|
|
|
public bool Equals(IBeatmapSetInfo? other) => other is BeatmapSetInfo b && Equals(b);
|
2021-11-16 03:25:37 +00:00
|
|
|
|
|
2021-10-11 06:25:00 +00:00
|
|
|
|
IEnumerable<IBeatmapInfo> IBeatmapSetInfo.Beatmaps => Beatmaps;
|
2022-01-07 05:17:22 +00:00
|
|
|
|
|
2021-11-25 07:35:42 +00:00
|
|
|
|
IEnumerable<INamedFileUsage> IHasNamedFiles.Files => Files;
|
2022-07-18 09:06:11 +00:00
|
|
|
|
|
|
|
|
|
public bool AllBeatmapsUpToDate => Beatmaps.All(b => b.MatchesOnlineVersion);
|
2021-10-11 06:25:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|