Skip to content

Commit

Permalink
only update first/last turn end dates when not skipping or undoing
Browse files Browse the repository at this point in the history
  • Loading branch information
mrosack committed Jan 3, 2024
1 parent 6fa6189 commit b960f99
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/util/statsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,22 @@ export class StatsUtil {
const undoInc = undo ? -1 : 1;

if (gameTurn.endDate) {
if (!turnData.firstTurnEndDate || gameTurn.endDate < turnData.firstTurnEndDate) {
turnData.firstTurnEndDate = gameTurn.endDate;
}

if (!turnData.lastTurnEndDate || gameTurn.endDate > turnData.lastTurnEndDate) {
turnData.lastTurnEndDate = gameTurn.endDate;
}

turnData.turnLengthBuckets = turnData.turnLengthBuckets || {};
turnData.yearBuckets = turnData.yearBuckets || {};

if (gameTurn.skipped) {
turnData.turnsSkipped = (turnData.turnsSkipped || 0) + undoInc;
} else {
if (!undo) {
if (!turnData.firstTurnEndDate || gameTurn.endDate < turnData.firstTurnEndDate) {
turnData.firstTurnEndDate = gameTurn.endDate;
}

if (!turnData.lastTurnEndDate || gameTurn.endDate > turnData.lastTurnEndDate) {
turnData.lastTurnEndDate = gameTurn.endDate;
}
}

turnData.turnsPlayed = (turnData.turnsPlayed || 0) + undoInc;

const timeTaken = gameTurn.endDate.getTime() - gameTurn.startDate.getTime();
Expand Down

0 comments on commit b960f99

Please sign in to comment.