// 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.Linq; using Newtonsoft.Json; using osu.Framework.Bindables; namespace osu.Game.Tournament.Models { /// /// A team representation. For official tournaments this is generally a country. /// [Serializable] public class TournamentTeam { /// /// The name of this team. /// public Bindable FullName = new Bindable(string.Empty); /// /// Name of the file containing the flag. /// public Bindable FlagName = new Bindable(string.Empty); /// /// Short acronym which appears in the group boxes post-selection. /// public Bindable Acronym = new Bindable(string.Empty); public BindableList SeedingResults = new BindableList(); public double AverageRank { get { int[] ranks = Players.Select(p => p.Rank) .Where(i => i.HasValue) .Select(i => i!.Value) .ToArray(); if (ranks.Length == 0) return 0; return ranks.Average(); } } public Bindable Seed = new Bindable(string.Empty); public Bindable LastYearPlacing = new BindableInt { MinValue = 0, MaxValue = 256 }; [JsonProperty] public BindableList Players { get; set; } = new BindableList(); public TournamentTeam() { Acronym.ValueChanged += val => { // use a sane default flag name based on acronym. if (val.OldValue.StartsWith(FlagName.Value, StringComparison.InvariantCultureIgnoreCase)) 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)) Acronym.Value = val.NewValue?.Length >= 3 ? val.NewValue.Substring(0, 3).ToUpperInvariant() : string.Empty; }; } public override string ToString() => FullName.Value ?? Acronym.Value; } }