1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 16:43:00 +08:00

Merge pull request #15356 from peppy/score-refactor/less-create-score-info

Change `DrawableProfileScore` to use `APIScoreInfo`
This commit is contained in:
Bartłomiej Dach 2021-11-01 16:00:32 +01:00 committed by GitHub
commit a4e65de2d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 78 additions and 71 deletions

View File

@ -136,7 +136,7 @@ namespace osu.Game.Tests.Visual.Gameplay
return new APIScoreInfo return new APIScoreInfo
{ {
OnlineID = 2553163309, OnlineID = 2553163309,
OnlineRulesetID = 0, RulesetID = 0,
Beatmap = CreateAPIBeatmapSet(new OsuRuleset().RulesetInfo).Beatmaps.First(), Beatmap = CreateAPIBeatmapSet(new OsuRuleset().RulesetInfo).Beatmaps.First(),
HasReplay = replayAvailable, HasReplay = replayAvailable,
User = new User User = new User

View File

@ -7,6 +7,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.BeatmapSet.Scores; using osu.Game.Overlays.BeatmapSet.Scores;
@ -61,10 +62,10 @@ namespace osu.Game.Tests.Visual.Online
}, },
Mods = new[] Mods = new[]
{ {
new OsuModDoubleTime().Acronym, new APIMod { Acronym = new OsuModDoubleTime().Acronym },
new OsuModHidden().Acronym, new APIMod { Acronym = new OsuModHidden().Acronym },
new OsuModFlashlight().Acronym, new APIMod { Acronym = new OsuModFlashlight().Acronym },
new OsuModHardRock().Acronym, new APIMod { Acronym = new OsuModHardRock().Acronym },
}, },
Rank = ScoreRank.XH, Rank = ScoreRank.XH,
PP = 200, PP = 200,
@ -86,9 +87,9 @@ namespace osu.Game.Tests.Visual.Online
}, },
Mods = new[] Mods = new[]
{ {
new OsuModDoubleTime().Acronym, new APIMod { Acronym = new OsuModDoubleTime().Acronym },
new OsuModHidden().Acronym, new APIMod { Acronym = new OsuModHidden().Acronym },
new OsuModFlashlight().Acronym, new APIMod { Acronym = new OsuModFlashlight().Acronym },
}, },
Rank = ScoreRank.S, Rank = ScoreRank.S,
PP = 190, PP = 190,
@ -110,8 +111,8 @@ namespace osu.Game.Tests.Visual.Online
}, },
Mods = new[] Mods = new[]
{ {
new OsuModDoubleTime().Acronym, new APIMod { Acronym = new OsuModDoubleTime().Acronym },
new OsuModHidden().Acronym, new APIMod { Acronym = new OsuModHidden().Acronym },
}, },
Rank = ScoreRank.B, Rank = ScoreRank.B,
PP = 180, PP = 180,
@ -133,7 +134,7 @@ namespace osu.Game.Tests.Visual.Online
}, },
Mods = new[] Mods = new[]
{ {
new OsuModDoubleTime().Acronym, new APIMod { Acronym = new OsuModDoubleTime().Acronym },
}, },
Rank = ScoreRank.C, Rank = ScoreRank.C,
PP = 170, PP = 170,
@ -226,10 +227,10 @@ namespace osu.Game.Tests.Visual.Online
}, },
Mods = new[] Mods = new[]
{ {
new OsuModDoubleTime().Acronym, new APIMod { Acronym = new OsuModDoubleTime().Acronym },
new OsuModHidden().Acronym, new APIMod { Acronym = new OsuModHidden().Acronym },
new OsuModFlashlight().Acronym, new APIMod { Acronym = new OsuModFlashlight().Acronym },
new OsuModHardRock().Acronym, new APIMod { Acronym = new OsuModHardRock().Acronym },
}, },
Rank = ScoreRank.XH, Rank = ScoreRank.XH,
PP = 200, PP = 200,

