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-04-13 09:19:50 +00:00
|
|
|
|
|
2019-06-05 09:17:43 +00:00
|
|
|
|
using System;
|
2017-02-07 04:52:19 +00:00
|
|
|
|
using System.Collections.Generic;
|
2017-10-04 19:52:12 +00:00
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
2017-03-16 04:59:23 +00:00
|
|
|
|
using System.Linq;
|
2021-05-28 05:33:05 +00:00
|
|
|
|
using JetBrains.Annotations;
|
2021-11-24 04:34:52 +00:00
|
|
|
|
using Newtonsoft.Json;
|
2020-09-04 11:34:26 +00:00
|
|
|
|
using osu.Framework.Testing;
|
2017-10-25 13:07:32 +00:00
|
|
|
|
using osu.Game.Database;
|
2021-11-19 07:07:55 +00:00
|
|
|
|
using osu.Game.Extensions;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-07-26 04:22:46 +00:00
|
|
|
|
namespace osu.Game.Beatmaps
|
2017-02-07 04:52:19 +00:00
|
|
|
|
{
|
2020-09-04 11:34:26 +00:00
|
|
|
|
[ExcludeFromDynamicCompile]
|
2021-12-14 15:31:35 +00:00
|
|
|
|
[Serializable]
|
|
|
|
|
[Table(@"BeatmapSetInfo")]
|
2021-11-19 09:59:14 +00:00
|
|
|
|
public class EFBeatmapSetInfo : IHasPrimaryKey, IHasFiles<BeatmapSetFileInfo>, ISoftDelete, IEquatable<EFBeatmapSetInfo>, IBeatmapSetInfo
|
2017-02-07 04:52:19 +00:00
|
|
|
|
{
|
2017-10-14 05:28:25 +00:00
|
|
|
|
public int ID { get; set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-11-19 12:53:40 +00:00
|
|
|
|
public bool IsManaged => ID > 0;
|
|
|
|
|
|
2021-11-12 08:50:31 +00:00
|
|
|
|
private int? onlineID;
|
2018-06-28 01:28:35 +00:00
|
|
|
|
|
2021-11-12 08:50:31 +00:00
|
|
|
|
[Column("OnlineBeatmapSetID")]
|
|
|
|
|
public int? OnlineID
|
2018-06-28 01:28:35 +00:00
|
|
|
|
{
|
2021-11-12 08:50:31 +00:00
|
|
|
|
get => onlineID;
|
|
|
|
|
set => onlineID = value > 0 ? value : null;
|
2018-06-28 01:28:35 +00:00
|
|
|
|
}
|
2018-09-13 09:57:33 +00:00
|
|
|
|
|
2019-06-05 09:17:43 +00:00
|
|
|
|
public DateTimeOffset DateAdded { get; set; }
|
|
|
|
|
|
2021-11-19 09:59:14 +00:00
|
|
|
|
public EFBeatmapMetadata Metadata { get; set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-11-24 04:34:52 +00:00
|
|
|
|
[NotNull]
|
2021-12-14 10:47:11 +00:00
|
|
|
|
public List<EFBeatmapInfo> Beatmaps { get; } = new List<EFBeatmapInfo>();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-11-24 09:42:47 +00:00
|
|
|
|
public BeatmapOnlineStatus Status { get; set; } = BeatmapOnlineStatus.None;
|
2021-11-01 06:42:12 +00:00
|
|
|
|
|
2021-11-24 04:42:07 +00:00
|
|
|
|
public List<BeatmapSetFileInfo> Files { get; } = new List<BeatmapSetFileInfo>();
|
2021-05-28 05:33:05 +00:00
|
|
|
|
|
2019-07-08 06:35:12 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The maximum star difficulty of all beatmaps in this set.
|
|
|
|
|
/// </summary>
|
2021-11-24 04:34:52 +00:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public double MaxStarDifficulty => Beatmaps.Count == 0 ? 0 : Beatmaps.Max(b => b.StarRating);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-07-08 06:35:12 +00:00
|
|
|
|
/// <summary>
|
2019-07-09 14:53:34 +00:00
|
|
|
|
/// The maximum playable length in milliseconds of all beatmaps in this set.
|
2019-07-08 06:35:12 +00:00
|
|
|
|
/// </summary>
|
2021-11-24 04:34:52 +00:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public double MaxLength => Beatmaps.Count == 0 ? 0 : Beatmaps.Max(b => b.Length);
|
2019-07-07 15:26:56 +00:00
|
|
|
|
|
2019-07-08 07:43:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The maximum BPM of all beatmaps in this set.
|
|
|
|
|
/// </summary>
|
2021-11-24 04:34:52 +00:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public double MaxBPM => Beatmaps.Count == 0 ? 0 : Beatmaps.Max(b => b.BPM);
|
2019-07-08 07:43:35 +00:00
|
|
|
|
|
2017-10-05 21:23:26 +00:00
|
|
|
|
[NotMapped]
|
2017-02-24 08:08:13 +00:00
|
|
|
|
public bool DeletePending { get; set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-02-07 04:52:19 +00:00
|
|
|
|
public string Hash { get; set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-04-20 11:40:38 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the storage path for the file in this beatmapset with the given filename, if any exists, otherwise null.
|
2021-04-20 11:44:06 +00:00
|
|
|
|
/// The path returned is relative to the user file storage.
|
2021-04-20 11:40:38 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="filename">The name of the file to get the storage path of.</param>
|
2021-11-19 07:07:55 +00:00
|
|
|
|
public string GetPathForFile(string filename) => Files.SingleOrDefault(f => string.Equals(f.Filename, filename, StringComparison.OrdinalIgnoreCase))?.FileInfo.GetStoragePath();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-06-08 06:26:27 +00:00
|
|
|
|
public override string ToString() => Metadata?.ToString() ?? base.ToString();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-07-26 11:22:02 +00:00
|
|
|
|
public bool Protected { get; set; }
|
2019-06-11 17:53:40 +00:00
|
|
|
|
|
2021-11-19 09:59:14 +00:00
|
|
|
|
public bool Equals(EFBeatmapSetInfo 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
|
|
|
|
if (ID != 0 && other.ID != 0)
|
|
|
|
|
return ID == other.ID;
|
2021-11-12 09:14:11 +00:00
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 09:59:14 +00:00
|
|
|
|
public bool Equals(IBeatmapSetInfo other) => other is EFBeatmapSetInfo b && Equals(b);
|
2021-11-16 03:25:37 +00:00
|
|
|
|
|
2021-10-01 07:31:11 +00:00
|
|
|
|
#region Implementation of IHasOnlineID
|
|
|
|
|
|
2021-11-12 08:50:31 +00:00
|
|
|
|
int IHasOnlineID<int>.OnlineID => OnlineID ?? -1;
|
2021-10-01 07:31:11 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Implementation of IBeatmapSetInfo
|
|
|
|
|
|
2021-12-14 10:47:11 +00:00
|
|
|
|
IBeatmapMetadataInfo IBeatmapSetInfo.Metadata => Metadata ?? Beatmaps.FirstOrDefault()?.Metadata ?? new EFBeatmapMetadata();
|
2021-10-01 07:31:11 +00:00
|
|
|
|
IEnumerable<IBeatmapInfo> IBeatmapSetInfo.Beatmaps => Beatmaps;
|
2021-11-25 07:35:42 +00:00
|
|
|
|
IEnumerable<INamedFileUsage> IHasNamedFiles.Files => Files;
|
2021-10-01 07:31:11 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
2017-02-07 04:52:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|