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-04-13 17:19:50 +08:00
2019-06-05 17:17:43 +08:00
using System ;
2018-04-13 17:19:50 +08:00
using System.Collections.Generic ;
using System.ComponentModel.DataAnnotations.Schema ;
using System.Linq ;
2021-05-28 13:33:05 +08:00
using JetBrains.Annotations ;
2021-10-20 17:43:48 +08:00
using Newtonsoft.Json ;
2020-09-04 19:34:26 +08:00
using osu.Framework.Testing ;
2018-04-13 17:19:50 +08:00
using osu.Game.Database ;
2021-10-20 17:43:48 +08:00
using osu.Game.Online.API.Requests.Responses ;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Beatmaps
{
2020-09-04 19:34:26 +08:00
[ExcludeFromDynamicCompile]
2021-10-27 23:13:25 +08:00
public class BeatmapSetInfo : IHasPrimaryKey , IHasFiles < BeatmapSetFileInfo > , ISoftDelete , IEquatable < BeatmapSetInfo > , IBeatmapSetInfo
2018-04-13 17:19:50 +08:00
{
public int ID { get ; set ; }
2018-06-28 09:28:35 +08:00
private int? onlineBeatmapSetID ;
public int? OnlineBeatmapSetID
{
2018-09-13 16:10:58 +08:00
get = > onlineBeatmapSetID ;
set = > onlineBeatmapSetID = value > 0 ? value : null ;
2018-06-28 09:28:35 +08:00
}
2018-09-13 17:57:33 +08:00
2019-06-05 17:17:43 +08:00
public DateTimeOffset DateAdded { get ; set ; }
2018-04-13 17:19:50 +08:00
public BeatmapMetadata Metadata { get ; set ; }
public List < BeatmapInfo > Beatmaps { get ; set ; }
2021-05-28 13:33:05 +08:00
[NotNull]
public List < BeatmapSetFileInfo > Files { get ; set ; } = new List < BeatmapSetFileInfo > ( ) ;
2021-10-28 04:50:22 +08:00
// This field is temporary and only used by `APIBeatmapSet.ToBeatmapSet` (soon to be removed) and tests (to be updated to provide APIBeatmapSet instead).
2018-04-13 17:19:50 +08:00
[NotMapped]
2021-10-20 17:43:48 +08:00
public APIBeatmapSet OnlineInfo { get ; set ; }
2018-04-13 17:19:50 +08:00
2019-07-08 14:35:12 +08:00
/// <summary>
/// The maximum star difficulty of all beatmaps in this set.
/// </summary>
2018-06-08 14:26:27 +08:00
public double MaxStarDifficulty = > Beatmaps ? . Max ( b = > b . StarDifficulty ) ? ? 0 ;
2018-04-13 17:19:50 +08:00
2019-07-08 14:35:12 +08:00
/// <summary>
2019-07-09 22:53:34 +08:00
/// The maximum playable length in milliseconds of all beatmaps in this set.
2019-07-08 14:35:12 +08:00
/// </summary>
2019-07-08 01:25:36 +08:00
public double MaxLength = > Beatmaps ? . Max ( b = > b . Length ) ? ? 0 ;
2019-07-07 23:26:56 +08:00
2019-07-08 15:43:35 +08:00
/// <summary>
/// The maximum BPM of all beatmaps in this set.
/// </summary>
public double MaxBPM = > Beatmaps ? . Max ( b = > b . BPM ) ? ? 0 ;
2018-04-13 17:19:50 +08:00
[NotMapped]
public bool DeletePending { get ; set ; }
public string Hash { get ; set ; }
2021-04-20 19:40:38 +08:00
/// <summary>
/// Returns the storage path for the file in this beatmapset with the given filename, if any exists, otherwise null.
2021-04-20 19:44:06 +08:00
/// The path returned is relative to the user file storage.
2021-04-20 19:40:38 +08:00
/// </summary>
/// <param name="filename">The name of the file to get the storage path of.</param>
2021-05-28 13:33:05 +08:00
public string GetPathForFile ( string filename ) = > Files . SingleOrDefault ( f = > string . Equals ( f . Filename , filename , StringComparison . OrdinalIgnoreCase ) ) ? . FileInfo . StoragePath ;
2018-04-13 17:19:50 +08:00
2018-06-08 14:26:27 +08:00
public override string ToString ( ) = > Metadata ? . ToString ( ) ? ? base . ToString ( ) ;
2018-04-13 17:19:50 +08:00
public bool Protected { get ; set ; }
2019-06-12 01:53:40 +08:00
2019-10-16 04:40:48 +08:00
public bool Equals ( BeatmapSetInfo other )
{
2019-10-17 06:18:29 +08:00
if ( other = = null )
return false ;
2019-10-16 04:40:48 +08:00
2019-10-17 06:18:29 +08:00
if ( ID ! = 0 & & other . ID ! = 0 )
return ID = = other . ID ;
if ( OnlineBeatmapSetID . HasValue & & other . OnlineBeatmapSetID . HasValue )
return OnlineBeatmapSetID = = other . OnlineBeatmapSetID ;
if ( ! string . IsNullOrEmpty ( Hash ) & & ! string . IsNullOrEmpty ( other . Hash ) )
return Hash = = other . Hash ;
return ReferenceEquals ( this , other ) ;
2019-10-16 04:40:48 +08:00
}
2021-10-01 15:31:11 +08:00
#region Implementation of IHasOnlineID
2021-10-18 14:35:51 +08:00
public int OnlineID = > OnlineBeatmapSetID ? ? - 1 ;
2021-10-01 15:31:11 +08:00
#endregion
#region Implementation of IBeatmapSetInfo
IBeatmapMetadataInfo IBeatmapSetInfo . Metadata = > Metadata ;
IEnumerable < IBeatmapInfo > IBeatmapSetInfo . Beatmaps = > Beatmaps ;
IEnumerable < INamedFileUsage > IBeatmapSetInfo . Files = > Files ;
#endregion
2021-10-20 17:43:48 +08:00
#region Delegation for IBeatmapSetOnlineInfo
[NotMapped]
[JsonIgnore]
2021-10-22 16:48:09 +08:00
public DateTimeOffset Submitted = > OnlineInfo . Submitted ;
2021-10-20 17:43:48 +08:00
[NotMapped]
[JsonIgnore]
2021-10-22 16:48:09 +08:00
public DateTimeOffset ? Ranked = > OnlineInfo . Ranked ;
2021-10-20 17:43:48 +08:00
[NotMapped]
[JsonIgnore]
2021-10-22 16:48:09 +08:00
public DateTimeOffset ? LastUpdated = > OnlineInfo . LastUpdated ;
2021-10-20 17:43:48 +08:00
[JsonIgnore]
public BeatmapSetOnlineStatus Status { get ; set ; } = BeatmapSetOnlineStatus . None ;
[NotMapped]
[JsonIgnore]
2021-10-22 16:48:09 +08:00
public bool HasExplicitContent = > OnlineInfo . HasExplicitContent ;
2021-10-20 17:43:48 +08:00
[NotMapped]
[JsonIgnore]
2021-10-22 16:48:09 +08:00
public bool HasVideo = > OnlineInfo . HasVideo ;
2021-10-20 17:43:48 +08:00
[NotMapped]
[JsonIgnore]
2021-10-22 16:48:09 +08:00
public bool HasStoryboard = > OnlineInfo . HasStoryboard ;
2021-10-20 17:43:48 +08:00
[NotMapped]
[JsonIgnore]
2021-10-22 16:48:09 +08:00
public BeatmapSetOnlineCovers Covers = > OnlineInfo . Covers ;
2021-10-20 17:43:48 +08:00
[NotMapped]
[JsonIgnore]
2021-10-22 16:48:09 +08:00
public string Preview = > OnlineInfo . Preview ;
2021-10-20 17:43:48 +08:00
[NotMapped]
[JsonIgnore]
2021-10-22 16:48:09 +08:00
public double BPM = > OnlineInfo . BPM ;
2021-10-20 17:43:48 +08:00
[NotMapped]
[JsonIgnore]
2021-10-22 16:48:09 +08:00
public int PlayCount = > OnlineInfo . PlayCount ;
2021-10-20 17:43:48 +08:00
[NotMapped]
[JsonIgnore]
2021-10-22 16:48:09 +08:00
public int FavouriteCount = > OnlineInfo . FavouriteCount ;
2021-10-20 17:43:48 +08:00
[NotMapped]
[JsonIgnore]
2021-10-22 16:48:09 +08:00
public bool HasFavourited = > OnlineInfo . HasFavourited ;
2021-10-20 17:43:48 +08:00
[NotMapped]
[JsonIgnore]
2021-10-22 16:48:09 +08:00
public BeatmapSetOnlineAvailability Availability = > OnlineInfo . Availability ;
2021-10-20 17:43:48 +08:00
[NotMapped]
[JsonIgnore]
2021-10-22 16:48:09 +08:00
public BeatmapSetOnlineGenre Genre = > OnlineInfo . Genre ;
2021-10-20 17:43:48 +08:00
[NotMapped]
[JsonIgnore]
2021-10-22 16:48:09 +08:00
public BeatmapSetOnlineLanguage Language = > OnlineInfo . Language ;
2021-10-20 17:43:48 +08:00
[NotMapped]
[JsonIgnore]
2021-10-22 16:48:09 +08:00
public int? TrackId = > OnlineInfo ? . TrackId ;
2021-10-20 17:43:48 +08:00
2021-10-25 13:44:49 +08:00
[NotMapped]
[JsonIgnore]
public int [ ] Ratings = > OnlineInfo ? . Ratings ;
2021-10-20 17:43:48 +08:00
#endregion
2018-04-13 17:19:50 +08:00
}
}