2019-03-04 13:24:19 +09:00
|
|
|
// 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.
|
2018-08-26 01:14:18 +09:00
|
|
|
|
2018-10-14 05:19:50 +09:00
|
|
|
using System;
|
2018-12-01 15:32:11 +09:00
|
|
|
using System.Collections.Generic;
|
2018-11-08 06:29:04 +09:00
|
|
|
using System.Collections.ObjectModel;
|
2018-09-10 04:51:38 +09:00
|
|
|
using Newtonsoft.Json;
|
2019-03-02 13:40:43 +09:00
|
|
|
using osu.Framework.Bindables;
|
2019-06-18 14:51:48 +09:00
|
|
|
using osu.Game.Tournament.Screens.Ladder.Components;
|
2018-09-10 04:51:38 +09:00
|
|
|
using SixLabors.Primitives;
|
2018-08-26 01:14:18 +09:00
|
|
|
|
2019-06-18 14:51:48 +09:00
|
|
|
namespace osu.Game.Tournament.Models
|
2018-08-26 01:14:18 +09:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// A collection of two teams competing in a head-to-head match.
|
|
|
|
/// </summary>
|
2019-03-04 14:18:04 +09:00
|
|
|
[Serializable]
|
2019-06-18 14:57:05 +09:00
|
|
|
public class TournamentMatch
|
2018-08-26 01:14:18 +09:00
|
|
|
{
|
2018-09-16 05:35:51 +09:00
|
|
|
public int ID;
|
|
|
|
|
2018-12-01 15:32:11 +09: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-25 03:14:30 +09:00
|
|
|
[JsonIgnore]
|
2018-09-10 04:51:38 +09:00
|
|
|
public readonly Bindable<TournamentTeam> Team1 = new Bindable<TournamentTeam>();
|
2018-08-26 01:14:18 +09:00
|
|
|
|
2018-09-25 03:14:30 +09:00
|
|
|
public string Team1Acronym;
|
|
|
|
|
2018-09-10 04:51:38 +09:00
|
|
|
public readonly Bindable<int?> Team1Score = new Bindable<int?>();
|
2018-08-26 01:14:18 +09:00
|
|
|
|
2018-09-25 03:14:30 +09:00
|
|
|
[JsonIgnore]
|
2018-09-10 04:51:38 +09:00
|
|
|
public readonly Bindable<TournamentTeam> Team2 = new Bindable<TournamentTeam>();
|
|
|
|
|
2018-09-25 03:14:30 +09:00
|
|
|
public string Team2Acronym;
|
|
|
|
|
2018-09-10 04:51:38 +09:00
|
|
|
public readonly Bindable<int?> Team2Score = new Bindable<int?>();
|
|
|
|
|
|
|
|
public readonly Bindable<bool> Completed = new Bindable<bool>();
|
|
|
|
|
2018-09-25 02:31:48 +09:00
|
|
|
public readonly Bindable<bool> Losers = new Bindable<bool>();
|
|
|
|
|
2018-11-08 06:29:04 +09:00
|
|
|
public readonly ObservableCollection<BeatmapChoice> PicksBans = new ObservableCollection<BeatmapChoice>();
|
|
|
|
|
2018-09-24 23:30:37 +09:00
|
|
|
[JsonIgnore]
|
2019-06-18 14:44:15 +09:00
|
|
|
public readonly Bindable<TournamentRound> Round = new Bindable<TournamentRound>();
|
2018-09-16 05:35:51 +09:00
|
|
|
|
2018-09-21 19:58:47 +09:00
|
|
|
[JsonIgnore]
|
2019-06-18 14:57:05 +09:00
|
|
|
public readonly Bindable<TournamentMatch> Progression = new Bindable<TournamentMatch>();
|
2018-09-21 19:58:47 +09:00
|
|
|
|
2018-09-25 02:31:48 +09:00
|
|
|
[JsonIgnore]
|
2019-06-18 14:57:05 +09:00
|
|
|
public readonly Bindable<TournamentMatch> LosersProgression = new Bindable<TournamentMatch>();
|
2018-09-25 02:31:48 +09:00
|
|
|
|
2018-11-07 01:20:32 +09:00
|
|
|
/// <summary>
|
|
|
|
/// Should not be set directly. Use LadderInfo.CurrentMatch.Value = this instead.
|
|
|
|
/// </summary>
|
|
|
|
public readonly Bindable<bool> Current = new Bindable<bool>();
|
|
|
|
|
2019-06-21 15:34:03 +09:00
|
|
|
public readonly Bindable<DateTimeOffset> Date = new Bindable<DateTimeOffset>(DateTimeOffset.Now);
|
2018-10-14 05:19:50 +09:00
|
|
|
|
2019-03-04 14:18:04 +09:00
|
|
|
[JsonProperty]
|
2019-06-18 14:57:05 +09:00
|
|
|
public readonly BindableList<ConditionalTournamentMatch> ConditionalMatches = new BindableList<ConditionalTournamentMatch>();
|
2018-12-01 15:32:11 +09:00
|
|
|
|
2018-11-16 20:14:34 +09:00
|
|
|
public readonly Bindable<Point> Position = new Bindable<Point>();
|
2018-09-10 04:51:38 +09:00
|
|
|
|
2019-06-18 14:57:05 +09:00
|
|
|
public TournamentMatch()
|
2018-09-10 04:51:38 +09:00
|
|
|
{
|
2019-06-17 16:28:58 +09:00
|
|
|
Team1.BindValueChanged(t => Team1Acronym = t.NewValue?.Acronym.Value, true);
|
|
|
|
Team2.BindValueChanged(t => Team2Acronym = t.NewValue?.Acronym.Value, true);
|
2018-09-10 04:51:38 +09:00
|
|
|
}
|
2018-08-26 01:14:18 +09:00
|
|
|
|
2019-06-18 14:57:05 +09:00
|
|
|
public TournamentMatch(TournamentTeam team1 = null, TournamentTeam team2 = null)
|
2018-11-08 06:29:04 +09:00
|
|
|
: this()
|
2018-08-26 01:14:18 +09:00
|
|
|
{
|
|
|
|
Team1.Value = team1;
|
|
|
|
Team2.Value = team2;
|
|
|
|
}
|
2018-08-26 18:37:46 +09:00
|
|
|
|
2018-09-16 05:35:51 +09:00
|
|
|
[JsonIgnore]
|
|
|
|
public TournamentTeam Winner => !Completed.Value ? null : Team1Score.Value > Team2Score.Value ? Team1.Value : Team2.Value;
|
2018-08-26 18:37:46 +09:00
|
|
|
|
2018-09-25 02:31:48 +09:00
|
|
|
[JsonIgnore]
|
|
|
|
public TournamentTeam Loser => !Completed.Value ? null : Team1Score.Value > Team2Score.Value ? Team2.Value : Team1.Value;
|
|
|
|
|
2020-03-06 16:03:34 +09:00
|
|
|
public TeamColour WinnerColour => Winner == Team1.Value ? TeamColour.Red : TeamColour.Blue;
|
|
|
|
|
2019-06-18 14:44:15 +09:00
|
|
|
public int PointsToWin => Round.Value?.BestOf.Value / 2 + 1 ?? 0;
|
2018-11-10 07:31:06 +09:00
|
|
|
|
2018-08-26 19:11:46 +09:00
|
|
|
/// <summary>
|
|
|
|
/// Remove scores from the match, in case of a false click or false start.
|
|
|
|
/// </summary>
|
|
|
|
public void CancelMatchStart()
|
2018-08-26 18:37:46 +09:00
|
|
|
{
|
2018-08-26 19:11:46 +09: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 18:37:46 +09:00
|
|
|
Team1Score.Value = 0;
|
|
|
|
Team2Score.Value = 0;
|
|
|
|
}
|
2019-02-06 18:36:15 +09:00
|
|
|
|
|
|
|
public void Reset()
|
|
|
|
{
|
|
|
|
CancelMatchStart();
|
|
|
|
Team1.Value = null;
|
|
|
|
Team2.Value = null;
|
|
|
|
Completed.Value = false;
|
|
|
|
PicksBans.Clear();
|
|
|
|
}
|
2018-08-26 01:14:18 +09:00
|
|
|
}
|
|
|
|
}
|