mirror of
https://github.com/ppy/osu.git
synced 2024-12-13 08:32:57 +08:00
Replace tournament player storage type with lightweight model
This commit is contained in:
parent
f3793c8809
commit
b977ce7995
@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
|
||||||
using osu.Game.Tests.Visual;
|
using osu.Game.Tests.Visual;
|
||||||
using osu.Game.Tournament.Components;
|
using osu.Game.Tournament.Components;
|
||||||
using osu.Game.Tournament.Models;
|
using osu.Game.Tournament.Models;
|
||||||
@ -26,13 +25,13 @@ namespace osu.Game.Tournament.Tests.Components
|
|||||||
FullName = { Value = "Australia" },
|
FullName = { Value = "Australia" },
|
||||||
Players =
|
Players =
|
||||||
{
|
{
|
||||||
new APIUser { Username = "ASecretBox" },
|
new TournamentPlayer { Username = "ASecretBox" },
|
||||||
new APIUser { Username = "Dereban" },
|
new TournamentPlayer { Username = "Dereban" },
|
||||||
new APIUser { Username = "mReKk" },
|
new TournamentPlayer { Username = "mReKk" },
|
||||||
new APIUser { Username = "uyghti" },
|
new TournamentPlayer { Username = "uyghti" },
|
||||||
new APIUser { Username = "Parkes" },
|
new TournamentPlayer { Username = "Parkes" },
|
||||||
new APIUser { Username = "Shiroha" },
|
new TournamentPlayer { Username = "Shiroha" },
|
||||||
new APIUser { Username = "Jordan The Bear" },
|
new TournamentPlayer { Username = "Jordan The Bear" },
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -27,13 +27,13 @@ namespace osu.Game.Tournament.Tests.Components
|
|||||||
Colour = "f2ca34"
|
Colour = "f2ca34"
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly APIUser redUser = new APIUser
|
private readonly TournamentPlayer redPlayer = new TournamentPlayer
|
||||||
{
|
{
|
||||||
Username = "BanchoBot",
|
Username = "BanchoBot",
|
||||||
Id = 3,
|
Id = 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly APIUser blueUser = new APIUser
|
private readonly TournamentPlayer bluePlayer = new TournamentPlayer
|
||||||
{
|
{
|
||||||
Username = "Zallius",
|
Username = "Zallius",
|
||||||
Id = 4,
|
Id = 4,
|
||||||
@ -59,11 +59,11 @@ namespace osu.Game.Tournament.Tests.Components
|
|||||||
{
|
{
|
||||||
Team1 =
|
Team1 =
|
||||||
{
|
{
|
||||||
Value = new TournamentTeam { Players = new BindableList<APIUser> { redUser } }
|
Value = new TournamentTeam { Players = new BindableList<TournamentPlayer> { redPlayer } }
|
||||||
},
|
},
|
||||||
Team2 =
|
Team2 =
|
||||||
{
|
{
|
||||||
Value = new TournamentTeam { Players = new BindableList<APIUser> { blueUser } }
|
Value = new TournamentTeam { Players = new BindableList<TournamentPlayer> { bluePlayer } }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -82,19 +82,19 @@ namespace osu.Game.Tournament.Tests.Components
|
|||||||
|
|
||||||
AddStep("message from team red", () => testChannel.AddNewMessages(new Message(nextMessageId())
|
AddStep("message from team red", () => testChannel.AddNewMessages(new Message(nextMessageId())
|
||||||
{
|
{
|
||||||
Sender = redUser,
|
Sender = redPlayer.ToUser(),
|
||||||
Content = "I am team red."
|
Content = "I am team red."
|
||||||
}));
|
}));
|
||||||
|
|
||||||
AddStep("message from team red", () => testChannel.AddNewMessages(new Message(nextMessageId())
|
AddStep("message from team red", () => testChannel.AddNewMessages(new Message(nextMessageId())
|
||||||
{
|
{
|
||||||
Sender = redUser,
|
Sender = redPlayer.ToUser(),
|
||||||
Content = "I plan to win!"
|
Content = "I plan to win!"
|
||||||
}));
|
}));
|
||||||
|
|
||||||
AddStep("message from team blue", () => testChannel.AddNewMessages(new Message(nextMessageId())
|
AddStep("message from team blue", () => testChannel.AddNewMessages(new Message(nextMessageId())
|
||||||
{
|
{
|
||||||
Sender = blueUser,
|
Sender = bluePlayer.ToUser(),
|
||||||
Content = "Not on my watch. Prepare to eat saaaaaaaaaand. Lots and lots of saaaaaaand."
|
Content = "Not on my watch. Prepare to eat saaaaaaaaaand. Lots and lots of saaaaaaand."
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -15,8 +15,6 @@ using osu.Game.Tests.Visual;
|
|||||||
using osu.Game.Tournament.IO;
|
using osu.Game.Tournament.IO;
|
||||||
using osu.Game.Tournament.IPC;
|
using osu.Game.Tournament.IPC;
|
||||||
using osu.Game.Tournament.Models;
|
using osu.Game.Tournament.Models;
|
||||||
using osu.Game.Users;
|
|
||||||
using APIUser = osu.Game.Online.API.Requests.Responses.APIUser;
|
|
||||||
|
|
||||||
namespace osu.Game.Tournament.Tests
|
namespace osu.Game.Tournament.Tests
|
||||||
{
|
{
|
||||||
@ -123,11 +121,11 @@ namespace osu.Game.Tournament.Tests
|
|||||||
},
|
},
|
||||||
Players =
|
Players =
|
||||||
{
|
{
|
||||||
new APIUser { Username = "Hello", Statistics = new UserStatistics { GlobalRank = 12 } },
|
new TournamentPlayer { Username = "Hello", Rank = 12 },
|
||||||
new APIUser { Username = "Hello", Statistics = new UserStatistics { GlobalRank = 16 } },
|
new TournamentPlayer { Username = "Hello", Rank = 16 },
|
||||||
new APIUser { Username = "Hello", Statistics = new UserStatistics { GlobalRank = 20 } },
|
new TournamentPlayer { Username = "Hello", Rank = 20 },
|
||||||
new APIUser { Username = "Hello", Statistics = new UserStatistics { GlobalRank = 24 } },
|
new TournamentPlayer { Username = "Hello", Rank = 24 },
|
||||||
new APIUser { Username = "Hello", Statistics = new UserStatistics { GlobalRank = 30 } },
|
new TournamentPlayer { Username = "Hello", Rank = 30 },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -140,11 +138,11 @@ namespace osu.Game.Tournament.Tests
|
|||||||
FullName = { Value = "United States" },
|
FullName = { Value = "United States" },
|
||||||
Players =
|
Players =
|
||||||
{
|
{
|
||||||
new APIUser { Username = "Hello" },
|
new TournamentPlayer { Username = "Hello" },
|
||||||
new APIUser { Username = "Hello" },
|
new TournamentPlayer { Username = "Hello" },
|
||||||
new APIUser { Username = "Hello" },
|
new TournamentPlayer { Username = "Hello" },
|
||||||
new APIUser { Username = "Hello" },
|
new TournamentPlayer { Username = "Hello" },
|
||||||
new APIUser { Username = "Hello" },
|
new TournamentPlayer { Username = "Hello" },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -7,7 +7,6 @@ using System.Linq;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
|
||||||
using osu.Game.Tournament.Models;
|
using osu.Game.Tournament.Models;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
@ -56,7 +55,7 @@ namespace osu.Game.Tournament.Components
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
TournamentSpriteText createPlayerText(APIUser p) =>
|
TournamentSpriteText createPlayerText(TournamentPlayer p) =>
|
||||||
new TournamentSpriteText
|
new TournamentSpriteText
|
||||||
{
|
{
|
||||||
Text = p.Username,
|
Text = p.Username,
|
||||||
|
@ -7,7 +7,6 @@ using System;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
|
||||||
|
|
||||||
namespace osu.Game.Tournament.Models
|
namespace osu.Game.Tournament.Models
|
||||||
{
|
{
|
||||||
@ -38,7 +37,7 @@ namespace osu.Game.Tournament.Models
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
int[] ranks = Players.Select(p => p.Statistics?.GlobalRank)
|
int[] ranks = Players.Select(p => p.Rank)
|
||||||
.Where(i => i.HasValue)
|
.Where(i => i.HasValue)
|
||||||
.Select(i => i.Value)
|
.Select(i => i.Value)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
@ -59,7 +58,7 @@ namespace osu.Game.Tournament.Models
|
|||||||
};
|
};
|
||||||
|
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public BindableList<APIUser> Players { get; set; } = new BindableList<APIUser>();
|
public BindableList<TournamentPlayer> Players { get; set; } = new BindableList<TournamentPlayer>();
|
||||||
|
|
||||||
public TournamentTeam()
|
public TournamentTeam()
|
||||||
{
|
{
|
||||||
|
@ -15,7 +15,6 @@ using osu.Framework.Graphics.Containers;
|
|||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
|
||||||
using osu.Game.Overlays.Settings;
|
using osu.Game.Overlays.Settings;
|
||||||
using osu.Game.Tournament.Components;
|
using osu.Game.Tournament.Components;
|
||||||
using osu.Game.Tournament.Models;
|
using osu.Game.Tournament.Models;
|
||||||
@ -202,14 +201,14 @@ namespace osu.Game.Tournament.Screens.Editors
|
|||||||
|
|
||||||
public void CreateNew()
|
public void CreateNew()
|
||||||
{
|
{
|
||||||
var user = new APIUser();
|
var player = new TournamentPlayer();
|
||||||
team.Players.Add(user);
|
team.Players.Add(player);
|
||||||
flow.Add(new PlayerRow(team, user));
|
flow.Add(new PlayerRow(team, player));
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PlayerRow : CompositeDrawable
|
public class PlayerRow : CompositeDrawable
|
||||||
{
|
{
|
||||||
private readonly APIUser user;
|
private readonly TournamentPlayer player;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
protected IAPIProvider API { get; private set; }
|
protected IAPIProvider API { get; private set; }
|
||||||
@ -217,13 +216,13 @@ namespace osu.Game.Tournament.Screens.Editors
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private TournamentGameBase game { get; set; }
|
private TournamentGameBase game { get; set; }
|
||||||
|
|
||||||
private readonly Bindable<int?> userId = new Bindable<int?>();
|
private readonly Bindable<int?> playerId = new Bindable<int?>();
|
||||||
|
|
||||||
private readonly Container drawableContainer;
|
private readonly Container drawableContainer;
|
||||||
|
|
||||||
public PlayerRow(TournamentTeam team, APIUser user)
|
public PlayerRow(TournamentTeam team, TournamentPlayer player)
|
||||||
{
|
{
|
||||||
this.user = user;
|
this.player = player;
|
||||||
|
|
||||||
Margin = new MarginPadding(10);
|
Margin = new MarginPadding(10);
|
||||||
|
|
||||||
@ -254,7 +253,7 @@ namespace osu.Game.Tournament.Screens.Editors
|
|||||||
LabelText = "User ID",
|
LabelText = "User ID",
|
||||||
RelativeSizeAxes = Axes.None,
|
RelativeSizeAxes = Axes.None,
|
||||||
Width = 200,
|
Width = 200,
|
||||||
Current = userId,
|
Current = playerId,
|
||||||
},
|
},
|
||||||
drawableContainer = new Container
|
drawableContainer = new Container
|
||||||
{
|
{
|
||||||
@ -272,7 +271,7 @@ namespace osu.Game.Tournament.Screens.Editors
|
|||||||
Action = () =>
|
Action = () =>
|
||||||
{
|
{
|
||||||
Expire();
|
Expire();
|
||||||
team.Players.Remove(user);
|
team.Players.Remove(player);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -281,27 +280,27 @@ namespace osu.Game.Tournament.Screens.Editors
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
userId.Value = user.Id;
|
playerId.Value = player.Id;
|
||||||
userId.BindValueChanged(id =>
|
playerId.BindValueChanged(id =>
|
||||||
{
|
{
|
||||||
user.Id = id.NewValue ?? 0;
|
player.Id = id.NewValue ?? 0;
|
||||||
|
|
||||||
if (id.NewValue != id.OldValue)
|
if (id.NewValue != id.OldValue)
|
||||||
user.Username = string.Empty;
|
player.Username = string.Empty;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(user.Username))
|
if (!string.IsNullOrEmpty(player.Username))
|
||||||
{
|
{
|
||||||
updatePanel();
|
updatePanel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
game.PopulateUser(user, updatePanel, updatePanel);
|
game.PopulatePlayer(player, updatePanel, updatePanel);
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updatePanel()
|
private void updatePanel()
|
||||||
{
|
{
|
||||||
drawableContainer.Child = new UserGridPanel(user) { Width = 300 };
|
drawableContainer.Child = new UserGridPanel(player.ToUser()) { Width = 300 };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,7 +257,7 @@ namespace osu.Game.Tournament.Screens.TeamIntro
|
|||||||
};
|
};
|
||||||
|
|
||||||
foreach (var p in team.Players)
|
foreach (var p in team.Players)
|
||||||
fill.Add(new RowDisplay(p.Username, p.Statistics?.GlobalRank?.ToString("\\##,0") ?? "-"));
|
fill.Add(new RowDisplay(p.Username, p.Rank?.ToString("\\##,0") ?? "-"));
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class RowDisplay : CompositeDrawable
|
internal class RowDisplay : CompositeDrawable
|
||||||
|
@ -22,7 +22,6 @@ using osu.Game.Tournament.IO;
|
|||||||
using osu.Game.Tournament.IPC;
|
using osu.Game.Tournament.IPC;
|
||||||
using osu.Game.Tournament.Models;
|
using osu.Game.Tournament.Models;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
using APIUser = osu.Game.Online.API.Requests.Responses.APIUser;
|
|
||||||
|
|
||||||
namespace osu.Game.Tournament
|
namespace osu.Game.Tournament
|
||||||
{
|
{
|
||||||
@ -187,9 +186,7 @@ namespace osu.Game.Tournament
|
|||||||
{
|
{
|
||||||
var playersRequiringPopulation = ladder.Teams
|
var playersRequiringPopulation = ladder.Teams
|
||||||
.SelectMany(t => t.Players)
|
.SelectMany(t => t.Players)
|
||||||
.Where(p => string.IsNullOrEmpty(p.Username)
|
.Where(p => string.IsNullOrEmpty(p.Username) || p.Rank == null).ToList();
|
||||||
|| p.Statistics?.GlobalRank == null
|
|
||||||
|| p.Statistics?.CountryRank == null).ToList();
|
|
||||||
|
|
||||||
if (playersRequiringPopulation.Count == 0)
|
if (playersRequiringPopulation.Count == 0)
|
||||||
return false;
|
return false;
|
||||||
@ -197,7 +194,7 @@ namespace osu.Game.Tournament
|
|||||||
for (int i = 0; i < playersRequiringPopulation.Count; i++)
|
for (int i = 0; i < playersRequiringPopulation.Count; i++)
|
||||||
{
|
{
|
||||||
var p = playersRequiringPopulation[i];
|
var p = playersRequiringPopulation[i];
|
||||||
PopulateUser(p, immediate: true);
|
PopulatePlayer(p, immediate: true);
|
||||||
updateLoadProgressMessage($"Populating user stats ({i} / {playersRequiringPopulation.Count})");
|
updateLoadProgressMessage($"Populating user stats ({i} / {playersRequiringPopulation.Count})");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,9 +256,9 @@ namespace osu.Game.Tournament
|
|||||||
|
|
||||||
private void updateLoadProgressMessage(string s) => Schedule(() => initialisationText.Text = s);
|
private void updateLoadProgressMessage(string s) => Schedule(() => initialisationText.Text = s);
|
||||||
|
|
||||||
public void PopulateUser(APIUser user, Action success = null, Action failure = null, bool immediate = false)
|
public void PopulatePlayer(TournamentPlayer player, Action success = null, Action failure = null, bool immediate = false)
|
||||||
{
|
{
|
||||||
var req = new GetUserRequest(user.Id, ladder.Ruleset.Value);
|
var req = new GetUserRequest(player.Id, ladder.Ruleset.Value);
|
||||||
|
|
||||||
if (immediate)
|
if (immediate)
|
||||||
{
|
{
|
||||||
@ -273,7 +270,7 @@ namespace osu.Game.Tournament
|
|||||||
req.Success += res => { populate(); };
|
req.Success += res => { populate(); };
|
||||||
req.Failure += _ =>
|
req.Failure += _ =>
|
||||||
{
|
{
|
||||||
user.Id = 1;
|
player.Id = 1;
|
||||||
failure?.Invoke();
|
failure?.Invoke();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -287,12 +284,12 @@ namespace osu.Game.Tournament
|
|||||||
if (res == null)
|
if (res == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
user.Id = res.Id;
|
player.Id = res.Id;
|
||||||
|
|
||||||
user.Username = res.Username;
|
player.Username = res.Username;
|
||||||
user.Statistics = res.Statistics;
|
player.CoverUrl = res.CoverUrl;
|
||||||
user.Country = res.Country;
|
player.Country = res.Country;
|
||||||
user.Cover = res.Cover;
|
player.Rank = res.Statistics?.GlobalRank;
|
||||||
|
|
||||||
success?.Invoke();
|
success?.Invoke();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user