1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-24 18:47:32 +08:00
osu-lazer/osu.Game.Tournament/Screens/Ladder/Components/MatchPairing.cs

93 lines
2.9 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 Newtonsoft.Json;
using osu.Framework.Configuration;
2018-08-26 00:24:19 +08: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-16 04:35:51 +08:00
public int ID;
public readonly Bindable<TournamentTeam> Team1 = new Bindable<TournamentTeam>();
public readonly Bindable<int?> Team1Score = new Bindable<int?>();
public readonly Bindable<TournamentTeam> Team2 = new Bindable<TournamentTeam>();
public readonly Bindable<int?> Team2Score = new Bindable<int?>();
public readonly Bindable<bool> Completed = new Bindable<bool>();
2018-09-16 04:35:51 +08:00
[JsonIgnore]
public readonly Bindable<MatchPairing> Progression = new Bindable<MatchPairing>();
2018-09-21 18:58:47 +08:00
[JsonIgnore]
public readonly Bindable<MatchPairing> ProgressionSource = new Bindable<MatchPairing>();
[JsonProperty]
public Point Position;
2018-09-21 18:58:47 +08:00
private MatchPairing lastProgression; // todo: fix if we ever get LastValue inside Bindable<>.
public MatchPairing()
{
2018-09-21 18:58:47 +08:00
Progression.ValueChanged += progression =>
{
if (lastProgression != null)
// clear the source from the previous progression.
2018-09-21 18:58:47 +08:00
lastProgression.ProgressionSource.Value = null;
if (progression != null)
// set the source on the new progression.
2018-09-21 18:58:47 +08:00
progression.ProgressionSource.Value = this;
lastProgression = progression;
};
ProgressionSource.ValueChanged += source =>
{
if (source != null)
// ennsure no two-way progressions.
Progression.Value = null;
};
}
public MatchPairing(TournamentTeam team1 = null, TournamentTeam team2 = null)
{
Team1.Value = team1;
Team2.Value = team2;
}
2018-08-26 17:37:46 +08:00
2018-09-16 04:35:51 +08:00
[JsonIgnore]
public TournamentTeam Winner => !Completed.Value ? null : Team1Score.Value > Team2Score.Value ? Team1.Value : Team2.Value;
2018-08-26 17:37:46 +08:00
/// <summary>
/// Remove scores from the match, in case of a false click or false start.
/// </summary>
public void CancelMatchStart()
2018-08-26 17:37:46 +08: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 17:37:46 +08:00
Team1Score.Value = 0;
Team2Score.Value = 0;
}
}
}