From c3df58e01c741c9ed204b66fe666b6c87855b1e3 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 19 Nov 2021 19:24:07 +0900 Subject: [PATCH] Add required properties to make realm models backwards compatible --- osu.Game/Beatmaps/BeatmapDifficulty.cs | 27 +++++++++++- osu.Game/Beatmaps/BeatmapInfo.cs | 59 ++++++++++++++++++++++---- osu.Game/Beatmaps/BeatmapMetadata.cs | 10 +++++ osu.Game/Models/RealmNamedFileUsage.cs | 10 +++++ osu.Game/Rulesets/RulesetInfo.cs | 8 +++- 5 files changed, 103 insertions(+), 11 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapDifficulty.cs b/osu.Game/Beatmaps/BeatmapDifficulty.cs index 6425c7b291..90a60c0f0c 100644 --- a/osu.Game/Beatmaps/BeatmapDifficulty.cs +++ b/osu.Game/Beatmaps/BeatmapDifficulty.cs @@ -12,6 +12,11 @@ namespace osu.Game.Beatmaps [MapTo("BeatmapDifficulty")] public class BeatmapDifficulty : EmbeddedObject, IBeatmapDifficultyInfo { + /// + /// The default value used for all difficulty settings except and . + /// + public const float DEFAULT_DIFFICULTY = 5; + public float DrainRate { get; set; } = IBeatmapDifficultyInfo.DEFAULT_DIFFICULTY; public float CircleSize { get; set; } = IBeatmapDifficultyInfo.DEFAULT_DIFFICULTY; public float OverallDifficulty { get; set; } = IBeatmapDifficultyInfo.DEFAULT_DIFFICULTY; @@ -20,6 +25,15 @@ namespace osu.Game.Beatmaps public double SliderMultiplier { get; set; } = 1; public double SliderTickRate { get; set; } = 1; + public BeatmapDifficulty() + { + } + + public BeatmapDifficulty(IBeatmapDifficultyInfo source) + { + CopyFrom(source); + } + /// /// Returns a shallow-clone of this . /// @@ -30,7 +44,7 @@ namespace osu.Game.Beatmaps return diff; } - public void CopyTo(BeatmapDifficulty difficulty) + public virtual void CopyTo(BeatmapDifficulty difficulty) { difficulty.ApproachRate = ApproachRate; difficulty.DrainRate = DrainRate; @@ -40,5 +54,16 @@ namespace osu.Game.Beatmaps difficulty.SliderMultiplier = SliderMultiplier; difficulty.SliderTickRate = SliderTickRate; } + + public virtual void CopyFrom(IBeatmapDifficultyInfo other) + { + ApproachRate = other.ApproachRate; + DrainRate = other.DrainRate; + CircleSize = other.CircleSize; + OverallDifficulty = other.OverallDifficulty; + + SliderMultiplier = other.SliderMultiplier; + SliderTickRate = other.SliderTickRate; + } } } diff --git a/osu.Game/Beatmaps/BeatmapInfo.cs b/osu.Game/Beatmaps/BeatmapInfo.cs index b000862457..796c2b2e90 100644 --- a/osu.Game/Beatmaps/BeatmapInfo.cs +++ b/osu.Game/Beatmaps/BeatmapInfo.cs @@ -8,6 +8,7 @@ using Newtonsoft.Json; using osu.Framework.Testing; using osu.Game.Database; using osu.Game.Models; +using osu.Game.Online.API.Requests.Responses; using osu.Game.Rulesets; using Realms; @@ -72,7 +73,7 @@ namespace osu.Game.Beatmaps } [UsedImplicitly] - private BeatmapInfo() + public BeatmapInfo() { } @@ -100,6 +101,13 @@ namespace osu.Game.Beatmaps public double TimelineZoom { get; set; } + public CountdownType Countdown { get; set; } = CountdownType.Normal; + + /// + /// The number of beats to move the countdown backwards (compared to its default location). + /// + public int CountdownOffset { get; set; } + #endregion public bool Equals(BeatmapInfo? other) @@ -113,20 +121,53 @@ namespace osu.Game.Beatmaps public bool Equals(IBeatmapInfo? other) => other is BeatmapInfo b && Equals(b); public bool AudioEquals(BeatmapInfo? other) => other != null - && BeatmapSet != null - && other.BeatmapSet != null - && BeatmapSet.Hash == other.BeatmapSet.Hash - && Metadata.AudioFile == other.Metadata.AudioFile; + && BeatmapSet != null + && other.BeatmapSet != null + && BeatmapSet.Hash == other.BeatmapSet.Hash + && Metadata.AudioFile == other.Metadata.AudioFile; public bool BackgroundEquals(BeatmapInfo? other) => other != null - && BeatmapSet != null - && other.BeatmapSet != null - && BeatmapSet.Hash == other.BeatmapSet.Hash - && Metadata.BackgroundFile == other.Metadata.BackgroundFile; + && BeatmapSet != null + && other.BeatmapSet != null + && BeatmapSet.Hash == other.BeatmapSet.Hash + && Metadata.BackgroundFile == other.Metadata.BackgroundFile; IBeatmapMetadataInfo IBeatmapInfo.Metadata => Metadata; IBeatmapSetInfo? IBeatmapInfo.BeatmapSet => BeatmapSet; IRulesetInfo IBeatmapInfo.Ruleset => Ruleset; IBeatmapDifficultyInfo IBeatmapInfo.Difficulty => Difficulty; + + #region Compatibility properties + + [Ignored] + public int RulesetID => Ruleset.OnlineID; + + [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(); + + public int BeatmapVersion; + + public BeatmapInfo Clone() => this.Detach(); + + #endregion } } diff --git a/osu.Game/Beatmaps/BeatmapMetadata.cs b/osu.Game/Beatmaps/BeatmapMetadata.cs index 387641db40..dc5517375d 100644 --- a/osu.Game/Beatmaps/BeatmapMetadata.cs +++ b/osu.Game/Beatmaps/BeatmapMetadata.cs @@ -44,5 +44,15 @@ namespace osu.Game.Beatmaps public string BackgroundFile { get; set; } = string.Empty; IUser IBeatmapMetadataInfo.Author => Author; + + #region Compatibility properties + + public string AuthorString + { + get => Author.Username; + set => Author.Username = value; + } + + #endregion } } diff --git a/osu.Game/Models/RealmNamedFileUsage.cs b/osu.Game/Models/RealmNamedFileUsage.cs index 17e32510a8..801c826292 100644 --- a/osu.Game/Models/RealmNamedFileUsage.cs +++ b/osu.Game/Models/RealmNamedFileUsage.cs @@ -31,5 +31,15 @@ namespace osu.Game.Models } IFileInfo INamedFileUsage.File => File; + + #region Compatibility properties + + public RealmFile FileInfo + { + get => File; + set => File = value; + } + + #endregion } } diff --git a/osu.Game/Rulesets/RulesetInfo.cs b/osu.Game/Rulesets/RulesetInfo.cs index 91a3d181f8..99b4f5915f 100644 --- a/osu.Game/Rulesets/RulesetInfo.cs +++ b/osu.Game/Rulesets/RulesetInfo.cs @@ -33,7 +33,7 @@ namespace osu.Game.Rulesets } [UsedImplicitly] - private RulesetInfo() + public RulesetInfo() { } @@ -83,5 +83,11 @@ namespace osu.Game.Rulesets return ruleset; } + + #region Compatibility properties + + public int ID => OnlineID; + + #endregion } }