1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:27:29 +08:00

Fix tournament client silently failing on error during parsing

This commit is contained in:
Dean Herbert 2021-10-25 16:46:07 +09:00
parent 7c99193ada
commit 7111f58bfe
2 changed files with 142 additions and 116 deletions

View File

@ -12,6 +12,7 @@ using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Handlers.Mouse;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Game.Graphics;
using osu.Game.Graphics.Cursor;
@ -60,72 +61,89 @@ namespace osu.Game.Tournament
loadingSpinner.Show();
BracketLoadTask.ContinueWith(_ => LoadComponentsAsync(new[]
BracketLoadTask.ContinueWith(t =>
{
new Container
if (t.IsFaulted)
{
CornerRadius = 10,
Depth = float.MinValue,
Position = new Vector2(5),
Masking = true,
AutoSizeAxes = Axes.Both,
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Children = new Drawable[]
Schedule(() =>
{
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()
loadingSpinner.Hide();
loadingSpinner.Expire();
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."));
});
return;
}
}, drawables =>
{
loadingSpinner.Hide();
loadingSpinner.Expire();
AddRange(drawables);
windowSize.BindValueChanged(size => ScheduleAfterChildren(() =>
LoadComponentsAsync(new[]
{
var minWidth = (int)(size.NewValue.Height / 768f * TournamentSceneManager.REQUIRED_WIDTH) - 1;
heightWarning.Alpha = size.NewValue.Width < minWidth ? 1 : 0;
}), true);
windowMode.BindValueChanged(mode => ScheduleAfterChildren(() =>
new Container
{
CornerRadius = 10,
Depth = float.MinValue,
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;
}), true);
}));
loadingSpinner.Hide();
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);
});
});
}
}
}

View File

@ -58,75 +58,83 @@ namespace osu.Game.Tournament
private void readBracket()
{
if (storage.Exists(bracket_filename))
try
{
using (Stream stream = storage.GetStream(bracket_filename, FileAccess.Read, FileMode.Open))
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)
if (storage.Exists(bracket_filename))
{
conditional.Team1.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == conditional.Team1Acronym);
conditional.Team2.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == conditional.Team2Acronym);
conditional.Round.Value = match.Round.Value;
using (Stream stream = storage.GetStream(bracket_filename, FileAccess.Read, FileMode.Open))
using (var sr = new StreamReader(stream))
ladder = JsonConvert.DeserializeObject<LadderInfo>(sr.ReadToEnd(), new JsonPointConverter());
}
}
// 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);
ladder ??= new LadderInfo();
if (src == null)
continue;
ladder.Ruleset.Value = RulesetStore.GetRuleset(ladder.Ruleset.Value?.ShortName)
?? RulesetStore.AvailableRulesets.First();
if (dest != null)
bool addedInfo = false;
// assign teams
foreach (var match in ladder.Matches)
{
if (pair.Losers)
src.LosersProgression.Value = dest;
else
src.Progression.Value = dest;
}
}
match.Team1.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == match.Team1Acronym);
match.Team2.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == match.Team2Acronym);
// 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)
foreach (var conditional in match.ConditionalMatches)
{
found.Round.Value = round;
if (round.StartDate.Value > found.Date.Value)
found.Date.Value = round.StartDate.Value;
conditional.Team1.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == conditional.Team1Acronym);
conditional.Team2.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == conditional.Team2Acronym);
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(() =>
{