mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Merge dependencies
This commit is contained in:
@ -0,0 +1,58 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Cursor;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Game.Utils;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
|
{
|
||||||
|
public class TestSceneMetricNumbers : OsuTestScene
|
||||||
|
{
|
||||||
|
public TestSceneMetricNumbers()
|
||||||
|
{
|
||||||
|
Child = new FillFlowContainer
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Direction = FillDirection.Vertical,
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new DrawableNumber(0),
|
||||||
|
new DrawableNumber(1001),
|
||||||
|
new DrawableNumber(999_999),
|
||||||
|
new DrawableNumber(1_000_000),
|
||||||
|
new DrawableNumber(845_006_456),
|
||||||
|
new DrawableNumber(999_999_999),
|
||||||
|
new DrawableNumber(1_000_000_000),
|
||||||
|
new DrawableNumber(7_875_454_545),
|
||||||
|
new DrawableNumber(999_999_999_999),
|
||||||
|
new DrawableNumber(1_000_000_000_000),
|
||||||
|
new DrawableNumber(687_545_454_554_545),
|
||||||
|
new DrawableNumber(999_999_999_999_999),
|
||||||
|
new DrawableNumber(1_000_000_000_000_000),
|
||||||
|
new DrawableNumber(587_545_454_554_545_455),
|
||||||
|
new DrawableNumber(999_999_999_999_999_999),
|
||||||
|
new DrawableNumber(1_000_000_000_000_000_000),
|
||||||
|
new DrawableNumber(long.MaxValue),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private class DrawableNumber : SpriteText, IHasTooltip
|
||||||
|
{
|
||||||
|
public string TooltipText => value.ToString("F0");
|
||||||
|
|
||||||
|
private readonly long value;
|
||||||
|
|
||||||
|
public DrawableNumber(long value)
|
||||||
|
{
|
||||||
|
this.value = value;
|
||||||
|
Text = HumanizerUtils.ToMetric(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
18
osu.Game/Online/API/Requests/GetCountryRankingsRequest.cs
Normal file
18
osu.Game/Online/API/Requests/GetCountryRankingsRequest.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
|
||||||
|
namespace osu.Game.Online.API.Requests
|
||||||
|
{
|
||||||
|
public class GetCountryRankingsRequest : GetRankingsRequest<APICountryRankings>
|
||||||
|
{
|
||||||
|
public GetCountryRankingsRequest(RulesetInfo ruleset, int page = 1)
|
||||||
|
: base(ruleset, page)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string TargetPostfix() => "country";
|
||||||
|
}
|
||||||
|
}
|
34
osu.Game/Online/API/Requests/GetRankingsRequest.cs
Normal file
34
osu.Game/Online/API/Requests/GetRankingsRequest.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using osu.Framework.IO.Network;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace osu.Game.Online.API.Requests
|
||||||
|
{
|
||||||
|
public abstract class GetRankingsRequest<TModel> : APIRequest<List<TModel>>
|
||||||
|
{
|
||||||
|
private readonly RulesetInfo ruleset;
|
||||||
|
private readonly int page;
|
||||||
|
|
||||||
|
protected GetRankingsRequest(RulesetInfo ruleset, int page = 1)
|
||||||
|
{
|
||||||
|
this.ruleset = ruleset;
|
||||||
|
this.page = page;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override WebRequest CreateWebRequest()
|
||||||
|
{
|
||||||
|
var req = base.CreateWebRequest();
|
||||||
|
|
||||||
|
req.AddParameter("page", page.ToString());
|
||||||
|
|
||||||
|
return req;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string Target => $"rankings/{ruleset.ShortName}/{TargetPostfix()}";
|
||||||
|
|
||||||
|
protected abstract string TargetPostfix();
|
||||||
|
}
|
||||||
|
}
|
40
osu.Game/Online/API/Requests/GetUserRankingsRequest.cs
Normal file
40
osu.Game/Online/API/Requests/GetUserRankingsRequest.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using osu.Framework.IO.Network;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
|
||||||
|
namespace osu.Game.Online.API.Requests
|
||||||
|
{
|
||||||
|
public class GetUserRankingsRequest : GetRankingsRequest<APIUserRankings>
|
||||||
|
{
|
||||||
|
private readonly string country;
|
||||||
|
private readonly UserRankingsType type;
|
||||||
|
|
||||||
|
public GetUserRankingsRequest(RulesetInfo ruleset, UserRankingsType type = UserRankingsType.Performance, int page = 1, string country = null)
|
||||||
|
: base(ruleset, page)
|
||||||
|
{
|
||||||
|
this.type = type;
|
||||||
|
this.country = country;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override WebRequest CreateWebRequest()
|
||||||
|
{
|
||||||
|
var req = base.CreateWebRequest();
|
||||||
|
|
||||||
|
if (country != null)
|
||||||
|
req.AddParameter("country", country);
|
||||||
|
|
||||||
|
return req;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string TargetPostfix() => type.ToString().ToLowerInvariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum UserRankingsType
|
||||||
|
{
|
||||||
|
Performance,
|
||||||
|
Score
|
||||||
|
}
|
||||||
|
}
|
14
osu.Game/Online/API/Requests/Responses/APICountryRankings.cs
Normal file
14
osu.Game/Online/API/Requests/Responses/APICountryRankings.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using osu.Game.Users;
|
||||||
|
|
||||||
|
namespace osu.Game.Online.API.Requests.Responses
|
||||||
|
{
|
||||||
|
public class APICountryRankings : CountryStatistics
|
||||||
|
{
|
||||||
|
[JsonProperty]
|
||||||
|
public Country Country;
|
||||||
|
}
|
||||||
|
}
|
14
osu.Game/Online/API/Requests/Responses/APIUserRankings.cs
Normal file
14
osu.Game/Online/API/Requests/Responses/APIUserRankings.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using osu.Game.Users;
|
||||||
|
|
||||||
|
namespace osu.Game.Online.API.Requests.Responses
|
||||||
|
{
|
||||||
|
public class APIUserRankings : UserStatistics
|
||||||
|
{
|
||||||
|
[JsonProperty]
|
||||||
|
public User User;
|
||||||
|
}
|
||||||
|
}
|
25
osu.Game/Users/CountryStatistics.cs
Normal file
25
osu.Game/Users/CountryStatistics.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace osu.Game.Users
|
||||||
|
{
|
||||||
|
public class CountryStatistics
|
||||||
|
{
|
||||||
|
[JsonProperty(@"code")]
|
||||||
|
public string FlagName;
|
||||||
|
|
||||||
|
[JsonProperty(@"active_users")]
|
||||||
|
public long ActiveUsers;
|
||||||
|
|
||||||
|
[JsonProperty(@"play_count")]
|
||||||
|
public long PlayCount;
|
||||||
|
|
||||||
|
[JsonProperty(@"ranked_score")]
|
||||||
|
public long RankedScore;
|
||||||
|
|
||||||
|
[JsonProperty(@"performance")]
|
||||||
|
public long Performance;
|
||||||
|
}
|
||||||
|
}
|
@ -26,5 +26,32 @@ namespace osu.Game.Utils
|
|||||||
return input.Humanize(culture: new CultureInfo("en-US"));
|
return input.Humanize(culture: new CultureInfo("en-US"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Turns the current or provided big number into a readable string.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">The number to be humanized.</param>
|
||||||
|
/// <returns>Simplified number with a suffix.</returns>
|
||||||
|
public static string ToMetric(long input)
|
||||||
|
{
|
||||||
|
const int k = 1000;
|
||||||
|
|
||||||
|
if (input < k)
|
||||||
|
return input.ToString();
|
||||||
|
|
||||||
|
int i = (int)Math.Floor(Math.Round(Math.Log(input, k)));
|
||||||
|
return $"{input / Math.Pow(k, i):F} {suffixes[i]}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly string[] suffixes = new[]
|
||||||
|
{
|
||||||
|
"",
|
||||||
|
"k",
|
||||||
|
"million",
|
||||||
|
"billion",
|
||||||
|
"trillion",
|
||||||
|
"quadrillion",
|
||||||
|
"quintillion",
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user