mirror of
https://github.com/ppy/osu.git
synced 2024-12-13 08:32:57 +08:00
Allow tests to run custom game
This commit is contained in:
parent
49d3beac19
commit
5a4292717f
@ -1,91 +1,16 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System.IO;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Framework.Platform;
|
|
||||||
using osu.Game.Beatmaps;
|
|
||||||
using osu.Game.Graphics.UserInterface;
|
|
||||||
using osu.Game.Online.API;
|
|
||||||
using osu.Game.Online.API.Requests;
|
|
||||||
using osu.Game.Rulesets;
|
|
||||||
using osu.Game.Tests.Visual;
|
using osu.Game.Tests.Visual;
|
||||||
using osu.Game.Tournament.Screens.Ladder.Components;
|
using osu.Game.Tournament.Screens.Ladder.Components;
|
||||||
|
|
||||||
namespace osu.Game.Tournament.Tests
|
namespace osu.Game.Tournament.Tests
|
||||||
{
|
{
|
||||||
public abstract class LadderTestCase : OsuTestCase
|
public class LadderTestCase : OsuTestCase
|
||||||
{
|
{
|
||||||
private const string bracket_filename = "bracket.json";
|
|
||||||
|
|
||||||
protected LadderInfo Ladder;
|
|
||||||
private Storage storage;
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private APIAccess api { get; set; }
|
protected LadderInfo Ladder { get; set; }
|
||||||
|
|
||||||
[Resolved]
|
|
||||||
private RulesetStore rulesets { get; set; }
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load(Storage storage)
|
|
||||||
{
|
|
||||||
this.storage = storage;
|
|
||||||
|
|
||||||
string content = null;
|
|
||||||
if (storage.Exists(bracket_filename))
|
|
||||||
{
|
|
||||||
using (Stream stream = storage.GetStream(bracket_filename, FileAccess.Read, FileMode.Open))
|
|
||||||
using (var sr = new StreamReader(stream))
|
|
||||||
content = sr.ReadToEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
Ladder = content != null ? JsonConvert.DeserializeObject<LadderInfo>(content) : new LadderInfo();
|
|
||||||
|
|
||||||
bool addedInfo = false;
|
|
||||||
|
|
||||||
foreach (var g in Ladder.Groupings)
|
|
||||||
foreach (var b in g.Beatmaps)
|
|
||||||
{
|
|
||||||
if (b.BeatmapInfo == null)
|
|
||||||
{
|
|
||||||
var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = b.ID });
|
|
||||||
req.Success += i => b.BeatmapInfo = i.ToBeatmap(rulesets);
|
|
||||||
req.Perform(api);
|
|
||||||
|
|
||||||
addedInfo = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (addedInfo)
|
|
||||||
SaveChanges();
|
|
||||||
|
|
||||||
Add(new OsuButton
|
|
||||||
{
|
|
||||||
Text = "Save Changes",
|
|
||||||
Width = 140,
|
|
||||||
Height = 50,
|
|
||||||
Anchor = Anchor.BottomRight,
|
|
||||||
Origin = Anchor.BottomRight,
|
|
||||||
Padding = new MarginPadding(10),
|
|
||||||
Action = SaveChanges,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void SaveChanges()
|
|
||||||
{
|
|
||||||
using (var stream = storage.GetStream(bracket_filename, FileAccess.Write, FileMode.Create))
|
|
||||||
using (var sw = new StreamWriter(stream))
|
|
||||||
{
|
|
||||||
sw.Write(JsonConvert.SerializeObject(Ladder,
|
|
||||||
new JsonSerializerSettings
|
|
||||||
{
|
|
||||||
NullValueHandling = NullValueHandling.Ignore,
|
|
||||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,10 +47,10 @@ namespace osu.Game.Tournament.Tests
|
|||||||
items.Add(new GroupingRow(g));
|
items.Add(new GroupingRow(g));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void SaveChanges()
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
Ladder.Groupings = items.Children.Select(c => c.Grouping).ToList();
|
Ladder.Groupings = items.Children.Select(c => c.Grouping).ToList();
|
||||||
base.SaveChanges();
|
base.Dispose(isDisposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addNew() => items.Add(new GroupingRow(new TournamentGrouping()));
|
private void addNew() => items.Add(new GroupingRow(new TournamentGrouping()));
|
||||||
|
@ -22,10 +22,10 @@ namespace osu.Game.Tournament.Tests
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void SaveChanges()
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
|
base.Dispose(isDisposing);
|
||||||
Ladder = manager.CreateInfo();
|
Ladder = manager.CreateInfo();
|
||||||
base.SaveChanges();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,12 @@
|
|||||||
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
|
using osu.Game.Tests.Visual;
|
||||||
using osu.Game.Tournament.Screens;
|
using osu.Game.Tournament.Screens;
|
||||||
|
|
||||||
namespace osu.Game.Tournament.Tests
|
namespace osu.Game.Tournament.Tests
|
||||||
{
|
{
|
||||||
public class TestCaseSceneManager : LadderTestCase
|
public class TestCaseSceneManager : OsuTestCase
|
||||||
{
|
{
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(Storage storage)
|
private void load(Storage storage)
|
||||||
|
27
osu.Game.Tournament.Tests/TournamentTestBrowser.cs
Normal file
27
osu.Game.Tournament.Tests/TournamentTestBrowser.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Screens.Backgrounds;
|
||||||
|
|
||||||
|
namespace osu.Game.Tournament.Tests
|
||||||
|
{
|
||||||
|
public class TournamentTestBrowser : TournamentGame
|
||||||
|
{
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
LoadComponentAsync(new BackgroundScreenDefault
|
||||||
|
{
|
||||||
|
Colour = OsuColour.Gray(0.5f),
|
||||||
|
Depth = 10
|
||||||
|
}, AddInternal);
|
||||||
|
|
||||||
|
// Have to construct this here, rather than in the constructor, because
|
||||||
|
// we depend on some dependencies to be loaded within OsuGameBase.load().
|
||||||
|
Add(new TestBrowser());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
22
osu.Game.Tournament.Tests/TournamentTestRunner.cs
Normal file
22
osu.Game.Tournament.Tests/TournamentTestRunner.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using osu.Framework;
|
||||||
|
using osu.Framework.Platform;
|
||||||
|
|
||||||
|
namespace osu.Game.Tournament.Tests
|
||||||
|
{
|
||||||
|
public static class TournamentTestRunner
|
||||||
|
{
|
||||||
|
[STAThread]
|
||||||
|
public static int Main(string[] args)
|
||||||
|
{
|
||||||
|
using (DesktopGameHost host = Host.GetSuitableHost(@"osu", true))
|
||||||
|
{
|
||||||
|
host.Run(new TournamentTestBrowser());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,8 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<Import Project="..\osu.TestProject.props" />
|
<Import Project="..\osu.TestProject.props" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<StartupObject>osu.Game.Tournament.Tests.TournamentTestRunner</StartupObject>
|
||||||
|
</PropertyGroup>
|
||||||
<ItemGroup Label="Package References">
|
<ItemGroup Label="Package References">
|
||||||
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
|
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
|
||||||
|
Loading…
Reference in New Issue
Block a user