Skip to content

Commit

Permalink
fix(common): updateClassificationPoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustl22 committed Nov 27, 2023
1 parent 28f04b7 commit d412da9
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions wrestling_scoreboard_common/lib/src/data/fight.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ class Fight with _$Fight implements DataObject {
);
}

void updateClassificationPoints(List<FightAction> actions, {bool isTournament = false}) {
Fight updateClassificationPoints(List<FightAction> actions, {bool isTournament = false}) {
if (result != null && winnerRole != null) {
var winner = winnerRole == FightRole.red ? r : b;
var looser = winnerRole == FightRole.red ? b : r;

int? winnerClassificationPoints;
int? looserClassificationPoints;
if (winner != null) {
winner.classificationPoints = isTournament
winnerClassificationPoints = isTournament
? getClassificationPointsWinnerTournament(result!)
: getClassificationPointsWinnerTeamMatch(
result!,
Expand All @@ -75,13 +77,23 @@ class Fight with _$Fight implements DataObject {
}

if (looser != null) {
looser.classificationPoints = isTournament
looserClassificationPoints = isTournament
? getClassificationPointsLooserTournament(result!)
: getClassificationPointsLooserTeamMatch(result!);
}
return copyWith(
r: r?.copyWith(
classificationPoints: winnerRole == FightRole.red ? winnerClassificationPoints : looserClassificationPoints,
),
b: b?.copyWith(
classificationPoints: winnerRole == FightRole.blue ? winnerClassificationPoints : looserClassificationPoints,
),
);
} else {
r?.classificationPoints = null;
b?.classificationPoints = null;
return copyWith(
r: r?.copyWith(classificationPoints: null),
b: b?.copyWith(classificationPoints: null),
);
}
}

Expand Down

0 comments on commit d412da9

Please sign in to comment.