1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 00:47:24 +08:00
osu-lazer/osu.Game/Scoring/ScoreInfo.cs

100 lines
2.7 KiB
C#
Raw Normal View History

2018-04-13 17:19:50 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
2018-11-28 15:39:08 +08:00
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
2018-09-28 17:29:49 +08:00
using Newtonsoft.Json;
2018-04-13 17:19:50 +08:00
using osu.Game.Beatmaps;
2018-11-28 15:39:08 +08:00
using osu.Game.Database;
2018-11-28 15:33:42 +08:00
using osu.Game.Rulesets;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Mods;
using osu.Game.Users;
2018-11-28 15:33:42 +08:00
using osu.Game.Rulesets.Scoring;
2018-04-13 17:19:50 +08:00
2018-11-28 15:12:57 +08:00
namespace osu.Game.Scoring
2018-04-13 17:19:50 +08:00
{
2018-11-28 17:33:01 +08:00
public class ScoreInfo : IHasFiles<ScoreFileInfo>, IHasPrimaryKey, ISoftDelete
2018-04-13 17:19:50 +08:00
{
2018-11-28 15:39:08 +08:00
[JsonIgnore]
public int ID { get; set; }
2018-04-13 17:19:50 +08:00
public ScoreRank Rank { get; set; }
public double TotalScore { get; set; }
public double Accuracy { get; set; }
public double Health { get; set; } = 1;
public double? PP { get; set; }
public int MaxCombo { get; set; }
public int Combo { get; set; }
2018-11-28 16:26:46 +08:00
public int RulesetID { get; set; }
2018-04-13 17:19:50 +08:00
public RulesetInfo Ruleset { get; set; }
2018-11-28 18:47:20 +08:00
[NotMapped, JsonIgnore]
public Mod[] Mods
2018-11-28 15:39:08 +08:00
{
2018-11-28 18:47:20 +08:00
get
2018-11-28 15:39:08 +08:00
{
2018-11-30 13:24:10 +08:00
if (ModsString == null)
return Array.Empty<Mod>();
2018-11-30 13:24:10 +08:00
var deserialized = JsonConvert.DeserializeObject<string[]>(ModsString);
2018-11-28 18:47:20 +08:00
return Ruleset.CreateInstance().GetAllMods().Where(mod => deserialized.Any(d => d == mod.ShortenedName)).ToArray();
2018-11-28 15:39:08 +08:00
}
2018-11-30 13:24:10 +08:00
set => ModsString = JsonConvert.SerializeObject(value.Select(m => m.ShortenedName).ToArray());
2018-11-28 15:39:08 +08:00
}
2018-11-30 13:24:10 +08:00
public string ModsString { get; set; }
2018-11-28 18:47:20 +08:00
[NotMapped, JsonIgnore]
2018-04-13 17:19:50 +08:00
public User User;
2018-11-28 15:39:08 +08:00
public string UserString
{
get => User?.Username;
set => User = new User { Username = value };
}
public int BeatmapInfoID { get; set; }
2018-11-28 19:16:20 +08:00
public BeatmapInfo BeatmapInfo { get; set; }
2018-04-13 17:19:50 +08:00
2018-11-28 17:52:57 +08:00
public long? OnlineScoreID { get; set; }
2018-04-13 17:19:50 +08:00
2018-11-28 19:16:20 +08:00
public DateTimeOffset Date { get; set; }
2018-04-13 17:19:50 +08:00
[NotMapped, JsonIgnore]
2018-04-13 17:19:50 +08:00
public Dictionary<HitResult, object> Statistics = new Dictionary<HitResult, object>();
2018-11-28 15:39:08 +08:00
public string StatisticsString
{
get => JsonConvert.SerializeObject(Statistics);
set
{
if (value == null)
return;
Statistics = JsonConvert.DeserializeObject<Dictionary<HitResult, object>>(value);
}
}
/// <summary>
/// MD5 is kept for legacy support.
/// </summary>
[JsonProperty("file_md5")]
public string MD5Hash { get; set; }
2018-11-28 15:39:08 +08:00
public List<ScoreFileInfo> Files { get; set; }
public bool DeletePending { get; set; }
2018-04-13 17:19:50 +08:00
}
}