1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 15:53:21 +08:00
osu-lazer/osu.Game/Beatmaps/EFBeatmapSetInfo.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

109 lines
3.6 KiB
C#
Raw Normal View History

// 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
2022-06-17 15:37:17 +08:00
#nullable disable
using System;
2017-02-07 12:52:19 +08:00
using System.Collections.Generic;
2017-10-05 03:52:12 +08:00
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using JetBrains.Annotations;
using Newtonsoft.Json;
using osu.Framework.Testing;
2017-10-25 21:07:32 +08:00
using osu.Game.Database;
using osu.Game.Extensions;
2018-04-13 17:19:50 +08:00
2017-07-26 12:22:46 +08:00
namespace osu.Game.Beatmaps
2017-02-07 12:52:19 +08:00
{
[ExcludeFromDynamicCompile]
[Serializable]
[Table(@"BeatmapSetInfo")]
public class EFBeatmapSetInfo : IHasPrimaryKey, IHasFiles<BeatmapSetFileInfo>, ISoftDelete, IEquatable<EFBeatmapSetInfo>, IBeatmapSetInfo
2017-02-07 12:52:19 +08:00
{
2017-10-14 13:28:25 +08:00
public int ID { get; set; }
2018-04-13 17:19:50 +08:00
public bool IsManaged => ID > 0;
private int? onlineID;
[Column("OnlineBeatmapSetID")]
public int? OnlineID
{
get => onlineID;
set => onlineID = value > 0 ? value : null;
}
public DateTimeOffset DateAdded { get; set; }
public EFBeatmapMetadata Metadata { get; set; }
2018-04-13 17:19:50 +08:00
[NotNull]
public List<EFBeatmapInfo> Beatmaps { get; } = new List<EFBeatmapInfo>();
2018-04-13 17:19:50 +08:00
public BeatmapOnlineStatus Status { get; set; } = BeatmapOnlineStatus.None;
public List<BeatmapSetFileInfo> Files { get; } = new List<BeatmapSetFileInfo>();
/// <summary>
/// The maximum star difficulty of all beatmaps in this set.
/// </summary>
[JsonIgnore]
public double MaxStarDifficulty => Beatmaps.Count == 0 ? 0 : Beatmaps.Max(b => b.StarRating);
2018-04-13 17:19:50 +08:00
/// <summary>
/// The maximum playable length in milliseconds of all beatmaps in this set.
/// </summary>
[JsonIgnore]
public double MaxLength => Beatmaps.Count == 0 ? 0 : Beatmaps.Max(b => b.Length);
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>
[JsonIgnore]
public double MaxBPM => Beatmaps.Count == 0 ? 0 : Beatmaps.Max(b => b.BPM);
2019-07-08 15:43:35 +08:00
2017-10-06 05:23:26 +08:00
[NotMapped]
2017-02-24 16:08:13 +08:00
public bool DeletePending { get; set; }
2018-04-13 17:19:50 +08:00
2017-02-07 12:52:19 +08:00
public string Hash { get; set; }
2018-04-13 17:19:50 +08:00
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.
/// 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>
public string GetPathForFile(string filename) => Files.SingleOrDefault(f => string.Equals(f.Filename, filename, StringComparison.OrdinalIgnoreCase))?.FileInfo.GetStoragePath();
2018-04-13 17:19:50 +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
public bool Equals(EFBeatmapSetInfo other)
2021-11-12 17:14:11 +08:00
{
2021-11-12 17:48:34 +08:00
if (ReferenceEquals(this, other)) return true;
if (other == null) return false;
2021-11-12 17:14:11 +08:00
2021-11-12 17:48:34 +08:00
if (ID != 0 && other.ID != 0)
return ID == other.ID;
2021-11-12 17:14:11 +08:00
return false;
}
public bool Equals(IBeatmapSetInfo other) => other is EFBeatmapSetInfo b && Equals(b);
#region Implementation of IHasOnlineID
int IHasOnlineID<int>.OnlineID => OnlineID ?? -1;
#endregion
#region Implementation of IBeatmapSetInfo
IBeatmapMetadataInfo IBeatmapSetInfo.Metadata => Metadata ?? Beatmaps.FirstOrDefault()?.Metadata ?? new EFBeatmapMetadata();
IEnumerable<IBeatmapInfo> IBeatmapSetInfo.Beatmaps => Beatmaps;
IEnumerable<INamedFileUsage> IHasNamedFiles.Files => Files;
#endregion
2017-02-07 12:52:19 +08:00
}
}