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;
|
2022-06-17 22:34:09 +00:00
|
|
|
using osu.Game.Beatmaps;
|
2023-07-17 06:59:15 +00:00
|
|
|
using osu.Game.Overlays;
|
2020-06-24 07:57:17 +00:00
|
|
|
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;
|
2019-07-29 22:23:25 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Tests
|
|
|
|
{
|
2023-07-17 06:59:15 +00:00
|
|
|
public abstract partial class TournamentTestScene : OsuManualInputManagerTestScene
|
2019-07-29 22:23:25 +00:00
|
|
|
{
|
2023-07-25 09:31:28 +00:00
|
|
|
[Cached(typeof(IDialogOverlay))]
|
|
|
|
protected readonly DialogOverlay DialogOverlay = new DialogOverlay { Depth = float.MinValue };
|
2021-08-28 07:22:01 +00:00
|
|
|
|
2020-06-24 07:57:17 +00:00
|
|
|
[Cached]
|
|
|
|
protected LadderInfo Ladder { get; private set; } = new LadderInfo();
|
|
|
|
|
|
|
|
[Cached]
|
|
|
|
protected MatchIPCInfo IPCInfo { get; private set; } = new MatchIPCInfo();
|
|
|
|
|
2023-07-24 09:22:32 +00:00
|
|
|
[Resolved]
|
|
|
|
private RulesetStore rulesetStore { get; set; } = null!;
|
|
|
|
|
|
|
|
private TournamentMatch match = null!;
|
|
|
|
|
2020-06-24 07:57:17 +00:00
|
|
|
[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
|
|
|
|
2023-08-09 15:20:37 +00:00
|
|
|
Ladder.Rounds.Add(match.Round.Value!);
|
2020-06-24 07:57:17 +00:00
|
|
|
Ladder.Matches.Add(match);
|
2023-08-09 15:20:37 +00:00
|
|
|
Ladder.Teams.Add(match.Team1.Value!);
|
|
|
|
Ladder.Teams.Add(match.Team2.Value!);
|
2020-06-24 07:57:17 +00:00
|
|
|
|
2020-06-24 08:57:07 +00:00
|
|
|
Ruleset.BindTo(Ladder.Ruleset);
|
|
|
|
Dependencies.CacheAs(new StableInfo(storage));
|
2023-07-17 06:59:15 +00:00
|
|
|
|
2023-07-25 09:31:28 +00:00
|
|
|
Add(DialogOverlay);
|
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 },
|
2023-10-28 05:29:46 +00:00
|
|
|
Seed = { Value = "#12" },
|
2020-06-24 07:57:17 +00:00
|
|
|
SeedingResults =
|
|
|
|
{
|
|
|
|
new SeedingResult
|
|
|
|
{
|
|
|
|
Mod = { Value = "NM" },
|
|
|
|
Seed = { Value = 10 },
|
|
|
|
Beatmaps =
|
|
|
|
{
|
|
|
|
new SeedingBeatmap
|
|
|
|
{
|
2021-10-27 09:25:23 +00:00
|
|
|
Beatmap = CreateSampleBeatmap(),
|
2020-06-24 07:57:17 +00:00
|
|
|
Score = 12345672,
|
|
|
|
Seed = { Value = 24 },
|
|
|
|
},
|
|
|
|
new SeedingBeatmap
|
|
|
|
{
|
2021-10-27 09:25:23 +00:00
|
|
|
Beatmap = CreateSampleBeatmap(),
|
2020-06-24 07:57:17 +00:00
|
|
|
Score = 1234567,
|
|
|
|
Seed = { Value = 12 },
|
|
|
|
},
|
|
|
|
new SeedingBeatmap
|
|
|
|
{
|
2021-10-27 09:25:23 +00:00
|
|
|
Beatmap = CreateSampleBeatmap(),
|
2020-06-24 07:57:17 +00:00
|
|
|
Score = 1234567,
|
|
|
|
Seed = { Value = 16 },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new SeedingResult
|
|
|
|
{
|
|
|
|
Mod = { Value = "DT" },
|
|
|
|
Seed = { Value = 5 },
|
|
|
|
Beatmaps =
|
|
|
|
{
|
|
|
|
new SeedingBeatmap
|
|
|
|
{
|
2021-10-27 09:25:23 +00:00
|
|
|
Beatmap = CreateSampleBeatmap(),
|
2020-06-24 07:57:17 +00:00
|
|
|
Score = 234567,
|
|
|
|
Seed = { Value = 3 },
|
|
|
|
},
|
|
|
|
new SeedingBeatmap
|
|
|
|
{
|
2021-10-27 09:25:23 +00:00
|
|
|
Beatmap = CreateSampleBeatmap(),
|
2020-06-24 07:57:17 +00:00
|
|
|
Score = 234567,
|
|
|
|
Seed = { Value = 6 },
|
|
|
|
},
|
|
|
|
new SeedingBeatmap
|
|
|
|
{
|
2021-10-27 09:25:23 +00:00
|
|
|
Beatmap = CreateSampleBeatmap(),
|
2020-06-24 07:57:17 +00:00
|
|
|
Score = 234567,
|
|
|
|
Seed = { Value = 12 },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Players =
|
|
|
|
{
|
2022-06-17 23:33:26 +00:00
|
|
|
new TournamentUser { Username = "Hello", Rank = 12 },
|
|
|
|
new TournamentUser { Username = "Hello", Rank = 16 },
|
|
|
|
new TournamentUser { Username = "Hello", Rank = 20 },
|
|
|
|
new TournamentUser { Username = "Hello", Rank = 24 },
|
|
|
|
new TournamentUser { Username = "Hello", Rank = 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" },
|
2023-10-28 05:29:46 +00:00
|
|
|
Seed = { Value = "#3" },
|
2020-06-24 07:57:17 +00:00
|
|
|
Players =
|
|
|
|
{
|
2022-06-17 23:33:26 +00:00
|
|
|
new TournamentUser { Username = "Hello" },
|
|
|
|
new TournamentUser { Username = "Hello" },
|
|
|
|
new TournamentUser { Username = "Hello" },
|
|
|
|
new TournamentUser { Username = "Hello" },
|
|
|
|
new TournamentUser { Username = "Hello" },
|
2020-06-24 07:57:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Round =
|
|
|
|
{
|
2023-07-25 11:50:55 +00:00
|
|
|
Value = new TournamentRound { Name = { Value = "Quarterfinals" } },
|
2020-06-24 07:57:17 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-06-17 22:34:09 +00:00
|
|
|
public static TournamentBeatmap CreateSampleBeatmap() =>
|
|
|
|
new TournamentBeatmap
|
2021-10-25 07:45:46 +00:00
|
|
|
{
|
2022-06-17 22:34:09 +00:00
|
|
|
Metadata = new BeatmapMetadata
|
2021-10-25 07:45:46 +00:00
|
|
|
{
|
|
|
|
Title = "Test Title",
|
|
|
|
Artist = "Test Artist",
|
|
|
|
},
|
2021-10-27 08:22:23 +00:00
|
|
|
OnlineID = RNG.Next(0, 1000000),
|
2021-10-25 07:45:46 +00:00
|
|
|
};
|
2020-06-24 07:57:17 +00:00
|
|
|
|
2019-07-29 22:23:25 +00:00
|
|
|
protected override ITestSceneTestRunner CreateRunner() => new TournamentTestSceneTestRunner();
|
|
|
|
|
|
|
|
public partial class TournamentTestSceneTestRunner : TournamentGameBase, ITestSceneTestRunner
|
|
|
|
{
|
2023-07-24 09:22:32 +00:00
|
|
|
private TestSceneTestRunner.TestRunner runner = null!;
|
2019-07-29 22:23:25 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|