View File

@ -2,16 +2,16 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using osu.Game.Overlays.Profile.Sections.Ranks;
using osu.Framework.Graphics;
using osu.Game.Scoring;
using osu.Framework.Graphics.Containers;
using osuTK;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Overlays;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;
using osu.Game.Overlays.Profile.Sections.Ranks;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Scoring;
using osuTK;
namespace osu.Game.Tests.Visual.Online namespace osu.Game.Tests.Visual.Online
{ {
@ -19,79 +19,79 @@ namespace osu.Game.Tests.Visual.Online
{ {
public TestSceneUserProfileScores() public TestSceneUserProfileScores()
{ {
var firstScore = new ScoreInfo var firstScore = new APIScoreInfo
{ {
PP = 1047.21, PP = 1047.21,
Rank = ScoreRank.SH, Rank = ScoreRank.SH,
BeatmapInfo = new BeatmapInfo Beatmap = new APIBeatmap
{ {
Metadata = new BeatmapMetadata BeatmapSet = new APIBeatmapSet
{ {
Title = "JUSTadICE (TV Size)", Title = "JUSTadICE (TV Size)",
Artist = "Oomori Seiko" Artist = "Oomori Seiko",
}, },
Version = "Extreme" DifficultyName = "Extreme"
}, },
Date = DateTimeOffset.Now, Date = DateTimeOffset.Now,
Mods = new Mod[] Mods = new[]
{ {
new OsuModHidden(), new APIMod { Acronym = new OsuModHidden().Acronym },
new OsuModHardRock(), new APIMod { Acronym = new OsuModHardRock().Acronym },
new OsuModDoubleTime() new APIMod { Acronym = new OsuModDoubleTime().Acronym },
}, },
Accuracy = 0.9813 Accuracy = 0.9813
}; };
var secondScore = new ScoreInfo var secondScore = new APIScoreInfo
{ {
PP = 134.32, PP = 134.32,
Rank = ScoreRank.A, Rank = ScoreRank.A,
BeatmapInfo = new BeatmapInfo Beatmap = new APIBeatmap
{ {
Metadata = new BeatmapMetadata BeatmapSet = new APIBeatmapSet
{ {
Title = "Triumph & Regret", Title = "Triumph & Regret",
Artist = "typeMARS" Artist = "typeMARS",
}, },
Version = "[4K] Regret" DifficultyName = "[4K] Regret"
}, },
Date = DateTimeOffset.Now, Date = DateTimeOffset.Now,
Mods = new Mod[] Mods = new[]
{ {
new OsuModHardRock(), new APIMod { Acronym = new OsuModHardRock().Acronym },
new OsuModDoubleTime(), new APIMod { Acronym = new OsuModDoubleTime().Acronym },
}, },
Accuracy = 0.998546 Accuracy = 0.998546
}; };
var thirdScore = new ScoreInfo var thirdScore = new APIScoreInfo
{ {
PP = 96.83, PP = 96.83,
Rank = ScoreRank.S, Rank = ScoreRank.S,
BeatmapInfo = new BeatmapInfo Beatmap = new APIBeatmap
{ {
Metadata = new BeatmapMetadata BeatmapSet = new APIBeatmapSet
{ {
Title = "Idolize", Title = "Idolize",
Artist = "Creo" Artist = "Creo",
}, },
Version = "Insane" DifficultyName = "Insane"
}, },
Date = DateTimeOffset.Now, Date = DateTimeOffset.Now,
Accuracy = 0.9726 Accuracy = 0.9726
}; };
var noPPScore = new ScoreInfo var noPPScore = new APIScoreInfo
{ {
Rank = ScoreRank.B, Rank = ScoreRank.B,
BeatmapInfo = new BeatmapInfo Beatmap = new APIBeatmap
{ {
Metadata = new BeatmapMetadata BeatmapSet = new APIBeatmapSet
{ {
Title = "C18H27NO3(extend)", Title = "C18H27NO3(extend)",
Artist = "Team Grimoire" Artist = "Team Grimoire",
}, },
Version = "[4K] Cataclysmic Hypernova" DifficultyName = "[4K] Cataclysmic Hypernova"
}, },
Date = DateTimeOffset.Now, Date = DateTimeOffset.Now,
Accuracy = 0.55879 Accuracy = 0.55879

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using JetBrains.Annotations;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
@ -62,10 +63,13 @@ namespace osu.Game.Online.API.Requests.Responses
public Dictionary<string, int> Statistics { get; set; } public Dictionary<string, int> Statistics { get; set; }
[JsonProperty(@"mode_int")] [JsonProperty(@"mode_int")]
public int OnlineRulesetID { get; set; } public int RulesetID { get; set; }
[JsonProperty(@"mods")] [JsonProperty(@"mods")]
public string[] Mods { get; set; } private string[] mods { set => Mods = value.Select(acronym => new APIMod { Acronym = acronym }); }
[NotNull]
public IEnumerable<APIMod> Mods { get; set; } = Array.Empty<APIMod>();
[JsonProperty("rank")] [JsonProperty("rank")]
[JsonConverter(typeof(StringEnumConverter))] [JsonConverter(typeof(StringEnumConverter))]
@ -79,14 +83,14 @@ namespace osu.Game.Online.API.Requests.Responses
/// <returns></returns> /// <returns></returns>
public ScoreInfo CreateScoreInfo(RulesetStore rulesets, BeatmapInfo beatmap = null) public ScoreInfo CreateScoreInfo(RulesetStore rulesets, BeatmapInfo beatmap = null)
{ {
var ruleset = rulesets.GetRuleset(OnlineRulesetID); var ruleset = rulesets.GetRuleset(RulesetID);
var rulesetInstance = ruleset.CreateInstance(); var rulesetInstance = ruleset.CreateInstance();
var mods = Mods != null ? Mods.Select(acronym => rulesetInstance.CreateModFromAcronym(acronym)).Where(m => m != null).ToArray() : Array.Empty<Mod>(); var modInstances = Mods.Select(apiMod => rulesetInstance.CreateModFromAcronym(apiMod.Acronym)).Where(m => m != null).ToArray();
// all API scores provided by this class are considered to be legacy. // all API scores provided by this class are considered to be legacy.
mods = mods.Append(rulesetInstance.CreateMod<ModClassic>()).ToArray(); modInstances = modInstances.Append(rulesetInstance.CreateMod<ModClassic>()).ToArray();
var scoreInfo = new ScoreInfo var scoreInfo = new ScoreInfo
{ {
@ -98,11 +102,11 @@ namespace osu.Game.Online.API.Requests.Responses
OnlineScoreID = OnlineID, OnlineScoreID = OnlineID,
Date = Date, Date = Date,
PP = PP, PP = PP,
RulesetID = OnlineRulesetID, RulesetID = RulesetID,
Hash = HasReplay ? "online" : string.Empty, // todo: temporary? Hash = HasReplay ? "online" : string.Empty, // todo: temporary?
Rank = Rank, Rank = Rank,
Ruleset = ruleset, Ruleset = ruleset,
Mods = mods, Mods = modInstances,
}; };
if (beatmap != null) if (beatmap != null)
@ -144,7 +148,7 @@ namespace osu.Game.Online.API.Requests.Responses
return scoreInfo; return scoreInfo;
} }
public IRulesetInfo Ruleset => new RulesetInfo { ID = OnlineRulesetID }; public IRulesetInfo Ruleset => new RulesetInfo { ID = RulesetID };
IBeatmapInfo IScoreInfo.Beatmap => Beatmap; IBeatmapInfo IScoreInfo.Beatmap => Beatmap;
} }

View File

@ -12,9 +12,11 @@ using osu.Framework.Localisation;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Leaderboards; using osu.Game.Online.Leaderboards;
using osu.Game.Rulesets;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using osu.Game.Scoring; using osu.Game.Utils;
using osuTK; using osuTK;
namespace osu.Game.Overlays.Profile.Sections.Ranks namespace osu.Game.Overlays.Profile.Sections.Ranks
@ -26,7 +28,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
private const float performance_background_shear = 0.45f; private const float performance_background_shear = 0.45f;
protected readonly ScoreInfo Score; protected readonly APIScoreInfo Score;
[Resolved] [Resolved]
private OsuColour colours { get; set; } private OsuColour colours { get; set; }
@ -34,7 +36,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
[Resolved] [Resolved]
private OverlayColourProvider colourProvider { get; set; } private OverlayColourProvider colourProvider { get; set; }
public DrawableProfileScore(ScoreInfo score) public DrawableProfileScore(APIScoreInfo score)
{ {
Score = score; Score = score;
@ -43,7 +45,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load(RulesetStore rulesets)
{ {
AddInternal(new ProfileItemContainer AddInternal(new ProfileItemContainer
{ {
@ -79,7 +81,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
Spacing = new Vector2(0, 2), Spacing = new Vector2(0, 2),
Children = new Drawable[] Children = new Drawable[]
{ {
new ScoreBeatmapMetadataContainer(Score.BeatmapInfo), new ScoreBeatmapMetadataContainer(Score.Beatmap),
new FillFlowContainer new FillFlowContainer
{ {
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
@ -89,7 +91,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
{ {
new OsuSpriteText new OsuSpriteText
{ {
Text = $"{Score.BeatmapInfo.Version}", Text = $"{Score.Beatmap.DifficultyName}",
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Regular), Font = OsuFont.GetFont(size: 12, weight: FontWeight.Regular),
Colour = colours.Yellow Colour = colours.Yellow
}, },
@ -129,7 +131,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
Origin = Anchor.CentreRight, Origin = Anchor.CentreRight,
Direction = FillDirection.Horizontal, Direction = FillDirection.Horizontal,
Spacing = new Vector2(2), Spacing = new Vector2(2),
Children = Score.Mods.Select(mod => new ModIcon(mod) Children = Score.Mods.Select(mod => new ModIcon(rulesets.GetRuleset(Score.RulesetID).CreateInstance().CreateModFromAcronym(mod.Acronym))
{ {
Scale = new Vector2(0.35f) Scale = new Vector2(0.35f)
}).ToList(), }).ToList(),
@ -198,7 +200,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
Child = new OsuSpriteText Child = new OsuSpriteText
{ {
Text = Score.DisplayAccuracy, Text = Score.Accuracy.FormatAccuracy(),
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true), Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true),
Colour = colours.Yellow, Colour = colours.Yellow,
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,

View File

@ -6,8 +6,8 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Resources.Localisation.Web; using osu.Game.Resources.Localisation.Web;
using osu.Game.Scoring;
using osuTK; using osuTK;
namespace osu.Game.Overlays.Profile.Sections.Ranks namespace osu.Game.Overlays.Profile.Sections.Ranks
@ -16,7 +16,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
{ {
private readonly double weight; private readonly double weight;
public DrawableProfileWeightedScore(ScoreInfo score, double weight) public DrawableProfileWeightedScore(APIScoreInfo score, double weight)
: base(score) : base(score)
{ {
this.weight = weight; this.weight = weight;

View File

@ -69,10 +69,10 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
switch (type) switch (type)
{ {
default: default:
return new DrawableProfileScore(model.CreateScoreInfo(Rulesets)); return new DrawableProfileScore(model);
case ScoreType.Best: case ScoreType.Best:
return new DrawableProfileWeightedScore(model.CreateScoreInfo(Rulesets), Math.Pow(0.95, drawableItemIndex++)); return new DrawableProfileWeightedScore(model, Math.Pow(0.95, drawableItemIndex++));
} }
} }
} }