1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 12:37:47 +08:00
osu-lazer/osu.Game.Tournament/Models/TournamentTeam.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
2.7 KiB
C#
Raw Normal View History

2019-03-04 12:24:19 +08: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-04-13 17:19:50 +08:00
2018-10-16 15:07:59 +08:00
using System;
2020-03-03 17:12:42 +08:00
using System.Linq;
2018-10-16 15:07:59 +08:00
using Newtonsoft.Json;
using osu.Framework.Bindables;
2019-06-18 13:51:48 +08:00
namespace osu.Game.Tournament.Models
{
2019-06-18 14:00:33 +08:00
/// <summary>
/// A team representation. For official tournaments this is generally a country.
/// </summary>
2018-10-16 15:07:59 +08:00
[Serializable]
public class TournamentTeam
{
2017-05-02 15:54:43 +08:00
/// <summary>
/// The name of this team.
/// </summary>
public Bindable<string> FullName = new Bindable<string>(string.Empty);
/// <summary>
/// Name of the file containing the flag.
/// </summary>
public Bindable<string> FlagName = new Bindable<string>(string.Empty);
2018-04-13 17:19:50 +08:00
2017-05-02 15:54:43 +08:00
/// <summary>
/// Short acronym which appears in the group boxes post-selection.
2017-05-02 15:54:43 +08:00
/// </summary>
public Bindable<string> Acronym = new Bindable<string>(string.Empty);
2020-03-03 17:12:42 +08:00
public BindableList<SeedingResult> SeedingResults = new BindableList<SeedingResult>();
public double AverageRank
{
get
{
int[] ranks = Players.Select(p => p.Rank)
.Where(i => i.HasValue)
2023-08-09 17:21:57 +08:00
.Select(i => i!.Value)
.ToArray();
2020-03-03 17:12:42 +08:00
if (ranks.Length == 0)
return 0;
return ranks.Average();
}
}
public Bindable<string> Seed = new Bindable<string>(string.Empty);
public Bindable<int> LastYearPlacing = new BindableInt
{
MinValue = 0,
MaxValue = 256
2020-03-03 17:12:42 +08:00
};
2018-10-16 15:07:59 +08:00
[JsonProperty]
2023-10-06 15:51:24 +08:00
public BindableList<TournamentUser> Players { get; } = new BindableList<TournamentUser>();
public TournamentTeam()
{
Acronym.ValueChanged += val =>
{
// use a sane default flag name based on acronym.
if (val.OldValue.StartsWith(FlagName.Value, StringComparison.InvariantCultureIgnoreCase))
2023-07-25 19:50:55 +08:00
FlagName.Value = val.NewValue?.Length >= 2 ? val.NewValue.Substring(0, 2).ToUpperInvariant() : string.Empty;
};
FullName.ValueChanged += val =>
{
// use a sane acronym based on full name.
if (val.OldValue.StartsWith(Acronym.Value, StringComparison.InvariantCultureIgnoreCase))
2023-07-25 19:50:55 +08:00
Acronym.Value = val.NewValue?.Length >= 3 ? val.NewValue.Substring(0, 3).ToUpperInvariant() : string.Empty;
};
}
2018-09-22 04:52:25 +08:00
public override string ToString() => FullName.Value ?? Acronym.Value;
}
}