-
Notifications
You must be signed in to change notification settings - Fork 1
/
TournamentTestScene.cs
197 lines (178 loc) · 7.38 KB
/
TournamentTestScene.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// 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 System.Linq;
using System.Threading;
using osu.Framework.Allocation;
using osu.Framework.Platform;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Overlays;
using osu.Game.Rulesets;
using osu.Game.Tests.Visual;
using osu.Game.Tournament.IO;
using osu.Game.Tournament.IPC;
using osu.Game.Tournament.Models;
namespace osu.Game.Tournament.Tests
{
public abstract partial class TournamentTestScene : OsuManualInputManagerTestScene
{
[Cached(typeof(IDialogOverlay))]
protected readonly DialogOverlay DialogOverlay = new DialogOverlay { Depth = float.MinValue };
[Cached]
protected LadderInfo Ladder { get; private set; } = new LadderInfo();
[Cached]
protected MatchIPCInfo IPCInfo { get; private set; } = new MatchIPCInfo();
[Resolved]
private RulesetStore rulesetStore { get; set; } = null!;
private TournamentMatch match = null!;
[BackgroundDependencyLoader]
private void load(TournamentStorage storage)
{
Ladder.Ruleset.Value ??= rulesetStore.AvailableRulesets.First();
match = CreateSampleMatch();
Ladder.Rounds.Add(match.Round.Value!);
Ladder.Matches.Add(match);
Ladder.Teams.Add(match.Team1.Value!);
Ladder.Teams.Add(match.Team2.Value!);
Ruleset.BindTo(Ladder.Ruleset);
Dependencies.CacheAs(new StableInfo(storage));
Add(DialogOverlay);
}
[SetUpSteps]
public virtual void SetUpSteps()
{
AddStep("set current match", () => Ladder.CurrentMatch.Value = match);
}
public static TournamentMatch CreateSampleMatch() => new TournamentMatch
{
Team1 =
{
Value = new TournamentTeam
{
Acronym = { Value = "JPN" },
FlagName = { Value = "JP" },
FullName = { Value = "Japan" },
LastYearPlacing = { Value = 10 },
Seed = { Value = "#12" },
SeedingResults =
{
new SeedingResult
{
Mod = { Value = "NM" },
Seed = { Value = 10 },
Beatmaps =
{
new SeedingBeatmap
{
Beatmap = CreateSampleBeatmap(),
Score = 12345672,
Seed = { Value = 24 },
},
new SeedingBeatmap
{
Beatmap = CreateSampleBeatmap(),
Score = 1234567,
Seed = { Value = 12 },
},
new SeedingBeatmap
{
Beatmap = CreateSampleBeatmap(),
Score = 1234567,
Seed = { Value = 16 },
}
}
},
new SeedingResult
{
Mod = { Value = "DT" },
Seed = { Value = 5 },
Beatmaps =
{
new SeedingBeatmap
{
Beatmap = CreateSampleBeatmap(),
Score = 234567,
Seed = { Value = 3 },
},
new SeedingBeatmap
{
Beatmap = CreateSampleBeatmap(),
Score = 234567,
Seed = { Value = 6 },
},
new SeedingBeatmap
{
Beatmap = CreateSampleBeatmap(),
Score = 234567,
Seed = { Value = 12 },
}
}
}
},
Players =
{
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 },
}
}
},
Team2 =
{
Value = new TournamentTeam
{
Acronym = { Value = "USA" },
FlagName = { Value = "US" },
FullName = { Value = "United States" },
Seed = { Value = "#3" },
Players =
{
new TournamentUser { Username = "Hello" },
new TournamentUser { Username = "Hello" },
new TournamentUser { Username = "Hello" },
new TournamentUser { Username = "Hello" },
new TournamentUser { Username = "Hello" },
}
}
},
Round =
{
Value = new TournamentRound { Name = { Value = "Quarterfinals" } },
}
};
public static TournamentBeatmap CreateSampleBeatmap() =>
new TournamentBeatmap
{
Metadata = new BeatmapMetadata
{
Title = "Test Title",
Artist = "Test Artist",
},
OnlineID = RNG.Next(0, 1000000),
};
protected override ITestSceneTestRunner CreateRunner() => new TournamentTestSceneTestRunner();
public partial class TournamentTestSceneTestRunner : TournamentGameBase, ITestSceneTestRunner
{
private TestSceneTestRunner.TestRunner runner = null!;
protected override void LoadAsyncComplete()
{
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());
}));
}
public void RunTestBlocking(TestScene test)
{
while (runner?.IsLoaded != true && Host.ExecutionState == ExecutionState.Running)
Thread.Sleep(10);
runner?.RunTestBlocking(test);
}
}
}
}