Updated function _getSortedPlayerIndices()

This commit is contained in:
2025-07-14 11:14:22 +02:00
parent f8bbbb04f3
commit 4a0ce067b5

View File

@@ -32,7 +32,10 @@ class _ActiveGameViewState extends State<ActiveGameView> {
return ListenableBuilder( return ListenableBuilder(
listenable: gameSession, listenable: gameSession,
builder: (context, _) { builder: (context, _) {
List<int> sortedPlayerIndices = _getSortedPlayerIndices(); List<int> playerIndices =
List<int>.generate(gameSession.players.length, (index) => index);
List<int> sortedPlayerIndices =
_getSortedPlayerIndices(playerIndices);
return CupertinoPageScaffold( return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar( navigationBar: CupertinoNavigationBar(
middle: Text(gameSession.gameTitle), middle: Text(gameSession.gameTitle),
@@ -260,9 +263,7 @@ class _ActiveGameViewState extends State<ActiveGameView> {
/// Returns a list of player indices sorted by their scores in /// Returns a list of player indices sorted by their scores in
/// ascending order. /// ascending order.
List<int> _getSortedPlayerIndices() { List<int> _getSortedPlayerIndices(List<int> playerIndices) {
List<int> playerIndices =
List<int>.generate(gameSession.players.length, (index) => index);
// Sort the indices based on the summed points // Sort the indices based on the summed points
playerIndices.sort((a, b) { playerIndices.sort((a, b) {
int scoreA = gameSession.playerScores[a]; int scoreA = gameSession.playerScores[a];
@@ -285,7 +286,7 @@ class _ActiveGameViewState extends State<ActiveGameView> {
/// Calculates the dense rank for a player based on their index in the sorted list of players. /// Calculates the dense rank for a player based on their index in the sorted list of players.
int _calculateDenseRank(int index, List<int> playerScores) { int _calculateDenseRank(int index, List<int> playerScores) {
List<int> sortedIndices = _getSortedPlayerIndices(); List<int> sortedIndices = _getSortedPlayerIndices(playerScores);
List<int> denseRanks = []; List<int> denseRanks = [];
int rank = 1; int rank = 1;
for (int i = 0; i < sortedIndices.length; i++) { for (int i = 0; i < sortedIndices.length; i++) {