Updated player receiving logic

This commit is contained in:
2026-03-06 20:59:04 +01:00
parent cff95aff00
commit 598b8d0f9e

View File

@@ -40,12 +40,13 @@ class MatchTile extends StatefulWidget {
} }
class _MatchTileState extends State<MatchTile> { class _MatchTileState extends State<MatchTile> {
late final List<Player> _allPlayers; late List<Player> _allPlayers;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_allPlayers = _getCombinedPlayers(); _allPlayers = [...widget.match.players];
_allPlayers.sort((a, b) => a.name.compareTo(b.name));
} }
@override @override
@@ -93,7 +94,7 @@ class _MatchTileState extends State<MatchTile> {
const SizedBox(width: 6), const SizedBox(width: 6),
Expanded( Expanded(
child: Text( child: Text(
'${group.name} + ${widget.match.players.length}', '${group.name}${getExtraPlayerCount()}',
style: const TextStyle(fontSize: 14, color: Colors.grey), style: const TextStyle(fontSize: 14, color: Colors.grey),
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
@@ -236,21 +237,23 @@ class _MatchTileState extends State<MatchTile> {
} }
} }
/// Retrieves all unique players associated with the match, /// Counts how many players in the match are not part of the group
/// combining players from both the match and its group. /// Returns the count as a string, or an empty string if there is no group
List<Player> _getCombinedPlayers() { String getExtraPlayerCount() {
final allPlayers = <Player>[]; int count = 0;
final playerIds = <String>{};
// Add players from game.players final groupMembers = widget.match.group!.members;
for (var player in widget.match.players) { final players = widget.match.players;
if (!playerIds.contains(player.id)) {
allPlayers.add(player); for (var player in players) {
playerIds.add(player.id); if (!groupMembers.any((member) => member.id == player.id)) {
count++;
} }
} }
allPlayers.sort((a, b) => a.name.compareTo(b.name)); if (count == 0) {
return allPlayers; return '';
}
return ' + ${count.toString()}';
} }
} }