1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-26 04:32:55 +08:00
osu-lazer/osu.Game/Beatmaps/EFBeatmapInfo.cs

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

182 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 17:19:50 +08:00
2017-07-26 12:22:46 +08:00
using System;
using System.Collections.Generic;
2017-10-05 03:52:12 +08:00
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Newtonsoft.Json;
using osu.Framework.Testing;
2017-10-25 21:07:32 +08:00
using osu.Game.Database;
using osu.Game.Online.API.Requests.Responses;
2017-07-26 12:22:46 +08:00
using osu.Game.Rulesets;
using osu.Game.Scoring;
2018-04-13 17:19:50 +08:00
2017-07-26 12:22:46 +08:00
namespace osu.Game.Beatmaps
2016-11-07 23:12:49 +08:00
{
[ExcludeFromDynamicCompile]
[Serializable]
[Table(@"BeatmapInfo")]
public class EFBeatmapInfo : IEquatable<EFBeatmapInfo>, IHasPrimaryKey, IBeatmapInfo
2016-11-07 23:12:49 +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;
public int BeatmapVersion;
2018-04-13 17:19:50 +08:00
private int? onlineID;
2018-04-13 17:19:50 +08:00
[JsonProperty("id")]
[Column("OnlineBeatmapID")]
public int? OnlineID
{
get => onlineID;
set => onlineID = value > 0 ? value : null;
}
2018-04-13 17:19:50 +08:00
2018-11-30 17:06:48 +08:00
[JsonIgnore]
2017-10-14 13:28:25 +08:00
public int BeatmapSetInfoID { get; set; }
2018-04-13 17:19:50 +08:00
public BeatmapOnlineStatus Status { get; set; } = BeatmapOnlineStatus.None;
2017-10-10 04:30:32 +08:00
[Required]
2022-01-13 17:02:08 +08:00
public EFBeatmapSetInfo BeatmapSetInfo { get; set; }
2018-04-13 17:19:50 +08:00
public EFBeatmapMetadata Metadata { get; set; }
2018-04-13 17:19:50 +08:00
[JsonIgnore]
2017-10-14 13:28:25 +08:00
public int BaseDifficultyID { get; set; }
2018-04-13 17:19:50 +08:00
public EFBeatmapDifficulty BaseDifficulty { get; set; }
2018-04-13 17:19:50 +08:00
2017-10-05 03:52:12 +08:00
[NotMapped]
public APIBeatmap OnlineInfo { get; set; }
2018-04-13 17:19:50 +08:00
2019-07-08 01:25:36 +08:00
/// <summary>
2019-07-09 22:31:15 +08:00
/// The playable length in milliseconds of this beatmap.
2019-07-08 01:25:36 +08:00
/// </summary>
public double Length { get; set; }
2019-07-08 15:43:35 +08:00
/// <summary>
/// The most common BPM of this beatmap.
/// </summary>
public double BPM { get; set; }
2016-11-07 23:12:49 +08:00
public string Path { get; set; }
2018-04-13 17:19:50 +08:00
[JsonProperty("file_sha2")]
2017-03-04 18:02:36 +08:00
public string Hash { get; set; }
2018-04-13 17:19:50 +08:00
[JsonIgnore]
public bool Hidden { get; set; }
2018-04-13 17:19:50 +08:00
2017-08-22 11:42:35 +08: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 17:19:50 +08:00
2016-11-07 23:12:49 +08:00
// General
2019-11-21 17:21:49 +08:00
public double AudioLeadIn { get; set; }
public float StackLeniency { get; set; } = 0.7f;
2016-11-07 23:12:49 +08:00
public bool SpecialStyle { get; set; }
2018-04-13 17:19:50 +08:00
2022-01-13 17:02:08 +08:00
[Column("RulesetID")]
public int RulesetInfoID { get; set; }
2018-04-13 17:19:50 +08:00
2022-01-13 17:02:08 +08:00
public EFRulesetInfo RulesetInfo { get; set; }
2018-04-13 17:19:50 +08:00
2016-11-07 23:12:49 +08:00
public bool LetterboxInBreaks { get; set; }
public bool WidescreenStoryboard { get; set; }
2020-07-20 18:36:42 +08: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-05 03:52:12 +08:00
[NotMapped]
2019-11-28 21:41:29 +08:00
public int[] Bookmarks { get; set; } = Array.Empty<int>();
2018-04-13 17:19:50 +08:00
2016-11-07 23:12:49 +08:00
public double DistanceSpacing { get; set; }
public int BeatDivisor { get; set; }
public int GridSize { get; set; }
public double TimelineZoom { get; set; }
2018-04-13 17:19:50 +08:00
2016-11-07 23:12:49 +08:00
// Metadata
[Column("Version")]
public string DifficultyName { get; set; }
2021-04-18 09:52:25 +08:00
[JsonProperty("difficulty_rating")]
[Column("StarDifficulty")]
public double StarRating { get; set; }
2018-04-13 17:19:50 +08: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 => BeatmapDifficultyCache.GetDifficultyRating(StarRating);
public override string ToString() => this.GetDisplayTitle();
2018-04-13 17:19:50 +08:00
public bool Equals(EFBeatmapInfo other)
2021-11-12 17:09:45 +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:09:45 +08:00
2021-11-12 17:48:34 +08:00
if (ID != 0 && other.ID != 0)
return ID == other.ID;
2021-11-12 17:09:45 +08:00
return false;
}
public bool Equals(IBeatmapInfo other) => other is EFBeatmapInfo b && Equals(b);
2022-01-13 17:02:08 +08: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 17:19:50 +08:00
2022-01-13 17:02:08 +08: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 17:02:08 +08:00
IBeatmapMetadataInfo IBeatmapInfo.Metadata => Metadata ?? BeatmapSetInfo?.Metadata ?? new EFBeatmapMetadata();
[JsonIgnore]
IBeatmapDifficultyInfo IBeatmapInfo.Difficulty => BaseDifficulty;
[JsonIgnore]
2022-01-13 17:02:08 +08:00
IBeatmapSetInfo IBeatmapInfo.BeatmapSet => BeatmapSetInfo;
[JsonIgnore]
2022-01-13 17:02:08 +08:00
IRulesetInfo IBeatmapInfo.Ruleset => RulesetInfo;
#endregion
2016-11-07 23:12:49 +08:00
}
2016-11-07 21:52:23 +08:00
}