mirror of
https://github.com/ppy/osu.git
synced 2025-02-14 19:03:22 +08:00
Add required properties for compatibility with existing code
This commit is contained in:
parent
638b3d9161
commit
e44751c275
@ -3,11 +3,17 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Models;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Users;
|
||||
using Realms;
|
||||
|
||||
@ -80,5 +86,132 @@ namespace osu.Game.Scoring
|
||||
IBeatmapInfo IScoreInfo.Beatmap => Beatmap;
|
||||
IUser IScoreInfo.User => User;
|
||||
IEnumerable<INamedFileUsage> IHasNamedFiles.Files => Files;
|
||||
|
||||
#region Properties required to make things work with existing usages
|
||||
|
||||
private APIMod[]? localAPIMods;
|
||||
|
||||
private Mod[]? mods;
|
||||
|
||||
[Ignored]
|
||||
public List<HitEvent> HitEvents { get; set; } = new List<HitEvent>();
|
||||
|
||||
public ScoreInfo DeepClone()
|
||||
{
|
||||
var clone = (ScoreInfo)MemberwiseClone();
|
||||
|
||||
clone.Statistics = new Dictionary<HitResult, int>(clone.Statistics);
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
[Ignored]
|
||||
public bool Passed { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// The position of this score, starting at 1.
|
||||
/// </summary>
|
||||
[Ignored]
|
||||
public int? Position { get; set; } // TODO: remove after all calls to `CreateScoreInfo` are gone.
|
||||
|
||||
/// <summary>
|
||||
/// Whether this <see cref="EFScoreInfo"/> represents a legacy (osu!stable) score.
|
||||
/// </summary>
|
||||
[Ignored]
|
||||
public bool IsLegacyScore => Mods.OfType<ModClassic>().Any();
|
||||
|
||||
[Ignored]
|
||||
public Mod[] Mods
|
||||
{
|
||||
get
|
||||
{
|
||||
var rulesetInstance = Ruleset.CreateInstance();
|
||||
|
||||
Mod[] scoreMods = Array.Empty<Mod>();
|
||||
|
||||
if (mods != null)
|
||||
scoreMods = mods;
|
||||
else if (localAPIMods != null)
|
||||
scoreMods = APIMods.Select(m => m.ToMod(rulesetInstance)).ToArray();
|
||||
|
||||
return scoreMods;
|
||||
}
|
||||
set
|
||||
{
|
||||
localAPIMods = null;
|
||||
mods = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Used for API serialisation/deserialisation.
|
||||
[Ignored]
|
||||
public APIMod[] APIMods
|
||||
{
|
||||
get
|
||||
{
|
||||
if (localAPIMods != null)
|
||||
return localAPIMods;
|
||||
|
||||
if (mods == null)
|
||||
return Array.Empty<APIMod>();
|
||||
|
||||
return localAPIMods = mods.Select(m => new APIMod(m)).ToArray();
|
||||
}
|
||||
set
|
||||
{
|
||||
localAPIMods = value;
|
||||
|
||||
// We potentially can't update this yet due to Ruleset being late-bound, so instead update on read as necessary.
|
||||
mods = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Used for database serialisation/deserialisation.
|
||||
[Column("Mods")]
|
||||
public string ModsJson
|
||||
{
|
||||
get => JsonConvert.SerializeObject(APIMods);
|
||||
set => APIMods = JsonConvert.DeserializeObject<APIMod[]>(value) ?? Array.Empty<APIMod>();
|
||||
}
|
||||
|
||||
public IEnumerable<HitResultDisplayStatistic> GetStatisticsForDisplay()
|
||||
{
|
||||
foreach (var r in Ruleset.CreateInstance().GetHitResults())
|
||||
{
|
||||
int value = Statistics.GetValueOrDefault(r.result);
|
||||
|
||||
switch (r.result)
|
||||
{
|
||||
case HitResult.SmallTickHit:
|
||||
{
|
||||
int total = value + Statistics.GetValueOrDefault(HitResult.SmallTickMiss);
|
||||
if (total > 0)
|
||||
yield return new HitResultDisplayStatistic(r.result, value, total, r.displayName);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case HitResult.LargeTickHit:
|
||||
{
|
||||
int total = value + Statistics.GetValueOrDefault(HitResult.LargeTickMiss);
|
||||
if (total > 0)
|
||||
yield return new HitResultDisplayStatistic(r.result, value, total, r.displayName);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case HitResult.SmallTickMiss:
|
||||
case HitResult.LargeTickMiss:
|
||||
break;
|
||||
|
||||
default:
|
||||
yield return new HitResultDisplayStatistic(r.result, value, null, r.displayName);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user