General namespace tidy-up

This commit is contained in:
Dean Herbert
2019-06-18 14:51:48 +09:00
parent 4f5abeb79f
commit 96e24ebd20
48 changed files with 63 additions and 39 deletions

View File

@ -0,0 +1,33 @@
// 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.
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace osu.Game.Tournament.Models
{
public class BeatmapChoice
{
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public TeamColour Team;
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public ChoiceType Type;
public int BeatmapID;
}
[JsonConverter(typeof(StringEnumConverter))]
public enum TeamColour
{
Red,
Blue
}
[JsonConverter(typeof(StringEnumConverter))]
public enum ChoiceType
{
Pick,
Ban,
}
}

View File

@ -0,0 +1,12 @@
// 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.
using osu.Framework.Bindables;
namespace osu.Game.Tournament.Models
{
public class LadderEditorInfo
{
public readonly Bindable<MatchPairing> Selected = new Bindable<MatchPairing>();
}
}

View File

@ -0,0 +1,22 @@
// 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.
using System.Collections.Generic;
using Newtonsoft.Json;
using osu.Framework.Bindables;
namespace osu.Game.Tournament.Models
{
public class LadderInfo
{
public BindableList<MatchPairing> Pairings = new BindableList<MatchPairing>();
public BindableList<TournamentRound> Rounds = new BindableList<TournamentRound>();
public BindableList<TournamentTeam> Teams = new BindableList<TournamentTeam>();
// only used for serialisation
public List<TournamentProgression> Progressions = new List<TournamentProgression>();
[JsonIgnore]
public Bindable<MatchPairing> CurrentMatch = new Bindable<MatchPairing>();
}
}

View File

@ -0,0 +1,125 @@
// 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.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Newtonsoft.Json;
using osu.Framework.Bindables;
using osu.Game.Tournament.Screens.Ladder.Components;
using SixLabors.Primitives;
namespace osu.Game.Tournament.Models
{
/// <summary>
/// A collection of two teams competing in a head-to-head match.
/// </summary>
[Serializable]
public class MatchPairing
{
public int ID;
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;
}
}
[JsonIgnore]
public readonly Bindable<TournamentTeam> Team1 = new Bindable<TournamentTeam>();
public string Team1Acronym;
public readonly Bindable<int?> Team1Score = new Bindable<int?>();
[JsonIgnore]
public readonly Bindable<TournamentTeam> Team2 = new Bindable<TournamentTeam>();
public string Team2Acronym;
public readonly Bindable<int?> Team2Score = new Bindable<int?>();
public readonly Bindable<bool> Completed = new Bindable<bool>();
public readonly Bindable<bool> Losers = new Bindable<bool>();
public readonly ObservableCollection<BeatmapChoice> PicksBans = new ObservableCollection<BeatmapChoice>();
[JsonIgnore]
public readonly Bindable<TournamentRound> Round = new Bindable<TournamentRound>();
[JsonIgnore]
public readonly Bindable<MatchPairing> Progression = new Bindable<MatchPairing>();
[JsonIgnore]
public readonly Bindable<MatchPairing> LosersProgression = new Bindable<MatchPairing>();
/// <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>();
[JsonProperty]
public readonly BindableList<ConditionalMatchPairing> ConditionalPairings = new BindableList<ConditionalMatchPairing>();
public readonly Bindable<Point> Position = new Bindable<Point>();
public MatchPairing()
{
Team1.BindValueChanged(t => Team1Acronym = t.NewValue?.Acronym.Value, true);
Team2.BindValueChanged(t => Team2Acronym = t.NewValue?.Acronym.Value, true);
}
public MatchPairing(TournamentTeam team1 = null, TournamentTeam team2 = null)
: this()
{
Team1.Value = team1;
Team2.Value = team2;
}
[JsonIgnore]
public TournamentTeam Winner => !Completed.Value ? null : Team1Score.Value > Team2Score.Value ? Team1.Value : Team2.Value;
[JsonIgnore]
public TournamentTeam Loser => !Completed.Value ? null : Team1Score.Value > Team2Score.Value ? Team2.Value : Team1.Value;
public int PointsToWin => Round.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()
{
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;
Team1Score.Value = 0;
Team2Score.Value = 0;
}
public void Reset()
{
CancelMatchStart();
Team1.Value = null;
Team2.Value = null;
Completed.Value = false;
PicksBans.Clear();
}
}
}

View File

@ -0,0 +1,15 @@
// 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.
using osu.Game.Beatmaps;
namespace osu.Game.Tournament.Models
{
public class RoundBeatmap
{
public int ID;
public string Mods;
public BeatmapInfo BeatmapInfo;
}
}

View File

@ -0,0 +1,31 @@
// 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.
namespace osu.Game.Tournament.Models
{
public class TournamentProgression
{
public int SourceID;
public int TargetID;
// migration
public int Item1
{
set => SourceID = value;
}
public int Item2
{
set => TargetID = value;
}
public bool Losers;
public TournamentProgression(int sourceID, int targetID, bool losers = false)
{
SourceID = sourceID;
TargetID = targetID;
Losers = losers;
}
}
}

View File

@ -0,0 +1,29 @@
// 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.
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using osu.Framework.Bindables;
namespace osu.Game.Tournament.Models
{
[Serializable]
public class TournamentRound
{
public readonly Bindable<string> Name = new Bindable<string>();
public readonly Bindable<string> Description = new Bindable<string>();
public readonly BindableInt BestOf = new BindableInt(9) { Default = 9, MinValue = 3, MaxValue = 23 };
[JsonProperty]
public readonly List<RoundBeatmap> Beatmaps = new List<RoundBeatmap>();
public readonly Bindable<DateTimeOffset> StartDate = new Bindable<DateTimeOffset>();
// only used for serialisation
public List<int> Pairings = new List<int>();
public override string ToString() => Name.Value ?? "None";
}
}

View File

@ -0,0 +1,51 @@
// 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.
using System;
using Newtonsoft.Json;
using osu.Framework.Bindables;
using osu.Game.Users;
namespace osu.Game.Tournament.Models
{
[Serializable]
public class TournamentTeam
{
/// <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);
/// <summary>
/// Short acronym which appears in the group boxes post-selection.
/// </summary>
public Bindable<string> Acronym = new Bindable<string>(string.Empty);
[JsonProperty]
public BindableList<User> Players { get; set; } = new BindableList<User>();
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).ToUpper() : 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).ToUpper() : string.Empty;
};
}
public override string ToString() => FullName.Value ?? Acronym.Value;
}
}