1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-19 06:02:56 +08:00
osu-lazer/osu.Game/Beatmaps/BeatmapSetInfo.cs

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

106 lines
3.3 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.
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Newtonsoft.Json;
using osu.Framework.Testing;
using osu.Game.Database;
2021-11-15 13:35:01 +08:00
using osu.Game.Extensions;
using osu.Game.Models;
using Realms;
namespace osu.Game.Beatmaps
{
/// <summary>
2022-07-28 15:02:19 +08:00
/// A realm model containing metadata for a beatmap set (containing multiple <see cref="BeatmapInfo"/>s).
/// </summary>
[ExcludeFromDynamicCompile]
[MapTo("BeatmapSet")]
public class BeatmapSetInfo : RealmObject, IHasGuidPrimaryKey, IHasRealmFiles, ISoftDelete, IEquatable<BeatmapSetInfo>, IBeatmapSetInfo
{
[PrimaryKey]
public Guid ID { get; set; }
[Indexed]
public int OnlineID { get; set; } = -1;
public DateTimeOffset DateAdded { get; set; }
/// <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; }
[JsonIgnore]
public IBeatmapMetadataInfo Metadata => Beatmaps.FirstOrDefault()?.Metadata ?? new BeatmapMetadata();
public IList<BeatmapInfo> Beatmaps { get; } = null!;
public IList<RealmNamedFileUsage> Files { get; } = null!;
[Ignored]
2021-11-24 17:45:34 +08:00
public BeatmapOnlineStatus Status
{
get => (BeatmapOnlineStatus)StatusInt;
set => StatusInt = (int)value;
}
[MapTo(nameof(Status))]
public int StatusInt { get; set; } = (int)BeatmapOnlineStatus.None;
2021-11-24 17:45:34 +08: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; }
public double MaxStarDifficulty => Beatmaps.Count == 0 ? 0 : Beatmaps.Max(b => b.StarRating);
public double MaxLength => Beatmaps.Count == 0 ? 0 : Beatmaps.Max(b => b.Length);
public double MaxBPM => Beatmaps.Count == 0 ? 0 : Beatmaps.Max(b => b.BPM);
public BeatmapSetInfo(IEnumerable<BeatmapInfo>? beatmaps = null)
: this()
{
ID = Guid.NewGuid();
if (beatmaps != null)
Beatmaps.AddRange(beatmaps);
}
[UsedImplicitly] // Realm
private BeatmapSetInfo()
{
}
public bool Equals(BeatmapSetInfo? 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
return ID == other.ID;
2021-11-12 17:14:11 +08:00
}
2021-11-24 14:01:45 +08:00
public override string ToString() => Metadata.GetDisplayString();
2021-11-12 17:14:11 +08:00
public bool Equals(IBeatmapSetInfo? other) => other is BeatmapSetInfo b && Equals(b);
IEnumerable<IBeatmapInfo> IBeatmapSetInfo.Beatmaps => Beatmaps;
2022-01-07 13:17:22 +08:00
IEnumerable<INamedFileUsage> IHasNamedFiles.Files => Files;
2022-07-18 17:06:11 +08:00
public bool AllBeatmapsUpToDate => Beatmaps.All(b => b.MatchesOnlineVersion);
}
}