2021-10-11 14:25:00 +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.
|
|
|
|
|
|
|
|
|
|
using System;
|
2021-11-22 14:30:11 +08:00
|
|
|
|
using System.Linq;
|
2022-01-07 13:17:22 +08:00
|
|
|
|
using AutoMapper;
|
2021-10-11 14:25:00 +08:00
|
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
|
using osu.Game.Database;
|
2021-11-19 18:07:21 +08:00
|
|
|
|
using osu.Game.Models;
|
2021-11-19 18:24:07 +08:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2021-10-11 14:25:00 +08:00
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
|
using Realms;
|
|
|
|
|
|
|
|
|
|
#nullable enable
|
|
|
|
|
|
2021-11-19 18:07:21 +08:00
|
|
|
|
namespace osu.Game.Beatmaps
|
2021-10-11 14:25:00 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A single beatmap difficulty.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ExcludeFromDynamicCompile]
|
|
|
|
|
[Serializable]
|
|
|
|
|
[MapTo("Beatmap")]
|
2021-11-19 18:07:21 +08:00
|
|
|
|
public class BeatmapInfo : RealmObject, IHasGuidPrimaryKey, IBeatmapInfo, IEquatable<BeatmapInfo>
|
2021-10-11 14:25:00 +08:00
|
|
|
|
{
|
|
|
|
|
[PrimaryKey]
|
|
|
|
|
public Guid ID { get; set; } = Guid.NewGuid();
|
|
|
|
|
|
|
|
|
|
public string DifficultyName { get; set; } = string.Empty;
|
|
|
|
|
|
2021-11-19 18:07:21 +08:00
|
|
|
|
public RulesetInfo Ruleset { get; set; } = null!;
|
2021-10-11 14:25:00 +08:00
|
|
|
|
|
2021-11-19 18:07:21 +08:00
|
|
|
|
public BeatmapDifficulty Difficulty { get; set; } = null!;
|
2021-10-11 14:25:00 +08:00
|
|
|
|
|
2021-11-19 18:07:21 +08:00
|
|
|
|
public BeatmapMetadata Metadata { get; set; } = null!;
|
2021-10-11 14:25:00 +08:00
|
|
|
|
|
2021-11-19 18:07:21 +08:00
|
|
|
|
public BeatmapSetInfo? BeatmapSet { get; set; }
|
2021-10-11 14:25:00 +08:00
|
|
|
|
|
2021-11-22 15:45:55 +08:00
|
|
|
|
[Ignored]
|
2021-12-21 15:09:32 +08:00
|
|
|
|
public RealmNamedFileUsage? File => BeatmapSet?.Files.FirstOrDefault(f => f.File.Hash == Hash);
|
2021-11-22 14:30:11 +08:00
|
|
|
|
|
2021-11-24 17:42:47 +08:00
|
|
|
|
public BeatmapOnlineStatus Status
|
2021-10-11 14:25:00 +08:00
|
|
|
|
{
|
2021-11-24 17:42:47 +08:00
|
|
|
|
get => (BeatmapOnlineStatus)StatusInt;
|
2021-10-11 14:25:00 +08:00
|
|
|
|
set => StatusInt = (int)value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[MapTo(nameof(Status))]
|
2021-11-24 17:48:12 +08:00
|
|
|
|
public int StatusInt { get; set; } = (int)BeatmapOnlineStatus.None;
|
2021-10-11 14:25:00 +08:00
|
|
|
|
|
2021-10-18 14:35:51 +08:00
|
|
|
|
[Indexed]
|
|
|
|
|
public int OnlineID { get; set; } = -1;
|
2021-10-11 14:25:00 +08:00
|
|
|
|
|
|
|
|
|
public double Length { get; set; }
|
|
|
|
|
|
|
|
|
|
public double BPM { get; set; }
|
|
|
|
|
|
|
|
|
|
public string Hash { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
public double StarRating { get; set; }
|
|
|
|
|
|
|
|
|
|
public string MD5Hash { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public bool Hidden { get; set; }
|
|
|
|
|
|
2021-11-19 18:07:21 +08:00
|
|
|
|
public BeatmapInfo(RulesetInfo ruleset, BeatmapDifficulty difficulty, BeatmapMetadata metadata)
|
2021-10-11 14:25:00 +08:00
|
|
|
|
{
|
|
|
|
|
Ruleset = ruleset;
|
|
|
|
|
Difficulty = difficulty;
|
|
|
|
|
Metadata = metadata;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[UsedImplicitly]
|
2022-01-10 12:25:23 +08:00
|
|
|
|
public BeatmapInfo() // TODO: this bypasses null safeties. needs to be hidden from user api (only should be used by realm).
|
2021-10-11 14:25:00 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Properties we may not want persisted (but also maybe no harm?)
|
|
|
|
|
|
|
|
|
|
public double AudioLeadIn { get; set; }
|
|
|
|
|
|
|
|
|
|
public float StackLeniency { get; set; } = 0.7f;
|
|
|
|
|
|
|
|
|
|
public bool SpecialStyle { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool LetterboxInBreaks { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool WidescreenStoryboard { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool EpilepsyWarning { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool SamplesMatchPlaybackRate { get; set; }
|
|
|
|
|
|
|
|
|
|
public double DistanceSpacing { get; set; }
|
|
|
|
|
|
|
|
|
|
public int BeatDivisor { get; set; }
|
|
|
|
|
|
|
|
|
|
public int GridSize { get; set; }
|
|
|
|
|
|
|
|
|
|
public double TimelineZoom { get; set; }
|
|
|
|
|
|
2021-12-14 20:00:19 +08:00
|
|
|
|
[Ignored]
|
2021-11-19 18:24:07 +08:00
|
|
|
|
public CountdownType Countdown { get; set; } = CountdownType.Normal;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The number of beats to move the countdown backwards (compared to its default location).
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int CountdownOffset { get; set; }
|
|
|
|
|
|
2021-10-11 14:25:00 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
2021-11-19 18:07:21 +08:00
|
|
|
|
public bool Equals(BeatmapInfo? other)
|
2021-11-12 17:48:34 +08:00
|
|
|
|
{
|
|
|
|
|
if (ReferenceEquals(this, other)) return true;
|
|
|
|
|
if (other == null) return false;
|
|
|
|
|
|
|
|
|
|
return ID == other.ID;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 18:07:21 +08:00
|
|
|
|
public bool Equals(IBeatmapInfo? other) => other is BeatmapInfo b && Equals(b);
|
2021-11-16 11:25:37 +08:00
|
|
|
|
|
2021-11-19 18:07:21 +08:00
|
|
|
|
public bool AudioEquals(BeatmapInfo? other) => other != null
|
2021-11-19 18:24:07 +08:00
|
|
|
|
&& BeatmapSet != null
|
|
|
|
|
&& other.BeatmapSet != null
|
|
|
|
|
&& BeatmapSet.Hash == other.BeatmapSet.Hash
|
|
|
|
|
&& Metadata.AudioFile == other.Metadata.AudioFile;
|
2021-10-11 14:25:00 +08:00
|
|
|
|
|
2021-11-19 18:07:21 +08:00
|
|
|
|
public bool BackgroundEquals(BeatmapInfo? other) => other != null
|
2021-11-19 18:24:07 +08:00
|
|
|
|
&& BeatmapSet != null
|
|
|
|
|
&& other.BeatmapSet != null
|
|
|
|
|
&& BeatmapSet.Hash == other.BeatmapSet.Hash
|
|
|
|
|
&& Metadata.BackgroundFile == other.Metadata.BackgroundFile;
|
2021-10-11 14:25:00 +08:00
|
|
|
|
|
|
|
|
|
IBeatmapMetadataInfo IBeatmapInfo.Metadata => Metadata;
|
|
|
|
|
IBeatmapSetInfo? IBeatmapInfo.BeatmapSet => BeatmapSet;
|
|
|
|
|
IRulesetInfo IBeatmapInfo.Ruleset => Ruleset;
|
|
|
|
|
IBeatmapDifficultyInfo IBeatmapInfo.Difficulty => Difficulty;
|
2021-11-19 18:24:07 +08:00
|
|
|
|
|
|
|
|
|
#region Compatibility properties
|
|
|
|
|
|
2021-12-21 15:30:34 +08:00
|
|
|
|
private int rulesetID;
|
|
|
|
|
|
2021-11-19 18:24:07 +08:00
|
|
|
|
[Ignored]
|
2022-01-07 13:17:22 +08:00
|
|
|
|
[IgnoreMap]
|
2021-12-21 15:30:34 +08:00
|
|
|
|
public int RulesetID
|
|
|
|
|
{
|
|
|
|
|
// ReSharper disable once ConstantConditionalAccessQualifier
|
|
|
|
|
get => Ruleset?.OnlineID ?? rulesetID;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (Ruleset != null)
|
|
|
|
|
throw new InvalidOperationException($"Cannot set a {nameof(RulesetID)} when {nameof(Ruleset)} is non-null");
|
|
|
|
|
|
|
|
|
|
rulesetID = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-19 18:24:07 +08:00
|
|
|
|
|
|
|
|
|
[Ignored]
|
|
|
|
|
public Guid BeatmapSetInfoID => BeatmapSet?.ID ?? Guid.Empty;
|
|
|
|
|
|
|
|
|
|
[Ignored]
|
|
|
|
|
public BeatmapDifficulty BaseDifficulty
|
|
|
|
|
{
|
|
|
|
|
get => Difficulty;
|
|
|
|
|
set => Difficulty = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Ignored]
|
|
|
|
|
public string? Path => File?.Filename;
|
|
|
|
|
|
|
|
|
|
[Ignored]
|
|
|
|
|
public APIBeatmap? OnlineInfo { get; set; }
|
|
|
|
|
|
|
|
|
|
[Ignored]
|
|
|
|
|
public int? MaxCombo { get; set; }
|
|
|
|
|
|
|
|
|
|
[Ignored]
|
|
|
|
|
public int[] Bookmarks { get; set; } = Array.Empty<int>();
|
|
|
|
|
|
|
|
|
|
public int BeatmapVersion;
|
|
|
|
|
|
2022-01-10 12:16:39 +08:00
|
|
|
|
public BeatmapInfo Clone() => (BeatmapInfo)this.Detach().MemberwiseClone();
|
2021-11-19 18:24:07 +08:00
|
|
|
|
|
2022-01-10 11:36:11 +08:00
|
|
|
|
public override string ToString() => this.GetDisplayTitle();
|
2022-01-07 13:17:22 +08:00
|
|
|
|
|
2021-11-19 18:24:07 +08:00
|
|
|
|
#endregion
|
2021-10-11 14:25:00 +08:00
|
|
|
|
}
|
|
|
|
|
}
|