osu/osu.Game.Tournament/Screens/Ladder/Components/MatchPairing.cs

124 lines
4.0 KiB
C#
Raw Normal View History

// 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;
2018-12-01 06:32:11 +00:00
using System.Collections.Generic;
2018-11-07 21:29:04 +00:00
using System.Collections.ObjectModel;
using Newtonsoft.Json;
2019-03-02 04:40:43 +00:00
using osu.Framework.Bindables;
2018-08-25 16:24:19 +00:00
using osu.Game.Tournament.Components;
using SixLabors.Primitives;
namespace osu.Game.Tournament.Screens.Ladder.Components
{
/// <summary>
/// A collection of two teams competing in a head-to-head match.
/// </summary>
public class MatchPairing
{
2018-09-15 20:35:51 +00:00
public int ID;
2018-12-01 06:32:11 +00:00
public List<string> Acronyms
{
get
{
List<string> acronyms = new List<string>();
if (Team1Acronym != null) acronyms.Add(Team1Acronym);
if (Team2Acronym != null) acronyms.Add(Team2Acronym);
return acronyms;
}
}
2018-09-24 18:14:30 +00:00
[JsonIgnore]
public readonly Bindable<TournamentTeam> Team1 = new Bindable<TournamentTeam>();
2018-09-24 18:14:30 +00:00
public string Team1Acronym;
public readonly Bindable<int?> Team1Score = new Bindable<int?>();
2018-09-24 18:14:30 +00:00
[JsonIgnore]
public readonly Bindable<TournamentTeam> Team2 = new Bindable<TournamentTeam>();
2018-09-24 18:14:30 +00:00
public string Team2Acronym;
public readonly Bindable<int?> Team2Score = new Bindable<int?>();
public readonly Bindable<bool> Completed = new Bindable<bool>();
2018-09-24 17:31:48 +00:00
public readonly Bindable<bool> Losers = new Bindable<bool>();
2018-11-07 21:29:04 +00:00
public readonly ObservableCollection<BeatmapChoice> PicksBans = new ObservableCollection<BeatmapChoice>();
2018-09-24 14:30:37 +00:00
[JsonIgnore]
public readonly Bindable<TournamentGrouping> Grouping = new Bindable<TournamentGrouping>();
2018-09-15 20:35:51 +00:00
2018-09-21 10:58:47 +00:00
[JsonIgnore]
2018-09-21 20:52:25 +00:00
public readonly Bindable<MatchPairing> Progression = new Bindable<MatchPairing>();
2018-09-21 10:58:47 +00:00
2018-09-24 17:31:48 +00:00
[JsonIgnore]
public readonly Bindable<MatchPairing> LosersProgression = new Bindable<MatchPairing>();
2018-11-06 16:20:32 +00:00
/// <summary>
/// Should not be set directly. Use LadderInfo.CurrentMatch.Value = this instead.
/// </summary>
public readonly Bindable<bool> Current = new Bindable<bool>();
public readonly Bindable<DateTimeOffset> Date = new Bindable<DateTimeOffset>();
public readonly BindableList<ConditionalMatchPairing> ConditionalPairings = new BindableList<ConditionalMatchPairing>();
2018-12-01 06:32:11 +00:00
public readonly Bindable<Point> Position = new Bindable<Point>();
public MatchPairing()
{
2019-03-02 04:40:43 +00:00
Team1.BindValueChanged(t => Team1Acronym = t.NewValue?.Acronym, true);
Team2.BindValueChanged(t => Team2Acronym = t.NewValue?.Acronym, true);
}
2018-11-07 21:29:04 +00:00
public MatchPairing(TournamentTeam team1 = null, TournamentTeam team2 = null)
: this()
{
Team1.Value = team1;
Team2.Value = team2;
}
2018-08-26 09:37:46 +00:00
2018-09-15 20:35:51 +00:00
[JsonIgnore]
public TournamentTeam Winner => !Completed.Value ? null : Team1Score.Value > Team2Score.Value ? Team1.Value : Team2.Value;
2018-08-26 09:37:46 +00:00
2018-09-24 17:31:48 +00:00
[JsonIgnore]
public TournamentTeam Loser => !Completed.Value ? null : Team1Score.Value > Team2Score.Value ? Team2.Value : Team1.Value;
2019-03-02 04:40:43 +00:00
public int PointsToWin => Grouping.Value?.BestOf.Value / 2 + 1 ?? 0;
/// <summary>
/// Remove scores from the match, in case of a false click or false start.
/// </summary>
public void CancelMatchStart()
2018-08-26 09:37:46 +00:00
{
Team1Score.Value = null;
Team2Score.Value = null;
}
/// <summary>
/// Initialise this match with zeroed scores. Will be a noop if either team is not present.
/// </summary>
public void StartMatch()
{
if (Team1.Value == null || Team2.Value == null)
return;
2018-08-26 09:37:46 +00:00
Team1Score.Value = 0;
Team2Score.Value = 0;
}
2019-02-06 09:36:15 +00:00
public void Reset()
{
CancelMatchStart();
Team1.Value = null;
Team2.Value = null;
Completed.Value = false;
PicksBans.Clear();
}
}
}