1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-15 14:42:56 +08:00

Avoid constructor overhead for realm ScoreInfo parameterless constructor

This commit is contained in:
Dean Herbert 2022-01-20 16:43:51 +09:00
parent 3faf980fed
commit 3c852e6d02

View File

@ -29,11 +29,11 @@ namespace osu.Game.Scoring
public class ScoreInfo : RealmObject, IHasGuidPrimaryKey, IHasRealmFiles, ISoftDelete, IEquatable<ScoreInfo>, IScoreInfo public class ScoreInfo : RealmObject, IHasGuidPrimaryKey, IHasRealmFiles, ISoftDelete, IEquatable<ScoreInfo>, IScoreInfo
{ {
[PrimaryKey] [PrimaryKey]
public Guid ID { get; set; } = Guid.NewGuid(); public Guid ID { get; set; }
public BeatmapInfo BeatmapInfo { get; set; } public BeatmapInfo BeatmapInfo { get; set; } = null!;
public RulesetInfo Ruleset { get; set; } public RulesetInfo Ruleset { get; set; } = null!;
public IList<RealmNamedFileUsage> Files { get; } = null!; public IList<RealmNamedFileUsage> Files { get; } = null!;
@ -57,7 +57,7 @@ namespace osu.Game.Scoring
public long OnlineID { get; set; } = -1; public long OnlineID { get; set; } = -1;
[MapTo("User")] [MapTo("User")]
public RealmUser RealmUser { get; set; } public RealmUser RealmUser { get; set; } = null!;
[MapTo("Mods")] [MapTo("Mods")]
public string ModsJson { get; set; } = string.Empty; public string ModsJson { get; set; } = string.Empty;
@ -65,19 +65,17 @@ namespace osu.Game.Scoring
[MapTo("Statistics")] [MapTo("Statistics")]
public string StatisticsJson { get; set; } = string.Empty; public string StatisticsJson { get; set; } = string.Empty;
public ScoreInfo(BeatmapInfo beatmap, RulesetInfo ruleset, RealmUser realmUser) public ScoreInfo(BeatmapInfo? beatmap = null, RulesetInfo? ruleset = null, RealmUser? realmUser = null)
{ {
Ruleset = ruleset; Ruleset = ruleset ?? new RulesetInfo();
BeatmapInfo = beatmap; BeatmapInfo = beatmap ?? new BeatmapInfo();
RealmUser = realmUser; RealmUser = realmUser ?? new RealmUser();
ID = Guid.NewGuid();
} }
[UsedImplicitly] [UsedImplicitly] // Realm
public ScoreInfo() // TODO: consider removing this and migrating all usages to ctor with parameters. private ScoreInfo()
{ {
Ruleset = new RulesetInfo();
RealmUser = new RealmUser();
BeatmapInfo = new BeatmapInfo();
} }
// TODO: this is a bit temporary to account for the fact that this class is used to ferry API user data to certain UI components. // TODO: this is a bit temporary to account for the fact that this class is used to ferry API user data to certain UI components.