osu/osu.Game/Beatmaps/EFBeatmapInfo.cs

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

184 lines
6.0 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 09:19:50 +00:00
2022-06-17 07:37:17 +00:00
#nullable disable
2017-07-26 04:22:46 +00:00
using System;
using System.Collections.Generic;
2017-10-04 19:52:12 +00:00
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Newtonsoft.Json;
using osu.Framework.Testing;
2017-10-25 13:07:32 +00:00
using osu.Game.Database;
using osu.Game.Online.API.Requests.Responses;
2017-07-26 04:22:46 +00:00
using osu.Game.Rulesets;
using osu.Game.Scoring;
2018-04-13 09:19:50 +00:00
2017-07-26 04:22:46 +00:00
namespace osu.Game.Beatmaps
2016-11-07 15:12:49 +00:00
{
[ExcludeFromDynamicCompile]
[Serializable]
[Table(@"BeatmapInfo")]
public class EFBeatmapInfo : IEquatable<EFBeatmapInfo>, IHasPrimaryKey, IBeatmapInfo
2016-11-07 15:12:49 +00:00
{
2017-10-14 05:28:25 +00:00
public int ID { get; set; }
2018-04-13 09:19:50 +00:00
public bool IsManaged => ID > 0;
public int BeatmapVersion;
2018-04-13 09:19:50 +00:00
private int? onlineID;
2018-04-13 09:19:50 +00:00
[JsonProperty("id")]
[Column("OnlineBeatmapID")]
public int? OnlineID
{
get => onlineID;
set => onlineID = value > 0 ? value : null;
}
2018-04-13 09:19:50 +00:00
2018-11-30 09:06:48 +00:00
[JsonIgnore]
2017-10-14 05:28:25 +00:00
public int BeatmapSetInfoID { get; set; }
2018-04-13 09:19:50 +00:00
public BeatmapOnlineStatus Status { get; set; } = BeatmapOnlineStatus.None;
2017-10-09 20:30:32 +00:00
[Required]
2022-01-13 09:02:08 +00:00
public EFBeatmapSetInfo BeatmapSetInfo { get; set; }
2018-04-13 09:19:50 +00:00
public EFBeatmapMetadata Metadata { get; set; }
2018-04-13 09:19:50 +00:00
[JsonIgnore]
2017-10-14 05:28:25 +00:00
public int BaseDifficultyID { get; set; }
2018-04-13 09:19:50 +00:00
public EFBeatmapDifficulty BaseDifficulty { get; set; }
2018-04-13 09:19:50 +00:00
2017-10-04 19:52:12 +00:00
[NotMapped]
public APIBeatmap OnlineInfo { get; set; }
2018-04-13 09:19:50 +00:00
2019-07-07 17:25:36 +00:00
/// <summary>
2019-07-09 14:31:15 +00:00
/// The playable length in milliseconds of this beatmap.
2019-07-07 17:25:36 +00:00
/// </summary>
public double Length { get; set; }
2019-07-08 07:43:35 +00:00
/// <summary>
/// The most common BPM of this beatmap.
/// </summary>
public double BPM { get; set; }
2016-11-07 15:12:49 +00:00
public string Path { get; set; }
2018-04-13 09:19:50 +00:00
[JsonProperty("file_sha2")]
2017-03-04 10:02:36 +00:00
public string Hash { get; set; }
2018-04-13 09:19:50 +00:00
[JsonIgnore]
public bool Hidden { get; set; }
2018-04-13 09:19:50 +00:00
2017-08-22 03:42:35 +00:00
/// <summary>
/// MD5 is kept for legacy support (matching against replays, osu-web-10 etc.).
/// </summary>
[JsonProperty("file_md5")]
public string MD5Hash { get; set; }
2018-04-13 09:19:50 +00:00
2016-11-07 15:12:49 +00:00
// General
2019-11-21 09:21:49 +00:00
public double AudioLeadIn { get; set; }
public float StackLeniency { get; set; } = 0.7f;
2016-11-07 15:12:49 +00:00
public bool SpecialStyle { get; set; }
2018-04-13 09:19:50 +00:00
2022-01-13 09:02:08 +00:00
[Column("RulesetID")]
public int RulesetInfoID { get; set; }
2018-04-13 09:19:50 +00:00
2022-01-13 09:02:08 +00:00
public EFRulesetInfo RulesetInfo { get; set; }
2018-04-13 09:19:50 +00:00
2016-11-07 15:12:49 +00:00
public bool LetterboxInBreaks { get; set; }
public bool WidescreenStoryboard { get; set; }
2020-07-20 10:36:42 +00:00
public bool EpilepsyWarning { get; set; }
/// <summary>
/// Whether or not sound samples should change rate when playing with speed-changing mods.
/// TODO: only read/write supported for now, requires implementation in gameplay.
/// </summary>
public bool SamplesMatchPlaybackRate { get; set; }
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; }
2017-10-04 19:52:12 +00:00
[NotMapped]
2019-11-28 13:41:29 +00:00
public int[] Bookmarks { get; set; } = Array.Empty<int>();
2018-04-13 09:19:50 +00:00
2016-11-07 15:12:49 +00:00
public double DistanceSpacing { get; set; }
public int BeatDivisor { get; set; }
public int GridSize { get; set; }
public double TimelineZoom { get; set; }
2018-04-13 09:19:50 +00:00
2016-11-07 15:12:49 +00:00
// Metadata
[Column("Version")]
public string DifficultyName { get; set; }
2021-04-18 01:52:25 +00:00
[JsonProperty("difficulty_rating")]
[Column("StarDifficulty")]
public double StarRating { get; set; }
2018-04-13 09:19:50 +00:00
/// <summary>
/// Currently only populated for beatmap deletion. Use <see cref="ScoreManager"/> to query scores.
/// </summary>
public List<EFScoreInfo> Scores { get; set; }
[JsonIgnore]
public DifficultyRating DifficultyRating => StarDifficulty.GetDifficultyRating(StarRating);
public override string ToString() => this.GetDisplayTitle();
2018-04-13 09:19:50 +00:00
public bool Equals(EFBeatmapInfo other)
2021-11-12 09:09:45 +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:09:45 +00:00
2021-11-12 09:48:34 +00:00
if (ID != 0 && other.ID != 0)
return ID == other.ID;
2021-11-12 09:09:45 +00:00
return false;
}
public bool Equals(IBeatmapInfo other) => other is EFBeatmapInfo b && Equals(b);
2022-01-13 09:02:08 +00:00
public bool AudioEquals(EFBeatmapInfo other) => other != null && BeatmapSetInfo != null && other.BeatmapSetInfo != null &&
BeatmapSetInfo.Hash == other.BeatmapSetInfo.Hash &&
(Metadata ?? BeatmapSetInfo.Metadata).AudioFile == (other.Metadata ?? other.BeatmapSetInfo.Metadata).AudioFile;
2018-04-13 09:19:50 +00:00
2022-01-13 09:02:08 +00:00
public bool BackgroundEquals(EFBeatmapInfo other) => other != null && BeatmapSetInfo != null && other.BeatmapSetInfo != null &&
BeatmapSetInfo.Hash == other.BeatmapSetInfo.Hash &&
(Metadata ?? BeatmapSetInfo.Metadata).BackgroundFile == (other.Metadata ?? other.BeatmapSetInfo.Metadata).BackgroundFile;
/// <summary>
/// Returns a shallow-clone of this <see cref="EFBeatmapInfo"/>.
/// </summary>
public EFBeatmapInfo Clone() => (EFBeatmapInfo)MemberwiseClone();
#region Implementation of IHasOnlineID
int IHasOnlineID<int>.OnlineID => OnlineID ?? -1;
#endregion
#region Implementation of IBeatmapInfo
[JsonIgnore]
2022-01-13 09:02:08 +00:00
IBeatmapMetadataInfo IBeatmapInfo.Metadata => Metadata ?? BeatmapSetInfo?.Metadata ?? new EFBeatmapMetadata();
[JsonIgnore]
IBeatmapDifficultyInfo IBeatmapInfo.Difficulty => BaseDifficulty;
[JsonIgnore]
2022-01-13 09:02:08 +00:00
IBeatmapSetInfo IBeatmapInfo.BeatmapSet => BeatmapSetInfo;
[JsonIgnore]
2022-01-13 09:02:08 +00:00
IRulesetInfo IBeatmapInfo.Ruleset => RulesetInfo;
#endregion
2016-11-07 15:12:49 +00:00
}
2016-11-07 13:52:23 +00:00
}