// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using System.Collections.Generic; using System.Collections.ObjectModel; using Newtonsoft.Json; using osu.Framework.Bindables; using osu.Game.Tournament.Components; using SixLabors.Primitives; namespace osu.Game.Tournament.Screens.Ladder.Components { /// /// A collection of two teams competing in a head-to-head match. /// [Serializable] public class MatchPairing { public int ID; public List Acronyms { get { List acronyms = new List(); if (Team1Acronym != null) acronyms.Add(Team1Acronym); if (Team2Acronym != null) acronyms.Add(Team2Acronym); return acronyms; } } [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(); public readonly Bindable Losers = new Bindable(); public readonly ObservableCollection PicksBans = new ObservableCollection(); [JsonIgnore] public readonly Bindable Grouping = new Bindable(); [JsonIgnore] public readonly Bindable Progression = new Bindable(); [JsonIgnore] public readonly Bindable LosersProgression = new Bindable(); /// /// Should not be set directly. Use LadderInfo.CurrentMatch.Value = this instead. /// public readonly Bindable Current = new Bindable(); public readonly Bindable Date = new Bindable(); [JsonProperty] public readonly BindableList ConditionalPairings = new BindableList(); public readonly Bindable Position = new Bindable(); public MatchPairing() { Team1.BindValueChanged(t => Team1Acronym = t.NewValue?.Acronym, true); Team2.BindValueChanged(t => Team2Acronym = t.NewValue?.Acronym, true); } public MatchPairing(TournamentTeam team1 = null, TournamentTeam team2 = null) : this() { Team1.Value = team1; Team2.Value = team2; } [JsonIgnore] public TournamentTeam Winner => !Completed.Value ? null : Team1Score.Value > Team2Score.Value ? Team1.Value : Team2.Value; [JsonIgnore] public TournamentTeam Loser => !Completed.Value ? null : Team1Score.Value > Team2Score.Value ? Team2.Value : Team1.Value; public int PointsToWin => Grouping.Value?.BestOf.Value / 2 + 1 ?? 0; /// /// Remove scores from the match, in case of a false click or false start. /// public void CancelMatchStart() { Team1Score.Value = null; Team2Score.Value = null; } /// /// Initialise this match with zeroed scores. Will be a noop if either team is not present. /// public void StartMatch() { if (Team1.Value == null || Team2.Value == null) return; Team1Score.Value = 0; Team2Score.Value = 0; } public void Reset() { CancelMatchStart(); Team1.Value = null; Team2.Value = null; Completed.Value = false; PicksBans.Clear(); } } }