mirror of
https://github.com/ppy/osu.git
synced 2025-01-26 20:23:00 +08:00
Merge branch 'tournament-ladder-parsing' into move-online-beatmap-metrics
This commit is contained in:
commit
4dafe666ba
@ -0,0 +1,65 @@
|
|||||||
|
// 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 Newtonsoft.Json;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Game.Tournament.Models;
|
||||||
|
|
||||||
|
namespace osu.Game.Tournament.Tests.NonVisual
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class LadderInfoSerialisationTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void TestDeserialise()
|
||||||
|
{
|
||||||
|
var ladder = createSampleLadder();
|
||||||
|
string serialised = JsonConvert.SerializeObject(ladder);
|
||||||
|
|
||||||
|
JsonConvert.DeserializeObject<LadderInfo>(serialised, new JsonPointConverter());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestSerialise()
|
||||||
|
{
|
||||||
|
var ladder = createSampleLadder();
|
||||||
|
JsonConvert.SerializeObject(ladder);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static LadderInfo createSampleLadder()
|
||||||
|
{
|
||||||
|
var match = TournamentTestScene.CreateSampleMatch();
|
||||||
|
|
||||||
|
return new LadderInfo
|
||||||
|
{
|
||||||
|
PlayersPerTeam = { Value = 4 },
|
||||||
|
Teams =
|
||||||
|
{
|
||||||
|
match.Team1.Value,
|
||||||
|
match.Team2.Value,
|
||||||
|
},
|
||||||
|
Rounds =
|
||||||
|
{
|
||||||
|
new TournamentRound
|
||||||
|
{
|
||||||
|
Beatmaps =
|
||||||
|
{
|
||||||
|
new RoundBeatmap { BeatmapInfo = TournamentTestScene.CreateSampleBeatmapInfo() },
|
||||||
|
new RoundBeatmap { BeatmapInfo = TournamentTestScene.CreateSampleBeatmapInfo() },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
Matches =
|
||||||
|
{
|
||||||
|
match,
|
||||||
|
},
|
||||||
|
Progressions =
|
||||||
|
{
|
||||||
|
new TournamentProgression(1, 2),
|
||||||
|
new TournamentProgression(1, 3, true),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,7 @@ using osu.Framework.Platform;
|
|||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Tests.Visual;
|
using osu.Game.Tests.Visual;
|
||||||
using osu.Game.Tournament.IO;
|
using osu.Game.Tournament.IO;
|
||||||
@ -152,7 +153,16 @@ namespace osu.Game.Tournament.Tests
|
|||||||
};
|
};
|
||||||
|
|
||||||
public static BeatmapInfo CreateSampleBeatmapInfo() =>
|
public static BeatmapInfo CreateSampleBeatmapInfo() =>
|
||||||
new BeatmapInfo { Metadata = new BeatmapMetadata { Title = "Test Title", Artist = "Test Artist", ID = RNG.Next(0, 1000000) } };
|
new BeatmapInfo
|
||||||
|
{
|
||||||
|
Metadata = new BeatmapMetadata
|
||||||
|
{
|
||||||
|
Title = "Test Title",
|
||||||
|
Artist = "Test Artist",
|
||||||
|
ID = RNG.Next(0, 1000000)
|
||||||
|
},
|
||||||
|
OnlineInfo = new BeatmapOnlineInfo(),
|
||||||
|
};
|
||||||
|
|
||||||
protected override ITestSceneTestRunner CreateRunner() => new TournamentTestSceneTestRunner();
|
protected override ITestSceneTestRunner CreateRunner() => new TournamentTestSceneTestRunner();
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ using osu.Framework.Graphics.Colour;
|
|||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Input.Handlers.Mouse;
|
using osu.Framework.Input.Handlers.Mouse;
|
||||||
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Cursor;
|
using osu.Game.Graphics.Cursor;
|
||||||
@ -60,72 +61,89 @@ namespace osu.Game.Tournament
|
|||||||
|
|
||||||
loadingSpinner.Show();
|
loadingSpinner.Show();
|
||||||
|
|
||||||
BracketLoadTask.ContinueWith(_ => LoadComponentsAsync(new[]
|
BracketLoadTask.ContinueWith(t =>
|
||||||
{
|
{
|
||||||
new Container
|
if (t.IsFaulted)
|
||||||
{
|
{
|
||||||
CornerRadius = 10,
|
Schedule(() =>
|
||||||
Depth = float.MinValue,
|
|
||||||
Position = new Vector2(5),
|
|
||||||
Masking = true,
|
|
||||||
AutoSizeAxes = Axes.Both,
|
|
||||||
Anchor = Anchor.BottomRight,
|
|
||||||
Origin = Anchor.BottomRight,
|
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
{
|
||||||
new Box
|
loadingSpinner.Hide();
|
||||||
{
|
loadingSpinner.Expire();
|
||||||
Colour = OsuColour.Gray(0.2f),
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
Logger.Error(t.Exception, "Couldn't load bracket with error");
|
||||||
},
|
Add(new WarningBox("Your bracket.json file could not be parsed. Please check runtime.log for more details."));
|
||||||
new TourneyButton
|
});
|
||||||
{
|
|
||||||
Text = "Save Changes",
|
return;
|
||||||
Width = 140,
|
|
||||||
Height = 50,
|
|
||||||
Padding = new MarginPadding
|
|
||||||
{
|
|
||||||
Top = 10,
|
|
||||||
Left = 10,
|
|
||||||
},
|
|
||||||
Margin = new MarginPadding
|
|
||||||
{
|
|
||||||
Right = 10,
|
|
||||||
Bottom = 10,
|
|
||||||
},
|
|
||||||
Action = SaveChanges,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
heightWarning = new WarningBox("Please make the window wider")
|
|
||||||
{
|
|
||||||
Anchor = Anchor.BottomCentre,
|
|
||||||
Origin = Anchor.BottomCentre,
|
|
||||||
Margin = new MarginPadding(20),
|
|
||||||
},
|
|
||||||
new OsuContextMenuContainer
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Child = new TournamentSceneManager()
|
|
||||||
}
|
}
|
||||||
}, drawables =>
|
|
||||||
{
|
|
||||||
loadingSpinner.Hide();
|
|
||||||
loadingSpinner.Expire();
|
|
||||||
|
|
||||||
AddRange(drawables);
|
LoadComponentsAsync(new[]
|
||||||
|
|
||||||
windowSize.BindValueChanged(size => ScheduleAfterChildren(() =>
|
|
||||||
{
|
{
|
||||||
var minWidth = (int)(size.NewValue.Height / 768f * TournamentSceneManager.REQUIRED_WIDTH) - 1;
|
new Container
|
||||||
heightWarning.Alpha = size.NewValue.Width < minWidth ? 1 : 0;
|
{
|
||||||
}), true);
|
CornerRadius = 10,
|
||||||
|
Depth = float.MinValue,
|
||||||
windowMode.BindValueChanged(mode => ScheduleAfterChildren(() =>
|
Position = new Vector2(5),
|
||||||
|
Masking = true,
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Anchor = Anchor.BottomRight,
|
||||||
|
Origin = Anchor.BottomRight,
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new Box
|
||||||
|
{
|
||||||
|
Colour = OsuColour.Gray(0.2f),
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
},
|
||||||
|
new TourneyButton
|
||||||
|
{
|
||||||
|
Text = "Save Changes",
|
||||||
|
Width = 140,
|
||||||
|
Height = 50,
|
||||||
|
Padding = new MarginPadding
|
||||||
|
{
|
||||||
|
Top = 10,
|
||||||
|
Left = 10,
|
||||||
|
},
|
||||||
|
Margin = new MarginPadding
|
||||||
|
{
|
||||||
|
Right = 10,
|
||||||
|
Bottom = 10,
|
||||||
|
},
|
||||||
|
Action = SaveChanges,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
heightWarning = new WarningBox("Please make the window wider")
|
||||||
|
{
|
||||||
|
Anchor = Anchor.BottomCentre,
|
||||||
|
Origin = Anchor.BottomCentre,
|
||||||
|
Margin = new MarginPadding(20),
|
||||||
|
},
|
||||||
|
new OsuContextMenuContainer
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Child = new TournamentSceneManager()
|
||||||
|
}
|
||||||
|
}, drawables =>
|
||||||
{
|
{
|
||||||
windowMode.Value = WindowMode.Windowed;
|
loadingSpinner.Hide();
|
||||||
}), true);
|
loadingSpinner.Expire();
|
||||||
}));
|
|
||||||
|
AddRange(drawables);
|
||||||
|
|
||||||
|
windowSize.BindValueChanged(size => ScheduleAfterChildren(() =>
|
||||||
|
{
|
||||||
|
var minWidth = (int)(size.NewValue.Height / 768f * TournamentSceneManager.REQUIRED_WIDTH) - 1;
|
||||||
|
heightWarning.Alpha = size.NewValue.Width < minWidth ? 1 : 0;
|
||||||
|
}), true);
|
||||||
|
|
||||||
|
windowMode.BindValueChanged(mode => ScheduleAfterChildren(() =>
|
||||||
|
{
|
||||||
|
windowMode.Value = WindowMode.Windowed;
|
||||||
|
}), true);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,75 +58,83 @@ namespace osu.Game.Tournament
|
|||||||
|
|
||||||
private void readBracket()
|
private void readBracket()
|
||||||
{
|
{
|
||||||
if (storage.Exists(bracket_filename))
|
try
|
||||||
{
|
{
|
||||||
using (Stream stream = storage.GetStream(bracket_filename, FileAccess.Read, FileMode.Open))
|
if (storage.Exists(bracket_filename))
|
||||||
using (var sr = new StreamReader(stream))
|
|
||||||
ladder = JsonConvert.DeserializeObject<LadderInfo>(sr.ReadToEnd(), new JsonPointConverter());
|
|
||||||
}
|
|
||||||
|
|
||||||
ladder ??= new LadderInfo();
|
|
||||||
|
|
||||||
ladder.Ruleset.Value = RulesetStore.GetRuleset(ladder.Ruleset.Value?.ShortName)
|
|
||||||
?? RulesetStore.AvailableRulesets.First();
|
|
||||||
|
|
||||||
bool addedInfo = false;
|
|
||||||
|
|
||||||
// assign teams
|
|
||||||
foreach (var match in ladder.Matches)
|
|
||||||
{
|
|
||||||
match.Team1.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == match.Team1Acronym);
|
|
||||||
match.Team2.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == match.Team2Acronym);
|
|
||||||
|
|
||||||
foreach (var conditional in match.ConditionalMatches)
|
|
||||||
{
|
{
|
||||||
conditional.Team1.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == conditional.Team1Acronym);
|
using (Stream stream = storage.GetStream(bracket_filename, FileAccess.Read, FileMode.Open))
|
||||||
conditional.Team2.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == conditional.Team2Acronym);
|
using (var sr = new StreamReader(stream))
|
||||||
conditional.Round.Value = match.Round.Value;
|
ladder = JsonConvert.DeserializeObject<LadderInfo>(sr.ReadToEnd(), new JsonPointConverter());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// assign progressions
|
ladder ??= new LadderInfo();
|
||||||
foreach (var pair in ladder.Progressions)
|
|
||||||
{
|
|
||||||
var src = ladder.Matches.FirstOrDefault(p => p.ID == pair.SourceID);
|
|
||||||
var dest = ladder.Matches.FirstOrDefault(p => p.ID == pair.TargetID);
|
|
||||||
|
|
||||||
if (src == null)
|
ladder.Ruleset.Value = RulesetStore.GetRuleset(ladder.Ruleset.Value?.ShortName)
|
||||||
continue;
|
?? RulesetStore.AvailableRulesets.First();
|
||||||
|
|
||||||
if (dest != null)
|
bool addedInfo = false;
|
||||||
|
|
||||||
|
// assign teams
|
||||||
|
foreach (var match in ladder.Matches)
|
||||||
{
|
{
|
||||||
if (pair.Losers)
|
match.Team1.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == match.Team1Acronym);
|
||||||
src.LosersProgression.Value = dest;
|
match.Team2.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == match.Team2Acronym);
|
||||||
else
|
|
||||||
src.Progression.Value = dest;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// link matches to rounds
|
foreach (var conditional in match.ConditionalMatches)
|
||||||
foreach (var round in ladder.Rounds)
|
|
||||||
{
|
|
||||||
foreach (var id in round.Matches)
|
|
||||||
{
|
|
||||||
var found = ladder.Matches.FirstOrDefault(p => p.ID == id);
|
|
||||||
|
|
||||||
if (found != null)
|
|
||||||
{
|
{
|
||||||
found.Round.Value = round;
|
conditional.Team1.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == conditional.Team1Acronym);
|
||||||
if (round.StartDate.Value > found.Date.Value)
|
conditional.Team2.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == conditional.Team2Acronym);
|
||||||
found.Date.Value = round.StartDate.Value;
|
conditional.Round.Value = match.Round.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// assign progressions
|
||||||
|
foreach (var pair in ladder.Progressions)
|
||||||
|
{
|
||||||
|
var src = ladder.Matches.FirstOrDefault(p => p.ID == pair.SourceID);
|
||||||
|
var dest = ladder.Matches.FirstOrDefault(p => p.ID == pair.TargetID);
|
||||||
|
|
||||||
|
if (src == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (dest != null)
|
||||||
|
{
|
||||||
|
if (pair.Losers)
|
||||||
|
src.LosersProgression.Value = dest;
|
||||||
|
else
|
||||||
|
src.Progression.Value = dest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// link matches to rounds
|
||||||
|
foreach (var round in ladder.Rounds)
|
||||||
|
{
|
||||||
|
foreach (var id in round.Matches)
|
||||||
|
{
|
||||||
|
var found = ladder.Matches.FirstOrDefault(p => p.ID == id);
|
||||||
|
|
||||||
|
if (found != null)
|
||||||
|
{
|
||||||
|
found.Round.Value = round;
|
||||||
|
if (round.StartDate.Value > found.Date.Value)
|
||||||
|
found.Date.Value = round.StartDate.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addedInfo |= addPlayers();
|
||||||
|
addedInfo |= addBeatmaps();
|
||||||
|
|
||||||
|
if (addedInfo)
|
||||||
|
SaveChanges();
|
||||||
|
|
||||||
|
ladder.CurrentMatch.Value = ladder.Matches.FirstOrDefault(p => p.Current.Value);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
taskCompletionSource.SetException(e);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
addedInfo |= addPlayers();
|
|
||||||
addedInfo |= addBeatmaps();
|
|
||||||
|
|
||||||
if (addedInfo)
|
|
||||||
SaveChanges();
|
|
||||||
|
|
||||||
ladder.CurrentMatch.Value = ladder.Matches.FirstOrDefault(p => p.Current.Value);
|
|
||||||
|
|
||||||
Schedule(() =>
|
Schedule(() =>
|
||||||
{
|
{
|
||||||
|
@ -237,7 +237,7 @@ namespace osu.Game.Tournament
|
|||||||
{
|
{
|
||||||
Type = type;
|
Type = type;
|
||||||
BackgroundColour = OsuColour.Gray(0.2f);
|
BackgroundColour = OsuColour.Gray(0.2f);
|
||||||
Action = () => RequestSelection(type);
|
Action = () => RequestSelection?.Invoke(type);
|
||||||
|
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user