mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 18:33:20 +08:00
Add API retrieval support
This commit is contained in:
parent
9c4876d135
commit
98b847b025
@ -7,6 +7,7 @@ using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.IO.Network;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Users;
|
||||
using osu.Game.Rulesets.Replays;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
@ -73,6 +74,9 @@ namespace osu.Game.Online.API.Requests
|
||||
set { Replay = value; }
|
||||
}
|
||||
|
||||
[JsonProperty(@"mode_int")]
|
||||
public int OnlineRulesetID { get; set; }
|
||||
|
||||
[JsonProperty(@"score_id")]
|
||||
private long onlineScoreID
|
||||
{
|
||||
@ -85,6 +89,18 @@ namespace osu.Game.Online.API.Requests
|
||||
set { Date = value; }
|
||||
}
|
||||
|
||||
[JsonProperty(@"beatmap")]
|
||||
private BeatmapInfo beatmap
|
||||
{
|
||||
set { Beatmap = value; }
|
||||
}
|
||||
|
||||
[JsonProperty(@"beatmapset")]
|
||||
private BeatmapMetadata metadata
|
||||
{
|
||||
set { Beatmap.Metadata = value; }
|
||||
}
|
||||
|
||||
[JsonProperty(@"statistics")]
|
||||
private Dictionary<string, dynamic> jsonStats
|
||||
{
|
||||
@ -122,7 +138,12 @@ namespace osu.Game.Online.API.Requests
|
||||
public void ApplyBeatmap(BeatmapInfo beatmap)
|
||||
{
|
||||
Beatmap = beatmap;
|
||||
Ruleset = beatmap.Ruleset;
|
||||
ApplyRuleset(beatmap.Ruleset);
|
||||
}
|
||||
|
||||
public void ApplyRuleset(RulesetInfo ruleset)
|
||||
{
|
||||
Ruleset = ruleset;
|
||||
|
||||
// Evaluate the mod string
|
||||
Mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray();
|
||||
|
28
osu.Game/Online/API/Requests/GetUserScoresRequest.cs
Normal file
28
osu.Game/Online/API/Requests/GetUserScoresRequest.cs
Normal 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
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Users;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays.Profile
|
||||
@ -18,8 +19,17 @@ namespace osu.Game.Overlays.Profile
|
||||
public abstract string Identifier { get; }
|
||||
|
||||
private readonly FillFlowContainer content;
|
||||
|
||||
protected override Container<Drawable> Content => content;
|
||||
|
||||
public virtual User User
|
||||
{
|
||||
get { return user; }
|
||||
set { user = value; }
|
||||
}
|
||||
|
||||
private User user;
|
||||
|
||||
protected ProfileSection()
|
||||
{
|
||||
Direction = FillDirection.Vertical;
|
||||
|
@ -79,26 +79,28 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colour, LocalisationEngine locale)
|
||||
{
|
||||
stats.Add(new OsuSpriteText {
|
||||
Text = score.PP + "pp",
|
||||
stats.Add(new OsuSpriteText
|
||||
{
|
||||
Text = $"{score.PP ?? 0}pp",
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
TextSize = 18,
|
||||
Font = "Exo2.0-BoldItalic",
|
||||
});
|
||||
if(weight != -1)
|
||||
if (weight != -1)
|
||||
{
|
||||
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,
|
||||
Origin = Anchor.TopRight,
|
||||
Colour = colour.GrayA,
|
||||
TextSize = 11,
|
||||
Font = "Exo2.0-RegularItalic",
|
||||
});
|
||||
});
|
||||
}
|
||||
stats.Add(new OsuSpriteText {
|
||||
stats.Add(new OsuSpriteText
|
||||
{
|
||||
Text = "accuracy: " + score.Accuracy.ToString("0.00%"),
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
|
@ -8,7 +8,13 @@ using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Overlays.Profile.Sections.Ranks;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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
|
||||
{
|
||||
@ -21,6 +27,9 @@ namespace osu.Game.Overlays.Profile.Sections
|
||||
private readonly ScoreFlowContainer best, first;
|
||||
private readonly OsuSpriteText bestMissing, firstMissing;
|
||||
|
||||
private APIAccess api;
|
||||
private RulesetStore rulesets;
|
||||
|
||||
public RanksSection()
|
||||
{
|
||||
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
|
||||
{
|
||||
best.Clear();
|
||||
if (value.Length == 0)
|
||||
if (!value.Any())
|
||||
{
|
||||
bestMissing.Show();
|
||||
}
|
||||
@ -90,12 +144,12 @@ namespace osu.Game.Overlays.Profile.Sections
|
||||
}
|
||||
}
|
||||
|
||||
public Score[] ScoresFirst
|
||||
public IEnumerable<Score> ScoresFirst
|
||||
{
|
||||
set
|
||||
{
|
||||
first.Clear();
|
||||
if (value.Length == 0)
|
||||
if (!value.Any())
|
||||
{
|
||||
firstMissing.Show();
|
||||
}
|
||||
|
@ -174,6 +174,8 @@ namespace osu.Game.Overlays
|
||||
var sec = sections.FirstOrDefault(s => s.Identifier == id);
|
||||
if (sec != null)
|
||||
{
|
||||
sec.User = user;
|
||||
|
||||
sectionsContainer.Add(sec);
|
||||
tabs.AddItem(sec);
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ namespace osu.Game.Rulesets.Scoring
|
||||
|
||||
public double Health { get; set; } = 1;
|
||||
|
||||
public double PP { get; set; }
|
||||
public double? PP { get; set; }
|
||||
|
||||
public int MaxCombo { get; set; }
|
||||
|
||||
@ -28,7 +28,7 @@ namespace osu.Game.Rulesets.Scoring
|
||||
|
||||
public RulesetInfo Ruleset { get; set; }
|
||||
|
||||
public Mod[] Mods { get; set; }
|
||||
public Mod[] Mods { get; set; } = { };
|
||||
|
||||
public User User;
|
||||
|
||||
|
@ -81,6 +81,7 @@
|
||||
<Compile Include="Beatmaps\DifficultyCalculator.cs" />
|
||||
<Compile Include="Beatmaps\DummyWorkingBeatmap.cs" />
|
||||
<Compile Include="Beatmaps\IO\LegacyFilesystemReader.cs" />
|
||||
<Compile Include="Online\API\Requests\GetUserScoresRequest.cs" />
|
||||
<Compile Include="Storyboards\Drawables\IFlippable.cs" />
|
||||
<Compile Include="Storyboards\Drawables\DrawableStoryboardLayer.cs" />
|
||||
<Compile Include="Storyboards\Drawables\DrawableStoryboard.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user