From baefcb9deb52a6c3336e173af6cf1fd6217934bc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 25 Sep 2018 03:14:30 +0900 Subject: [PATCH] Simplify team storage --- .../TestCaseLadderManager.cs | 5 +---- .../Ladder/Components/DrawableMatchPairing.cs | 4 ++-- .../Ladder/Components/DrawableMatchTeam.cs | 21 ++++--------------- .../Screens/Ladder/Components/LadderInfo.cs | 2 ++ .../Screens/Ladder/Components/MatchPairing.cs | 11 ++++++++-- .../Screens/Ladder/LadderManager.cs | 13 ++++++++++-- 6 files changed, 29 insertions(+), 27 deletions(-) diff --git a/osu.Game.Tournament.Tests/TestCaseLadderManager.cs b/osu.Game.Tournament.Tests/TestCaseLadderManager.cs index ac56803c90..767681849b 100644 --- a/osu.Game.Tournament.Tests/TestCaseLadderManager.cs +++ b/osu.Game.Tournament.Tests/TestCaseLadderManager.cs @@ -1,7 +1,6 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System.Collections.Generic; using System.IO; using Newtonsoft.Json; using osu.Framework.Allocation; @@ -9,7 +8,6 @@ using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Game.Graphics.Cursor; using osu.Game.Tests.Visual; -using osu.Game.Tournament.Components; using osu.Game.Tournament.Screens.Ladder; using osu.Game.Tournament.Screens.Ladder.Components; @@ -25,13 +23,12 @@ namespace osu.Game.Tournament.Tests public TestCaseLadderManager() { - var teams = JsonConvert.DeserializeObject>(File.ReadAllText(@"teams.json")); var ladder = File.Exists(@"bracket.json") ? JsonConvert.DeserializeObject(File.ReadAllText(@"bracket.json")) : new LadderInfo(); Child = new OsuContextMenuContainer { RelativeSizeAxes = Axes.Both, - Child = manager = new LadderManager(ladder, teams) + Child = manager = new LadderManager(ladder) }; } diff --git a/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchPairing.cs b/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchPairing.cs index 285baad872..42670b7bc0 100644 --- a/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchPairing.cs +++ b/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchPairing.cs @@ -107,7 +107,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components { bool progressionAbove = progression.ID < Pairing.ID; - var destinationForWinner = progressionAbove || progression.Team1.Value != null && progression.Team1.Value != Pairing.Winner ? progression.Team2 : progression.Team1; + var destinationForWinner = progressionAbove || progression.Team1.Value != null && progression.Team1.Value != Pairing.Team1.Value && progression.Team1.Value != Pairing.Team2.Value ? progression.Team2 : progression.Team1; destinationForWinner.Value = Pairing.Winner; } @@ -115,7 +115,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components { bool progressionAbove = progression.ID < Pairing.ID; - var destinationForLoser = progressionAbove || progression.Team1.Value != null && progression.Team1.Value != Pairing.Winner ? progression.Team2 : progression.Team1; + var destinationForLoser = progressionAbove || progression.Team1.Value != null && progression.Team1.Value != Pairing.Team1.Value && progression.Team1.Value != Pairing.Team2.Value ? progression.Team2 : progression.Team1; destinationForLoser.Value = Pairing.Loser; } } diff --git a/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchTeam.cs b/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchTeam.cs index c66d3fff55..f346e3c242 100644 --- a/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchTeam.cs +++ b/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchTeam.cs @@ -145,6 +145,10 @@ namespace osu.Game.Tournament.Screens.Ladder.Components // don't allow changing scores if the match has a progression. can cause large data loss return false; + if (pairing.Completed && pairing.Winner != Team) + // don't allow changing scores from the non-winner + return false; + if (score.Value > 0) score.Value--; else @@ -179,21 +183,4 @@ namespace osu.Game.Tournament.Screens.Ladder.Components } } } - - internal static class Extensions - { - public static T Random(this IEnumerable enumerable) - { - if (enumerable == null) - { - throw new ArgumentNullException(nameof(enumerable)); - } - - // note: creating a Random instance each call may not be correct for you, - // consider a thread-safe static instance - var r = new Random(); - var list = enumerable as IList ?? enumerable.ToList(); - return list.Count == 0 ? default(T) : list[r.Next(0, list.Count)]; - } - } } diff --git a/osu.Game.Tournament/Screens/Ladder/Components/LadderInfo.cs b/osu.Game.Tournament/Screens/Ladder/Components/LadderInfo.cs index ba64b974d9..567cdb0daa 100644 --- a/osu.Game.Tournament/Screens/Ladder/Components/LadderInfo.cs +++ b/osu.Game.Tournament/Screens/Ladder/Components/LadderInfo.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System.Collections.Generic; +using osu.Game.Tournament.Components; namespace osu.Game.Tournament.Screens.Ladder.Components { @@ -10,5 +11,6 @@ namespace osu.Game.Tournament.Screens.Ladder.Components public List Pairings = new List(); public List Progressions = new List(); public List Groupings = new List(); + public List Teams = new List(); } } diff --git a/osu.Game.Tournament/Screens/Ladder/Components/MatchPairing.cs b/osu.Game.Tournament/Screens/Ladder/Components/MatchPairing.cs index 49a477701f..93d1b7085c 100644 --- a/osu.Game.Tournament/Screens/Ladder/Components/MatchPairing.cs +++ b/osu.Game.Tournament/Screens/Ladder/Components/MatchPairing.cs @@ -15,12 +15,18 @@ namespace osu.Game.Tournament.Screens.Ladder.Components { public int ID; + [JsonIgnore] public readonly Bindable Team1 = new Bindable(); + public string Team1Acronym; + public readonly Bindable Team1Score = new Bindable(); + [JsonIgnore] public readonly Bindable Team2 = new Bindable(); + public string Team2Acronym; + public readonly Bindable Team2Score = new Bindable(); public readonly Bindable Completed = new Bindable(); @@ -36,14 +42,15 @@ namespace osu.Game.Tournament.Screens.Ladder.Components [JsonIgnore] public readonly Bindable LosersProgression = new Bindable(); - [JsonProperty] public Point Position; public MatchPairing() { + Team1.BindValueChanged(t => Team1Acronym = t?.Acronym, true); + Team2.BindValueChanged(t => Team2Acronym = t?.Acronym, true); } - public MatchPairing(TournamentTeam team1 = null, TournamentTeam team2 = null) + public MatchPairing(TournamentTeam team1 = null, TournamentTeam team2 = null) : this() { Team1.Value = team1; Team2.Value = team2; diff --git a/osu.Game.Tournament/Screens/Ladder/LadderManager.cs b/osu.Game.Tournament/Screens/Ladder/LadderManager.cs index d5ff651ef3..665230eff7 100644 --- a/osu.Game.Tournament/Screens/Ladder/LadderManager.cs +++ b/osu.Game.Tournament/Screens/Ladder/LadderManager.cs @@ -35,9 +35,9 @@ namespace osu.Game.Tournament.Screens.Ladder [Cached] private readonly LadderEditorInfo editorInfo = new LadderEditorInfo(); - public LadderManager(LadderInfo info, List teams) + public LadderManager(LadderInfo info) { - editorInfo.Teams = Teams = teams; + editorInfo.Teams = Teams = info.Teams; editorInfo.Groupings = info.Groupings; RelativeSizeAxes = Axes.Both; @@ -66,6 +66,14 @@ namespace osu.Game.Tournament.Screens.Ladder } }; + // assign teams + foreach (var pairing in info.Pairings) + { + pairing.Team1.Value = info.Teams.FirstOrDefault(t => t.Acronym == pairing.Team1Acronym); + pairing.Team2.Value = info.Teams.FirstOrDefault(t => t.Acronym == pairing.Team2Acronym); + } + + // assign progressions foreach (var pair in info.Progressions) { var src = info.Pairings.FirstOrDefault(p => p.ID == pair.Item1); @@ -106,6 +114,7 @@ namespace osu.Game.Tournament.Screens.Ladder Progressions = pairings.Where(p => p.Progression.Value != null).Select(p => new TournamentProgression(p.ID, p.Progression.Value.ID)).Concat( pairings.Where(p => p.LosersProgression.Value != null).Select(p => new TournamentProgression(p.ID, p.LosersProgression.Value.ID, true))) .ToList(), + Teams = editorInfo.Teams, Groupings = editorInfo.Groupings }; }