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;
|
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Database;
|
2021-11-15 05:35:01 +00:00
|
|
|
|
using osu.Game.Extensions;
|
2021-10-11 06:25:00 +00:00
|
|
|
|
using Realms;
|
|
|
|
|
|
|
|
|
|
#nullable enable
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Models
|
|
|
|
|
{
|
|
|
|
|
[ExcludeFromDynamicCompile]
|
|
|
|
|
[MapTo("BeatmapSet")]
|
|
|
|
|
public class RealmBeatmapSet : RealmObject, IHasGuidPrimaryKey, IHasRealmFiles, ISoftDelete, IEquatable<RealmBeatmapSet>, IBeatmapSetInfo
|
|
|
|
|
{
|
|
|
|
|
[PrimaryKey]
|
|
|
|
|
public Guid ID { get; set; } = Guid.NewGuid();
|
|
|
|
|
|
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; }
|
|
|
|
|
|
2021-11-24 06:01:45 +00:00
|
|
|
|
public IBeatmapMetadataInfo Metadata => Beatmaps.FirstOrDefault()?.Metadata ?? new RealmBeatmapMetadata();
|
2021-10-11 06:25:00 +00:00
|
|
|
|
|
|
|
|
|
public IList<RealmBeatmap> Beatmaps { get; } = null!;
|
|
|
|
|
|
|
|
|
|
public IList<RealmNamedFileUsage> Files { get; } = null!;
|
|
|
|
|
|
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; }
|
|
|
|
|
|
|
|
|
|
public double MaxStarDifficulty => Beatmaps.Max(b => b.StarRating);
|
|
|
|
|
|
|
|
|
|
public double MaxLength => Beatmaps.Max(b => b.Length);
|
|
|
|
|
|
|
|
|
|
public double MaxBPM => Beatmaps.Max(b => b.BPM);
|
|
|
|
|
|
|
|
|
|
/// <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.
|
|
|
|
|
/// </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))?.File.GetStoragePath();
|
2021-10-11 06:25:00 +00:00
|
|
|
|
|
2021-11-12 09:48:34 +00:00
|
|
|
|
public bool Equals(RealmBeatmapSet? 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-16 03:25:37 +00:00
|
|
|
|
public bool Equals(IBeatmapSetInfo? other) => other is RealmBeatmapSet b && Equals(b);
|
|
|
|
|
|
2021-10-11 06:25:00 +00:00
|
|
|
|
IEnumerable<IBeatmapInfo> IBeatmapSetInfo.Beatmaps => Beatmaps;
|
2021-11-25 07:35:42 +00:00
|
|
|
|
IEnumerable<INamedFileUsage> IHasNamedFiles.Files => Files;
|
2021-10-11 06:25:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|