mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 18:12:56 +08:00
Simplify team storage
This commit is contained in:
parent
d2ce974ba8
commit
baefcb9deb
@ -1,7 +1,6 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -9,7 +8,6 @@ using osu.Framework.Configuration;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Graphics.Cursor;
|
using osu.Game.Graphics.Cursor;
|
||||||
using osu.Game.Tests.Visual;
|
using osu.Game.Tests.Visual;
|
||||||
using osu.Game.Tournament.Components;
|
|
||||||
using osu.Game.Tournament.Screens.Ladder;
|
using osu.Game.Tournament.Screens.Ladder;
|
||||||
using osu.Game.Tournament.Screens.Ladder.Components;
|
using osu.Game.Tournament.Screens.Ladder.Components;
|
||||||
|
|
||||||
@ -25,13 +23,12 @@ namespace osu.Game.Tournament.Tests
|
|||||||
|
|
||||||
public TestCaseLadderManager()
|
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();
|
var ladder = File.Exists(@"bracket.json") ? JsonConvert.DeserializeObject<LadderInfo>(File.ReadAllText(@"bracket.json")) : new LadderInfo();
|
||||||
|
|
||||||
Child = new OsuContextMenuContainer
|
Child = new OsuContextMenuContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Child = manager = new LadderManager(ladder, teams)
|
Child = manager = new LadderManager(ladder)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
|||||||
{
|
{
|
||||||
bool progressionAbove = progression.ID < Pairing.ID;
|
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;
|
destinationForWinner.Value = Pairing.Winner;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
|||||||
{
|
{
|
||||||
bool progressionAbove = progression.ID < Pairing.ID;
|
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;
|
destinationForLoser.Value = Pairing.Loser;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
// don't allow changing scores if the match has a progression. can cause large data loss
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (pairing.Completed && pairing.Winner != Team)
|
||||||
|
// don't allow changing scores from the non-winner
|
||||||
|
return false;
|
||||||
|
|
||||||
if (score.Value > 0)
|
if (score.Value > 0)
|
||||||
score.Value--;
|
score.Value--;
|
||||||
else
|
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)];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using osu.Game.Tournament.Components;
|
||||||
|
|
||||||
namespace osu.Game.Tournament.Screens.Ladder.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<MatchPairing> Pairings = new List<MatchPairing>();
|
||||||
public List<TournamentProgression> Progressions = new List<TournamentProgression>();
|
public List<TournamentProgression> Progressions = new List<TournamentProgression>();
|
||||||
public List<TournamentGrouping> Groupings = new List<TournamentGrouping>();
|
public List<TournamentGrouping> Groupings = new List<TournamentGrouping>();
|
||||||
|
public List<TournamentTeam> Teams = new List<TournamentTeam>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,18 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
|||||||
{
|
{
|
||||||
public int ID;
|
public int ID;
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
public readonly Bindable<TournamentTeam> Team1 = new Bindable<TournamentTeam>();
|
public readonly Bindable<TournamentTeam> Team1 = new Bindable<TournamentTeam>();
|
||||||
|
|
||||||
|
public string Team1Acronym;
|
||||||
|
|
||||||
public readonly Bindable<int?> Team1Score = new Bindable<int?>();
|
public readonly Bindable<int?> Team1Score = new Bindable<int?>();
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
public readonly Bindable<TournamentTeam> Team2 = new Bindable<TournamentTeam>();
|
public readonly Bindable<TournamentTeam> Team2 = new Bindable<TournamentTeam>();
|
||||||
|
|
||||||
|
public string Team2Acronym;
|
||||||
|
|
||||||
public readonly Bindable<int?> Team2Score = new Bindable<int?>();
|
public readonly Bindable<int?> Team2Score = new Bindable<int?>();
|
||||||
|
|
||||||
public readonly Bindable<bool> Completed = new Bindable<bool>();
|
public readonly Bindable<bool> Completed = new Bindable<bool>();
|
||||||
@ -36,14 +42,15 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
|||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public readonly Bindable<MatchPairing> LosersProgression = new Bindable<MatchPairing>();
|
public readonly Bindable<MatchPairing> LosersProgression = new Bindable<MatchPairing>();
|
||||||
|
|
||||||
[JsonProperty]
|
|
||||||
public Point Position;
|
public Point Position;
|
||||||
|
|
||||||
public MatchPairing()
|
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;
|
Team1.Value = team1;
|
||||||
Team2.Value = team2;
|
Team2.Value = team2;
|
||||||
|
@ -35,9 +35,9 @@ namespace osu.Game.Tournament.Screens.Ladder
|
|||||||
[Cached]
|
[Cached]
|
||||||
private readonly LadderEditorInfo editorInfo = new LadderEditorInfo();
|
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;
|
editorInfo.Groupings = info.Groupings;
|
||||||
|
|
||||||
RelativeSizeAxes = Axes.Both;
|
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)
|
foreach (var pair in info.Progressions)
|
||||||
{
|
{
|
||||||
var src = info.Pairings.FirstOrDefault(p => p.ID == pair.Item1);
|
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(
|
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)))
|
pairings.Where(p => p.LosersProgression.Value != null).Select(p => new TournamentProgression(p.ID, p.LosersProgression.Value.ID, true)))
|
||||||
.ToList(),
|
.ToList(),
|
||||||
|
Teams = editorInfo.Teams,
|
||||||
Groupings = editorInfo.Groupings
|
Groupings = editorInfo.Groupings
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user