1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 00:02:54 +08:00

Simplify team storage

This commit is contained in:
Dean Herbert 2018-09-25 03:14:30 +09:00
parent d2ce974ba8
commit baefcb9deb
6 changed files with 29 additions and 27 deletions

View File

@ -1,7 +1,6 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using osu.Framework.Allocation;
@ -9,7 +8,6 @@ using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Game.Graphics.Cursor;
using osu.Game.Tests.Visual;
using osu.Game.Tournament.Components;
using osu.Game.Tournament.Screens.Ladder;
using osu.Game.Tournament.Screens.Ladder.Components;
@ -25,13 +23,12 @@ namespace osu.Game.Tournament.Tests
public TestCaseLadderManager()
{
var teams = JsonConvert.DeserializeObject<List<TournamentTeam>>(File.ReadAllText(@"teams.json"));
var ladder = File.Exists(@"bracket.json") ? JsonConvert.DeserializeObject<LadderInfo>(File.ReadAllText(@"bracket.json")) : new LadderInfo();
Child = new OsuContextMenuContainer
{
RelativeSizeAxes = Axes.Both,
Child = manager = new LadderManager(ladder, teams)
Child = manager = new LadderManager(ladder)
};
}

View File

@ -107,7 +107,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
{
bool progressionAbove = progression.ID < Pairing.ID;
var destinationForWinner = progressionAbove || progression.Team1.Value != null && progression.Team1.Value != Pairing.Winner ? progression.Team2 : progression.Team1;
var destinationForWinner = progressionAbove || progression.Team1.Value != null && progression.Team1.Value != Pairing.Team1.Value && progression.Team1.Value != Pairing.Team2.Value ? progression.Team2 : progression.Team1;
destinationForWinner.Value = Pairing.Winner;
}
@ -115,7 +115,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
{
bool progressionAbove = progression.ID < Pairing.ID;
var destinationForLoser = progressionAbove || progression.Team1.Value != null && progression.Team1.Value != Pairing.Winner ? progression.Team2 : progression.Team1;
var destinationForLoser = progressionAbove || progression.Team1.Value != null && progression.Team1.Value != Pairing.Team1.Value && progression.Team1.Value != Pairing.Team2.Value ? progression.Team2 : progression.Team1;
destinationForLoser.Value = Pairing.Loser;
}
}

View File

@ -145,6 +145,10 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
// don't allow changing scores if the match has a progression. can cause large data loss
return false;
if (pairing.Completed && pairing.Winner != Team)
// don't allow changing scores from the non-winner
return false;
if (score.Value > 0)
score.Value--;
else
@ -179,21 +183,4 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
}
}
}
internal static class Extensions
{
public static T Random<T>(this IEnumerable<T> enumerable)
{
if (enumerable == null)
{
throw new ArgumentNullException(nameof(enumerable));
}
// note: creating a Random instance each call may not be correct for you,
// consider a thread-safe static instance
var r = new Random();
var list = enumerable as IList<T> ?? enumerable.ToList();
return list.Count == 0 ? default(T) : list[r.Next(0, list.Count)];
}
}
}

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using osu.Game.Tournament.Components;
namespace osu.Game.Tournament.Screens.Ladder.Components
{
@ -10,5 +11,6 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
public List<MatchPairing> Pairings = new List<MatchPairing>();
public List<TournamentProgression> Progressions = new List<TournamentProgression>();
public List<TournamentGrouping> Groupings = new List<TournamentGrouping>();
public List<TournamentTeam> Teams = new List<TournamentTeam>();
}
}

View File

@ -15,12 +15,18 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
{
public int ID;
[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>();
@ -36,14 +42,15 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
[JsonIgnore]
public readonly Bindable<MatchPairing> LosersProgression = new Bindable<MatchPairing>();
[JsonProperty]
public Point Position;
public MatchPairing()
{
Team1.BindValueChanged(t => Team1Acronym = t?.Acronym, true);
Team2.BindValueChanged(t => Team2Acronym = t?.Acronym, true);
}
public MatchPairing(TournamentTeam team1 = null, TournamentTeam team2 = null)
public MatchPairing(TournamentTeam team1 = null, TournamentTeam team2 = null) : this()
{
Team1.Value = team1;
Team2.Value = team2;

View File

@ -35,9 +35,9 @@ namespace osu.Game.Tournament.Screens.Ladder
[Cached]
private readonly LadderEditorInfo editorInfo = new LadderEditorInfo();
public LadderManager(LadderInfo info, List<TournamentTeam> teams)
public LadderManager(LadderInfo info)
{
editorInfo.Teams = Teams = teams;
editorInfo.Teams = Teams = info.Teams;
editorInfo.Groupings = info.Groupings;
RelativeSizeAxes = Axes.Both;
@ -66,6 +66,14 @@ namespace osu.Game.Tournament.Screens.Ladder
}
};
// assign teams
foreach (var pairing in info.Pairings)
{
pairing.Team1.Value = info.Teams.FirstOrDefault(t => t.Acronym == pairing.Team1Acronym);
pairing.Team2.Value = info.Teams.FirstOrDefault(t => t.Acronym == pairing.Team2Acronym);
}
// assign progressions
foreach (var pair in info.Progressions)
{
var src = info.Pairings.FirstOrDefault(p => p.ID == pair.Item1);
@ -106,6 +114,7 @@ namespace osu.Game.Tournament.Screens.Ladder
Progressions = pairings.Where(p => p.Progression.Value != null).Select(p => new TournamentProgression(p.ID, p.Progression.Value.ID)).Concat(
pairings.Where(p => p.LosersProgression.Value != null).Select(p => new TournamentProgression(p.ID, p.LosersProgression.Value.ID, true)))
.ToList(),
Teams = editorInfo.Teams,
Groupings = editorInfo.Groupings
};
}