1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 20:22:55 +08:00

Add API retrieval support

This commit is contained in:
Dean Herbert 2017-09-14 20:05:43 +09:00
parent 9c4876d135
commit 98b847b025
8 changed files with 131 additions and 13 deletions

View File

@ -7,6 +7,7 @@ using System.Linq;
using Newtonsoft.Json; using Newtonsoft.Json;
using osu.Framework.IO.Network; using osu.Framework.IO.Network;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets;
using osu.Game.Users; using osu.Game.Users;
using osu.Game.Rulesets.Replays; using osu.Game.Rulesets.Replays;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
@ -73,6 +74,9 @@ namespace osu.Game.Online.API.Requests
set { Replay = value; } set { Replay = value; }
} }
[JsonProperty(@"mode_int")]
public int OnlineRulesetID { get; set; }
[JsonProperty(@"score_id")] [JsonProperty(@"score_id")]
private long onlineScoreID private long onlineScoreID
{ {
@ -85,6 +89,18 @@ namespace osu.Game.Online.API.Requests
set { Date = value; } set { Date = value; }
} }
[JsonProperty(@"beatmap")]
private BeatmapInfo beatmap
{
set { Beatmap = value; }
}
[JsonProperty(@"beatmapset")]
private BeatmapMetadata metadata
{
set { Beatmap.Metadata = value; }
}
[JsonProperty(@"statistics")] [JsonProperty(@"statistics")]
private Dictionary<string, dynamic> jsonStats private Dictionary<string, dynamic> jsonStats
{ {
@ -122,7 +138,12 @@ namespace osu.Game.Online.API.Requests
public void ApplyBeatmap(BeatmapInfo beatmap) public void ApplyBeatmap(BeatmapInfo beatmap)
{ {
Beatmap = beatmap; Beatmap = beatmap;
Ruleset = beatmap.Ruleset; ApplyRuleset(beatmap.Ruleset);
}
public void ApplyRuleset(RulesetInfo ruleset)
{
Ruleset = ruleset;
// Evaluate the mod string // Evaluate the mod string
Mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); Mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray();

View File

@ -0,0 +1,28 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
namespace osu.Game.Online.API.Requests
{
public class GetUserScoresRequest : APIRequest<List<OnlineScore>>
{
private readonly long userId;
private readonly ScoreType type;
public GetUserScoresRequest(long userId, ScoreType type)
{
this.userId = userId;
this.type = type;
}
protected override string Target => $@"users/{userId}/scores/{type.ToString().ToLower()}";
}
public enum ScoreType
{
Best,
Firsts,
Recent
}
}

View File

@ -7,6 +7,7 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Users;
using OpenTK.Graphics; using OpenTK.Graphics;
namespace osu.Game.Overlays.Profile namespace osu.Game.Overlays.Profile
@ -18,8 +19,17 @@ namespace osu.Game.Overlays.Profile
public abstract string Identifier { get; } public abstract string Identifier { get; }
private readonly FillFlowContainer content; private readonly FillFlowContainer content;
protected override Container<Drawable> Content => content; protected override Container<Drawable> Content => content;
public virtual User User
{
get { return user; }
set { user = value; }
}
private User user;
protected ProfileSection() protected ProfileSection()
{ {
Direction = FillDirection.Vertical; Direction = FillDirection.Vertical;

View File

@ -79,26 +79,28 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colour, LocalisationEngine locale) private void load(OsuColour colour, LocalisationEngine locale)
{ {
stats.Add(new OsuSpriteText { stats.Add(new OsuSpriteText
Text = score.PP + "pp", {
Text = $"{score.PP ?? 0}pp",
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight, Origin = Anchor.TopRight,
TextSize = 18, TextSize = 18,
Font = "Exo2.0-BoldItalic", Font = "Exo2.0-BoldItalic",
}); });
if(weight != -1) if (weight != -1)
{ {
stats.Add(new OsuSpriteText stats.Add(new OsuSpriteText
{ {
Text = $"weighted: {(int)(score.PP * weight)}pp ({weight.ToString("0%", CultureInfo.CurrentCulture)})", Text = $"weighted: {(int)(score?.PP * weight ?? 0)}pp ({weight.ToString("0%", CultureInfo.CurrentCulture)})",
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight, Origin = Anchor.TopRight,
Colour = colour.GrayA, Colour = colour.GrayA,
TextSize = 11, TextSize = 11,
Font = "Exo2.0-RegularItalic", Font = "Exo2.0-RegularItalic",
}); });
} }
stats.Add(new OsuSpriteText { stats.Add(new OsuSpriteText
{
Text = "accuracy: " + score.Accuracy.ToString("0.00%"), Text = "accuracy: " + score.Accuracy.ToString("0.00%"),
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight, Origin = Anchor.TopRight,

View File

@ -8,7 +8,13 @@ using osu.Game.Graphics.Sprites;
using osu.Game.Overlays.Profile.Sections.Ranks; using osu.Game.Overlays.Profile.Sections.Ranks;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Rulesets;
using osu.Game.Users;
namespace osu.Game.Overlays.Profile.Sections namespace osu.Game.Overlays.Profile.Sections
{ {
@ -21,6 +27,9 @@ namespace osu.Game.Overlays.Profile.Sections
private readonly ScoreFlowContainer best, first; private readonly ScoreFlowContainer best, first;
private readonly OsuSpriteText bestMissing, firstMissing; private readonly OsuSpriteText bestMissing, firstMissing;
private APIAccess api;
private RulesetStore rulesets;
public RanksSection() public RanksSection()
{ {
Children = new Drawable[] Children = new Drawable[]
@ -62,12 +71,57 @@ namespace osu.Game.Overlays.Profile.Sections
}; };
} }
public Score[] ScoresBest [BackgroundDependencyLoader]
private void load(APIAccess api, RulesetStore rulesets)
{
this.api = api;
this.rulesets = rulesets;
}
public override User User
{
get
{
return base.User;
}
set
{
base.User = value;
// fetch online ranks
foreach (ScoreType m in new[] { ScoreType.Best, ScoreType.Firsts })
{
ScoreType thisType = m;
var req = new GetUserScoresRequest(User.Id, m);
req.Success += scores =>
{
foreach (var s in scores)
s.ApplyRuleset(rulesets.GetRuleset(s.OnlineRulesetID));
switch (thisType)
{
case ScoreType.Best:
ScoresBest = scores;
break;
case ScoreType.Firsts:
ScoresFirst = scores;
break;
}
};
Schedule(() => { api.Queue(req); });
}
}
}
public IEnumerable<Score> ScoresBest
{ {
set set
{ {
best.Clear(); best.Clear();
if (value.Length == 0) if (!value.Any())
{ {
bestMissing.Show(); bestMissing.Show();
} }
@ -90,12 +144,12 @@ namespace osu.Game.Overlays.Profile.Sections
} }
} }
public Score[] ScoresFirst public IEnumerable<Score> ScoresFirst
{ {
set set
{ {
first.Clear(); first.Clear();
if (value.Length == 0) if (!value.Any())
{ {
firstMissing.Show(); firstMissing.Show();
} }

View File

@ -174,6 +174,8 @@ namespace osu.Game.Overlays
var sec = sections.FirstOrDefault(s => s.Identifier == id); var sec = sections.FirstOrDefault(s => s.Identifier == id);
if (sec != null) if (sec != null)
{ {
sec.User = user;
sectionsContainer.Add(sec); sectionsContainer.Add(sec);
tabs.AddItem(sec); tabs.AddItem(sec);
} }

View File

@ -20,7 +20,7 @@ namespace osu.Game.Rulesets.Scoring
public double Health { get; set; } = 1; public double Health { get; set; } = 1;
public double PP { get; set; } public double? PP { get; set; }
public int MaxCombo { get; set; } public int MaxCombo { get; set; }
@ -28,7 +28,7 @@ namespace osu.Game.Rulesets.Scoring
public RulesetInfo Ruleset { get; set; } public RulesetInfo Ruleset { get; set; }
public Mod[] Mods { get; set; } public Mod[] Mods { get; set; } = { };
public User User; public User User;

View File

@ -81,6 +81,7 @@
<Compile Include="Beatmaps\DifficultyCalculator.cs" /> <Compile Include="Beatmaps\DifficultyCalculator.cs" />
<Compile Include="Beatmaps\DummyWorkingBeatmap.cs" /> <Compile Include="Beatmaps\DummyWorkingBeatmap.cs" />
<Compile Include="Beatmaps\IO\LegacyFilesystemReader.cs" /> <Compile Include="Beatmaps\IO\LegacyFilesystemReader.cs" />
<Compile Include="Online\API\Requests\GetUserScoresRequest.cs" />
<Compile Include="Storyboards\Drawables\IFlippable.cs" /> <Compile Include="Storyboards\Drawables\IFlippable.cs" />
<Compile Include="Storyboards\Drawables\DrawableStoryboardLayer.cs" /> <Compile Include="Storyboards\Drawables\DrawableStoryboardLayer.cs" />
<Compile Include="Storyboards\Drawables\DrawableStoryboard.cs" /> <Compile Include="Storyboards\Drawables\DrawableStoryboard.cs" />