2019-12-03 06:28:10 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 08:43:03 +00:00
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2022-01-17 06:15:34 +00:00
|
|
|
using System;
|
2019-03-24 16:02:36 +00:00
|
|
|
using System.Collections.Generic;
|
2022-01-17 07:23:58 +00:00
|
|
|
using System.Linq;
|
2022-01-17 06:15:34 +00:00
|
|
|
using NUnit.Framework;
|
2020-02-04 11:52:26 +00:00
|
|
|
using osu.Framework.Allocation;
|
2017-11-12 06:01:13 +00:00
|
|
|
using osu.Framework.Graphics;
|
2019-03-24 16:02:36 +00:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-11-12 06:01:13 +00:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2022-01-17 06:15:34 +00:00
|
|
|
using osu.Framework.Testing;
|
2020-01-09 04:43:44 +00:00
|
|
|
using osu.Framework.Utils;
|
2021-10-29 06:14:52 +00:00
|
|
|
using osu.Game.Online.API;
|
2019-07-08 09:02:10 +00:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2020-02-04 11:52:26 +00:00
|
|
|
using osu.Game.Overlays;
|
2017-11-12 06:01:13 +00:00
|
|
|
using osu.Game.Overlays.BeatmapSet.Scores;
|
|
|
|
using osu.Game.Rulesets.Osu.Mods;
|
2022-07-12 08:51:20 +00:00
|
|
|
using osu.Game.Rulesets.Scoring;
|
2018-11-28 07:12:57 +00:00
|
|
|
using osu.Game.Scoring;
|
2019-03-24 16:02:36 +00:00
|
|
|
using osu.Game.Users;
|
2019-07-09 09:16:58 +00:00
|
|
|
using osuTK.Graphics;
|
2021-11-04 09:02:44 +00:00
|
|
|
using APIUser = osu.Game.Online.API.Requests.Responses.APIUser;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2019-04-03 09:14:59 +00:00
|
|
|
namespace osu.Game.Tests.Visual.Online
|
2017-11-12 06:01:13 +00:00
|
|
|
{
|
2019-05-14 19:37:25 +00:00
|
|
|
public partial class TestSceneScoresContainer : OsuTestScene
|
2017-11-12 06:01:13 +00:00
|
|
|
{
|
2020-02-04 11:52:26 +00:00
|
|
|
[Cached]
|
|
|
|
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
|
|
|
|
|
2022-01-17 06:15:34 +00:00
|
|
|
private TestScoresContainer scoresContainer;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2022-01-17 06:15:34 +00:00
|
|
|
[SetUpSteps]
|
2022-01-17 07:23:58 +00:00
|
|
|
public void SetUp() => Schedule(() =>
|
2022-01-17 06:15:34 +00:00
|
|
|
{
|
2022-01-17 07:23:58 +00:00
|
|
|
Child = new Container
|
2017-11-12 06:01:13 +00:00
|
|
|
{
|
2022-01-17 07:23:58 +00:00
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Width = 0.8f,
|
|
|
|
Children = new Drawable[]
|
2017-11-12 06:01:13 +00:00
|
|
|
{
|
2022-01-17 07:23:58 +00:00
|
|
|
new Box
|
2019-07-09 09:16:58 +00:00
|
|
|
{
|
2022-01-17 07:23:58 +00:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.Black,
|
|
|
|
},
|
|
|
|
scoresContainer = new TestScoresContainer
|
|
|
|
{
|
|
|
|
Beatmap = { Value = CreateAPIBeatmap() }
|
2022-01-17 06:15:34 +00:00
|
|
|
}
|
2022-01-17 07:23:58 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestNoUserBest()
|
|
|
|
{
|
|
|
|
AddStep("Scores with no user best", () =>
|
|
|
|
{
|
|
|
|
var allScores = createScores();
|
|
|
|
|
|
|
|
allScores.UserScore = null;
|
|
|
|
|
|
|
|
scoresContainer.Scores = allScores;
|
2022-01-17 06:15:34 +00:00
|
|
|
});
|
2022-01-17 07:23:58 +00:00
|
|
|
|
|
|
|
AddUntilStep("wait for scores displayed", () => scoresContainer.ChildrenOfType<ScoreTableRowBackground>().Any());
|
|
|
|
AddAssert("no user best displayed", () => scoresContainer.ChildrenOfType<DrawableTopScore>().Count() == 1);
|
|
|
|
|
|
|
|
AddStep("Load null scores", () => scoresContainer.Scores = null);
|
|
|
|
|
|
|
|
AddUntilStep("wait for scores not displayed", () => !scoresContainer.ChildrenOfType<ScoreTableRowBackground>().Any());
|
|
|
|
AddAssert("no best score displayed", () => !scoresContainer.ChildrenOfType<DrawableTopScore>().Any());
|
|
|
|
|
|
|
|
AddStep("Load only one score", () =>
|
|
|
|
{
|
|
|
|
var allScores = createScores();
|
|
|
|
|
|
|
|
allScores.Scores.RemoveRange(1, allScores.Scores.Count - 1);
|
|
|
|
|
|
|
|
scoresContainer.Scores = allScores;
|
|
|
|
});
|
|
|
|
|
|
|
|
AddUntilStep("wait for scores not displayed", () => scoresContainer.ChildrenOfType<ScoreTableRowBackground>().Count() == 1);
|
|
|
|
AddAssert("no best score displayed", () => scoresContainer.ChildrenOfType<DrawableTopScore>().Count() == 1);
|
2022-01-17 06:15:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2022-01-17 07:23:58 +00:00
|
|
|
public void TestUserBest()
|
2022-01-17 06:15:34 +00:00
|
|
|
{
|
2022-01-17 07:23:58 +00:00
|
|
|
AddStep("Load scores with personal best", () =>
|
2022-01-17 06:15:34 +00:00
|
|
|
{
|
2022-01-17 07:23:58 +00:00
|
|
|
var allScores = createScores();
|
|
|
|
allScores.UserScore = createUserBest();
|
|
|
|
scoresContainer.Scores = allScores;
|
|
|
|
});
|
2022-01-17 06:15:34 +00:00
|
|
|
|
2022-01-17 07:23:58 +00:00
|
|
|
AddUntilStep("wait for scores displayed", () => scoresContainer.ChildrenOfType<ScoreTableRowBackground>().Any());
|
|
|
|
AddAssert("best score displayed", () => scoresContainer.ChildrenOfType<DrawableTopScore>().Count() == 2);
|
|
|
|
|
|
|
|
AddStep("Load scores with personal best (null position)", () =>
|
2022-01-17 06:15:34 +00:00
|
|
|
{
|
2022-01-17 07:23:58 +00:00
|
|
|
var allScores = createScores();
|
|
|
|
var userBest = createUserBest();
|
|
|
|
userBest.Position = null;
|
|
|
|
allScores.UserScore = userBest;
|
2022-01-17 06:15:34 +00:00
|
|
|
scoresContainer.Scores = allScores;
|
|
|
|
});
|
2022-01-17 07:23:58 +00:00
|
|
|
|
|
|
|
AddUntilStep("wait for scores displayed", () => scoresContainer.ChildrenOfType<ScoreTableRowBackground>().Any());
|
|
|
|
AddAssert("best score displayed", () => scoresContainer.ChildrenOfType<DrawableTopScore>().Count() == 2);
|
|
|
|
|
|
|
|
AddStep("Load scores with personal best (first place)", () =>
|
2022-01-17 06:15:34 +00:00
|
|
|
{
|
2022-01-17 07:23:58 +00:00
|
|
|
var allScores = createScores();
|
|
|
|
allScores.UserScore = new APIScoreWithPosition
|
|
|
|
{
|
|
|
|
Score = allScores.Scores.First(),
|
|
|
|
Position = 1,
|
|
|
|
};
|
2022-01-17 06:15:34 +00:00
|
|
|
scoresContainer.Scores = allScores;
|
|
|
|
});
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2022-01-17 07:23:58 +00:00
|
|
|
AddUntilStep("wait for scores displayed", () => scoresContainer.ChildrenOfType<ScoreTableRowBackground>().Any());
|
|
|
|
AddAssert("best score displayed", () => scoresContainer.ChildrenOfType<DrawableTopScore>().Count() == 1);
|
|
|
|
|
|
|
|
AddStep("Scores with no user best", () =>
|
2022-01-17 06:15:34 +00:00
|
|
|
{
|
2022-01-17 07:23:58 +00:00
|
|
|
var allScores = createScores();
|
|
|
|
|
|
|
|
allScores.UserScore = null;
|
|
|
|
|
2022-01-17 06:15:34 +00:00
|
|
|
scoresContainer.Scores = allScores;
|
|
|
|
});
|
2022-01-17 07:23:58 +00:00
|
|
|
|
2022-01-17 10:45:32 +00:00
|
|
|
AddUntilStep("best score not displayed", () => scoresContainer.ChildrenOfType<DrawableTopScore>().Count() == 1);
|
2022-01-17 06:15:34 +00:00
|
|
|
}
|
|
|
|
|
2022-07-25 06:28:59 +00:00
|
|
|
[Test]
|
|
|
|
public void TestUnprocessedPP()
|
|
|
|
{
|
|
|
|
AddStep("Load scores with unprocessed PP", () =>
|
|
|
|
{
|
|
|
|
var allScores = createScores();
|
|
|
|
allScores.Scores[0].PP = null;
|
|
|
|
allScores.UserScore = createUserBest();
|
|
|
|
allScores.UserScore.Score.PP = null;
|
|
|
|
scoresContainer.Scores = allScores;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-09-09 02:30:36 +00:00
|
|
|
private ulong onlineID = 1;
|
2022-01-17 07:23:58 +00:00
|
|
|
|
|
|
|
private APIScoresCollection createScores()
|
2022-01-17 06:15:34 +00:00
|
|
|
{
|
2022-01-17 07:23:58 +00:00
|
|
|
var scores = new APIScoresCollection
|
2017-11-12 06:01:13 +00:00
|
|
|
{
|
2022-07-12 08:51:20 +00:00
|
|
|
Scores = new List<SoloScoreInfo>
|
2017-11-12 06:01:13 +00:00
|
|
|
{
|
2022-07-12 08:51:20 +00:00
|
|
|
new SoloScoreInfo
|
2017-11-12 06:01:13 +00:00
|
|
|
{
|
2022-07-12 08:51:20 +00:00
|
|
|
EndedAt = DateTimeOffset.Now,
|
|
|
|
ID = onlineID++,
|
2022-01-17 07:23:58 +00:00
|
|
|
User = new APIUser
|
2017-11-12 06:01:13 +00:00
|
|
|
{
|
2022-01-17 07:23:58 +00:00
|
|
|
Id = 6602580,
|
|
|
|
Username = @"waaiiru",
|
2022-07-18 05:40:34 +00:00
|
|
|
CountryCode = CountryCode.ES,
|
2017-11-12 06:01:13 +00:00
|
|
|
},
|
2022-01-17 07:23:58 +00:00
|
|
|
Mods = new[]
|
2019-07-09 05:05:34 +00:00
|
|
|
{
|
2022-01-17 07:23:58 +00:00
|
|
|
new APIMod { Acronym = new OsuModDoubleTime().Acronym },
|
|
|
|
new APIMod { Acronym = new OsuModHidden().Acronym },
|
|
|
|
new APIMod { Acronym = new OsuModFlashlight().Acronym },
|
|
|
|
new APIMod { Acronym = new OsuModHardRock().Acronym },
|
2019-07-09 05:05:34 +00:00
|
|
|
},
|
2022-01-17 07:23:58 +00:00
|
|
|
Rank = ScoreRank.XH,
|
|
|
|
PP = 200,
|
|
|
|
MaxCombo = 1234,
|
|
|
|
TotalScore = 1234567890,
|
|
|
|
Accuracy = 1,
|
2017-11-12 06:01:13 +00:00
|
|
|
},
|
2022-07-12 08:51:20 +00:00
|
|
|
new SoloScoreInfo
|
2017-11-12 06:01:13 +00:00
|
|
|
{
|
2022-07-12 08:51:20 +00:00
|
|
|
EndedAt = DateTimeOffset.Now,
|
|
|
|
ID = onlineID++,
|
2022-01-17 07:23:58 +00:00
|
|
|
User = new APIUser
|
2017-11-12 06:01:13 +00:00
|
|
|
{
|
2022-01-17 07:23:58 +00:00
|
|
|
Id = 4608074,
|
|
|
|
Username = @"Skycries",
|
2022-07-18 05:40:34 +00:00
|
|
|
CountryCode = CountryCode.BR,
|
2017-11-12 06:01:13 +00:00
|
|
|
},
|
2022-01-17 07:23:58 +00:00
|
|
|
Mods = new[]
|
|
|
|
{
|
|
|
|
new APIMod { Acronym = new OsuModDoubleTime().Acronym },
|
|
|
|
new APIMod { Acronym = new OsuModHidden().Acronym },
|
|
|
|
new APIMod { Acronym = new OsuModFlashlight().Acronym },
|
|
|
|
},
|
|
|
|
Rank = ScoreRank.S,
|
|
|
|
PP = 190,
|
|
|
|
MaxCombo = 1234,
|
|
|
|
TotalScore = 1234789,
|
|
|
|
Accuracy = 0.9997,
|
2017-11-12 06:01:13 +00:00
|
|
|
},
|
2022-07-12 08:51:20 +00:00
|
|
|
new SoloScoreInfo
|
2019-07-08 09:02:10 +00:00
|
|
|
{
|
2022-07-12 08:51:20 +00:00
|
|
|
EndedAt = DateTimeOffset.Now,
|
|
|
|
ID = onlineID++,
|
2022-01-17 07:23:58 +00:00
|
|
|
User = new APIUser
|
|
|
|
{
|
|
|
|
Id = 1014222,
|
|
|
|
Username = @"eLy",
|
2022-07-18 05:40:34 +00:00
|
|
|
CountryCode = CountryCode.JP,
|
2022-01-17 07:23:58 +00:00
|
|
|
},
|
|
|
|
Mods = new[]
|
2019-07-08 09:02:10 +00:00
|
|
|
{
|
2022-01-17 07:23:58 +00:00
|
|
|
new APIMod { Acronym = new OsuModDoubleTime().Acronym },
|
|
|
|
new APIMod { Acronym = new OsuModHidden().Acronym },
|
2019-07-08 09:02:10 +00:00
|
|
|
},
|
2022-01-17 07:23:58 +00:00
|
|
|
Rank = ScoreRank.B,
|
2022-07-25 06:28:59 +00:00
|
|
|
PP = 180,
|
2022-01-17 07:23:58 +00:00
|
|
|
MaxCombo = 1234,
|
|
|
|
TotalScore = 12345678,
|
|
|
|
Accuracy = 0.9854,
|
2019-07-08 09:02:10 +00:00
|
|
|
},
|
2022-07-12 08:51:20 +00:00
|
|
|
new SoloScoreInfo
|
2022-01-17 06:15:34 +00:00
|
|
|
{
|
2022-07-12 08:51:20 +00:00
|
|
|
EndedAt = DateTimeOffset.Now,
|
|
|
|
ID = onlineID++,
|
2022-01-17 07:23:58 +00:00
|
|
|
User = new APIUser
|
|
|
|
{
|
|
|
|
Id = 1541390,
|
|
|
|
Username = @"Toukai",
|
2022-07-18 05:40:34 +00:00
|
|
|
CountryCode = CountryCode.CA,
|
2022-01-17 07:23:58 +00:00
|
|
|
},
|
|
|
|
Mods = new[]
|
|
|
|
{
|
|
|
|
new APIMod { Acronym = new OsuModDoubleTime().Acronym },
|
|
|
|
},
|
|
|
|
Rank = ScoreRank.C,
|
|
|
|
PP = 170,
|
|
|
|
MaxCombo = 1234,
|
|
|
|
TotalScore = 1234567,
|
|
|
|
Accuracy = 0.8765,
|
2022-01-17 06:15:34 +00:00
|
|
|
},
|
2022-07-12 08:51:20 +00:00
|
|
|
new SoloScoreInfo
|
2020-02-20 06:04:12 +00:00
|
|
|
{
|
2022-07-12 08:51:20 +00:00
|
|
|
EndedAt = DateTimeOffset.Now,
|
|
|
|
ID = onlineID++,
|
2022-01-17 07:23:58 +00:00
|
|
|
User = new APIUser
|
2020-02-20 06:04:12 +00:00
|
|
|
{
|
2022-01-17 07:23:58 +00:00
|
|
|
Id = 7151382,
|
|
|
|
Username = @"Mayuri Hana",
|
2022-07-18 05:40:34 +00:00
|
|
|
CountryCode = CountryCode.TH,
|
2020-02-20 06:04:12 +00:00
|
|
|
},
|
2022-01-17 07:23:58 +00:00
|
|
|
Rank = ScoreRank.D,
|
|
|
|
PP = 160,
|
|
|
|
MaxCombo = 1234,
|
|
|
|
TotalScore = 123456,
|
|
|
|
Accuracy = 0.6543,
|
2020-02-20 06:04:12 +00:00
|
|
|
},
|
2022-01-17 07:23:58 +00:00
|
|
|
}
|
|
|
|
};
|
2020-02-20 06:04:12 +00:00
|
|
|
|
2022-07-15 08:39:08 +00:00
|
|
|
const int initial_great_count = 2000;
|
2022-07-19 21:50:37 +00:00
|
|
|
const int initial_tick_count = 100;
|
2022-07-15 08:39:08 +00:00
|
|
|
|
|
|
|
int greatCount = initial_great_count;
|
2022-07-19 21:50:37 +00:00
|
|
|
int tickCount = initial_tick_count;
|
2022-07-15 08:39:08 +00:00
|
|
|
|
2022-01-17 07:23:58 +00:00
|
|
|
foreach (var s in scores.Scores)
|
2019-07-09 05:05:34 +00:00
|
|
|
{
|
2022-07-12 08:51:20 +00:00
|
|
|
s.Statistics = new Dictionary<HitResult, int>
|
2019-07-09 05:05:34 +00:00
|
|
|
{
|
2022-07-19 21:50:37 +00:00
|
|
|
{ HitResult.Great, greatCount },
|
|
|
|
{ HitResult.LargeTickHit, tickCount },
|
2022-07-15 08:39:08 +00:00
|
|
|
{ HitResult.Ok, RNG.Next(100) },
|
|
|
|
{ HitResult.Meh, RNG.Next(100) },
|
2022-07-19 21:50:37 +00:00
|
|
|
{ HitResult.Miss, initial_great_count - greatCount },
|
|
|
|
{ HitResult.LargeTickMiss, initial_tick_count - tickCount },
|
2022-01-17 07:23:58 +00:00
|
|
|
};
|
2022-07-19 21:50:37 +00:00
|
|
|
|
|
|
|
greatCount -= 100;
|
|
|
|
tickCount -= RNG.Next(1, 5);
|
2022-01-17 07:23:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return scores;
|
|
|
|
}
|
2019-07-09 05:05:34 +00:00
|
|
|
|
2022-01-17 07:23:58 +00:00
|
|
|
private APIScoreWithPosition createUserBest() => new APIScoreWithPosition
|
2022-01-17 06:15:34 +00:00
|
|
|
{
|
2022-07-12 08:51:20 +00:00
|
|
|
Score = new SoloScoreInfo
|
2017-11-12 06:01:13 +00:00
|
|
|
{
|
2022-07-12 08:51:20 +00:00
|
|
|
EndedAt = DateTimeOffset.Now,
|
|
|
|
ID = onlineID++,
|
2022-01-17 06:15:34 +00:00
|
|
|
User = new APIUser
|
2019-12-03 07:18:36 +00:00
|
|
|
{
|
2022-01-17 06:15:34 +00:00
|
|
|
Id = 7151382,
|
|
|
|
Username = @"Mayuri Hana",
|
2022-07-18 05:40:34 +00:00
|
|
|
CountryCode = CountryCode.TH,
|
2022-01-17 06:15:34 +00:00
|
|
|
},
|
|
|
|
Rank = ScoreRank.D,
|
|
|
|
PP = 160,
|
|
|
|
MaxCombo = 1234,
|
|
|
|
TotalScore = 123456,
|
|
|
|
Accuracy = 0.6543,
|
|
|
|
},
|
2022-01-17 07:23:58 +00:00
|
|
|
Position = 1337,
|
2022-01-17 06:15:34 +00:00
|
|
|
};
|
2019-07-10 16:40:29 +00:00
|
|
|
|
|
|
|
private partial class TestScoresContainer : ScoresContainer
|
|
|
|
{
|
2021-10-28 08:48:56 +00:00
|
|
|
public new APIScoresCollection Scores
|
2019-07-10 16:40:29 +00:00
|
|
|
{
|
|
|
|
set => base.Scores = value;
|
|
|
|
}
|
|
|
|
}
|
2017-11-12 06:01:13 +00:00
|
|
|
}
|
|
|
|
}
|