2019-07-29 22:23:25 +00:00
|
|
|
// 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.
|
|
|
|
|
2020-06-24 07:57:17 +00:00
|
|
|
using System.Linq;
|
2021-02-15 06:31:51 +00:00
|
|
|
using System.Threading;
|
2020-06-24 07:57:17 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Platform;
|
2019-07-29 22:23:25 +00:00
|
|
|
using osu.Framework.Testing;
|
2020-06-24 07:57:17 +00:00
|
|
|
using osu.Framework.Utils;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Rulesets;
|
2019-07-29 22:23:25 +00:00
|
|
|
using osu.Game.Tests.Visual;
|
2021-04-04 12:58:25 +00:00
|
|
|
using osu.Game.Tournament.IO;
|
2020-06-24 07:57:17 +00:00
|
|
|
using osu.Game.Tournament.IPC;
|
|
|
|
using osu.Game.Tournament.Models;
|
|
|
|
using osu.Game.Users;
|
2019-07-29 22:23:25 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Tests
|
|
|
|
{
|
|
|
|
public abstract class TournamentTestScene : OsuTestScene
|
|
|
|
{
|
2021-08-28 07:22:01 +00:00
|
|
|
private TournamentMatch match;
|
|
|
|
|
2020-06-24 07:57:17 +00:00
|
|
|
[Cached]
|
|
|
|
protected LadderInfo Ladder { get; private set; } = new LadderInfo();
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private RulesetStore rulesetStore { get; set; }
|
|
|
|
|
|
|
|
[Cached]
|
|
|
|
protected MatchIPCInfo IPCInfo { get; private set; } = new MatchIPCInfo();
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2021-04-04 12:58:25 +00:00
|
|
|
private void load(TournamentStorage storage)
|
2020-06-24 07:57:17 +00:00
|
|
|
{
|
|
|
|
Ladder.Ruleset.Value ??= rulesetStore.AvailableRulesets.First();
|
|
|
|
|
2021-08-28 07:22:01 +00:00
|
|
|
match = CreateSampleMatch();
|
2020-06-24 07:57:17 +00:00
|
|
|
|
|
|
|
Ladder.Rounds.Add(match.Round.Value);
|
|
|
|
Ladder.Matches.Add(match);
|
|
|
|
Ladder.Teams.Add(match.Team1.Value);
|
|
|
|
Ladder.Teams.Add(match.Team2.Value);
|
|
|
|
|
2020-06-24 08:57:07 +00:00
|
|
|
Ruleset.BindTo(Ladder.Ruleset);
|
|
|
|
Dependencies.CacheAs(new StableInfo(storage));
|
2020-06-24 07:57:17 +00:00
|
|
|
}
|
|
|
|
|
2021-08-28 07:22:01 +00:00
|
|
|
[SetUpSteps]
|
|
|
|
public virtual void SetUpSteps()
|
|
|
|
{
|
|
|
|
AddStep("set current match", () => Ladder.CurrentMatch.Value = match);
|
|
|
|
}
|
|
|
|
|
2020-06-24 07:57:17 +00:00
|
|
|
public static TournamentMatch CreateSampleMatch() => new TournamentMatch
|
|
|
|
{
|
|
|
|
Team1 =
|
|
|
|
{
|
|
|
|
Value = new TournamentTeam
|
|
|
|
{
|
2020-06-24 08:57:07 +00:00
|
|
|
Acronym = { Value = "JPN" },
|
2020-06-24 07:57:17 +00:00
|
|
|
FlagName = { Value = "JP" },
|
|
|
|
FullName = { Value = "Japan" },
|
|
|
|
LastYearPlacing = { Value = 10 },
|
|
|
|
Seed = { Value = "Low" },
|
|
|
|
SeedingResults =
|
|
|
|
{
|
|
|
|
new SeedingResult
|
|
|
|
{
|
|
|
|
Mod = { Value = "NM" },
|
|
|
|
Seed = { Value = 10 },
|
|
|
|
Beatmaps =
|
|
|
|
{
|
|
|
|
new SeedingBeatmap
|
|
|
|
{
|
|
|
|
BeatmapInfo = CreateSampleBeatmapInfo(),
|
|
|
|
Score = 12345672,
|
|
|
|
Seed = { Value = 24 },
|
|
|
|
},
|
|
|
|
new SeedingBeatmap
|
|
|
|
{
|
|
|
|
BeatmapInfo = CreateSampleBeatmapInfo(),
|
|
|
|
Score = 1234567,
|
|
|
|
Seed = { Value = 12 },
|
|
|
|
},
|
|
|
|
new SeedingBeatmap
|
|
|
|
{
|
|
|
|
BeatmapInfo = CreateSampleBeatmapInfo(),
|
|
|
|
Score = 1234567,
|
|
|
|
Seed = { Value = 16 },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new SeedingResult
|
|
|
|
{
|
|
|
|
Mod = { Value = "DT" },
|
|
|
|
Seed = { Value = 5 },
|
|
|
|
Beatmaps =
|
|
|
|
{
|
|
|
|
new SeedingBeatmap
|
|
|
|
{
|
|
|
|
BeatmapInfo = CreateSampleBeatmapInfo(),
|
|
|
|
Score = 234567,
|
|
|
|
Seed = { Value = 3 },
|
|
|
|
},
|
|
|
|
new SeedingBeatmap
|
|
|
|
{
|
|
|
|
BeatmapInfo = CreateSampleBeatmapInfo(),
|
|
|
|
Score = 234567,
|
|
|
|
Seed = { Value = 6 },
|
|
|
|
},
|
|
|
|
new SeedingBeatmap
|
|
|
|
{
|
|
|
|
BeatmapInfo = CreateSampleBeatmapInfo(),
|
|
|
|
Score = 234567,
|
|
|
|
Seed = { Value = 12 },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Players =
|
|
|
|
{
|
2021-02-17 05:50:48 +00:00
|
|
|
new User { Username = "Hello", Statistics = new UserStatistics { GlobalRank = 12 } },
|
|
|
|
new User { Username = "Hello", Statistics = new UserStatistics { GlobalRank = 16 } },
|
|
|
|
new User { Username = "Hello", Statistics = new UserStatistics { GlobalRank = 20 } },
|
|
|
|
new User { Username = "Hello", Statistics = new UserStatistics { GlobalRank = 24 } },
|
|
|
|
new User { Username = "Hello", Statistics = new UserStatistics { GlobalRank = 30 } },
|
2020-06-24 07:57:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Team2 =
|
|
|
|
{
|
|
|
|
Value = new TournamentTeam
|
|
|
|
{
|
2020-06-24 08:57:07 +00:00
|
|
|
Acronym = { Value = "USA" },
|
2020-06-24 07:57:17 +00:00
|
|
|
FlagName = { Value = "US" },
|
|
|
|
FullName = { Value = "United States" },
|
|
|
|
Players =
|
|
|
|
{
|
|
|
|
new User { Username = "Hello" },
|
|
|
|
new User { Username = "Hello" },
|
|
|
|
new User { Username = "Hello" },
|
|
|
|
new User { Username = "Hello" },
|
|
|
|
new User { Username = "Hello" },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Round =
|
|
|
|
{
|
|
|
|
Value = new TournamentRound { Name = { Value = "Quarterfinals" } }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
public static BeatmapInfo CreateSampleBeatmapInfo() =>
|
|
|
|
new BeatmapInfo { Metadata = new BeatmapMetadata { Title = "Test Title", Artist = "Test Artist", ID = RNG.Next(0, 1000000) } };
|
|
|
|
|
2019-07-29 22:23:25 +00:00
|
|
|
protected override ITestSceneTestRunner CreateRunner() => new TournamentTestSceneTestRunner();
|
|
|
|
|
|
|
|
public class TournamentTestSceneTestRunner : TournamentGameBase, ITestSceneTestRunner
|
|
|
|
{
|
|
|
|
private TestSceneTestRunner.TestRunner runner;
|
|
|
|
|
|
|
|
protected override void LoadAsyncComplete()
|
|
|
|
{
|
2021-02-12 16:10:39 +00:00
|
|
|
BracketLoadTask.ContinueWith(_ => Schedule(() =>
|
|
|
|
{
|
|
|
|
// this has to be run here rather than LoadComplete because
|
|
|
|
// TestScene.cs is checking the IsLoaded state (on another thread) and expects
|
|
|
|
// the runner to be loaded at that point.
|
|
|
|
Add(runner = new TestSceneTestRunner.TestRunner());
|
|
|
|
}));
|
2019-07-29 22:23:25 +00:00
|
|
|
}
|
|
|
|
|
2021-02-15 06:31:51 +00:00
|
|
|
public void RunTestBlocking(TestScene test)
|
|
|
|
{
|
|
|
|
while (runner?.IsLoaded != true && Host.ExecutionState == ExecutionState.Running)
|
|
|
|
Thread.Sleep(10);
|
|
|
|
|
|
|
|
runner?.RunTestBlocking(test);
|
|
|
|
}
|
2019-07-29 22:23:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|