diff --git a/README.md b/README.md index 553a0d6..8d9b4a5 100644 --- a/README.md +++ b/README.md @@ -44,10 +44,7 @@ cd /var/www/doko wget https://github.com/uncaught/doko/archive/v1.3.0.tar.gz tar xf v1.3.0.tar.gz cd doko-1.3.0 -./yarn.sh common install -./yarn.sh client install -./yarn.sh server install -./yarn.sh client build +./yarn.sh common install && ./yarn.sh client install && ./yarn.sh server install && ./yarn.sh client build cd .. ./backup.sh docker-compose down diff --git a/client/src/store/Games.ts b/client/src/store/Games.ts index d29ce24..ab64f3e 100644 --- a/client/src/store/Games.ts +++ b/client/src/store/Games.ts @@ -129,7 +129,7 @@ export function useAddGame() { const players = roundParticipatingPlayers.filter((p) => p.leftAfterGameNumber === null); const nextDealerId = lastGame ? getNextDealer(players, lastGame) : players[0].groupMemberId; const data = getDefaultGameData(settings); - data.runNumber = detectRunNumber(currentGames, nextDealerId); + data.runNumber = detectRunNumber(currentGames, nextDealerId, roundParticipatingPlayers); detectPlayers(data, nextDealerId, players); detectBockGame(round.data, data, currentGames, nextDealerId); detectLastGameAndForcedSolo(round.data, data, currentGames, nextDealerId, players, playersWithStats); diff --git a/client/src/store/Games/DetectRunNumber.ts b/client/src/store/Games/DetectRunNumber.ts index 5e7d9e0..d02f1f3 100644 --- a/client/src/store/Games/DetectRunNumber.ts +++ b/client/src/store/Games/DetectRunNumber.ts @@ -1,21 +1,23 @@ -import {Game} from '@doko/common'; +import {Game, Player} from '@doko/common'; export function detectRunNumber( sortedGames: Game[], newGameDealerId: string, + roundParticipatingPlayers: Player[], ): number { + const roundParticipatingPlayerIds = roundParticipatingPlayers.map(({groupMemberId}) => groupMemberId); + const newGameDealerRoundIndex = roundParticipatingPlayerIds.indexOf(newGameDealerId); let runNumber = 1; if (sortedGames.length) { - const firstDealer = sortedGames[0].dealerGroupMemberId; - let lastDealer = firstDealer; - - sortedGames.forEach(({gameNumber, data, dealerGroupMemberId}, idx) => { - if (dealerGroupMemberId === firstDealer && lastDealer !== firstDealer) { + let lastDealerRoundIndex = 0; + sortedGames.forEach(({dealerGroupMemberId}) => { + const dealerRoundIndex = roundParticipatingPlayerIds.indexOf(dealerGroupMemberId); + if (dealerRoundIndex < lastDealerRoundIndex) { runNumber++; } - lastDealer = dealerGroupMemberId; + lastDealerRoundIndex = dealerRoundIndex; }); - if (newGameDealerId === firstDealer && lastDealer !== firstDealer) { + if (newGameDealerRoundIndex < lastDealerRoundIndex) { runNumber++; } } diff --git a/server/src/database/migrations/Version004.ts b/server/src/database/migrations/Version004.ts new file mode 100644 index 0000000..6d5bbd4 --- /dev/null +++ b/server/src/database/migrations/Version004.ts @@ -0,0 +1,30 @@ +import {query} from '../../Connection'; + +async function fixBrokenRoundNumbers(update: typeof query) { + await update(`update rounds set data = JSON_REPLACE(data, '$.roundDuration', 7) +where id = '0fe83345-4b63-42fd-b960-5a9ee008ea7e'`); + + await update(`update games set data = JSON_REPLACE(data, '$.runNumber', 6) +where id IN ( +'c9978373-d63e-472e-a1a9-95f0334d4f24', +'d8e1f301-ad5e-461a-8c98-8f1d21766e13', +'d492906f-e795-4da3-874d-9d8d7700b85e', +'1a354f45-08a4-4dd9-9149-9b9d35f7c77e' +)`); + + await update(`update games set data = JSON_REPLACE(data, '$.runNumber', 7) +where id IN ( +'8f0d82ce-14d3-41b9-9358-3f8170da2a80', +'8f6be680-674f-420a-9c66-91f141fbcda4', +'5c1ed61b-f0c9-43b7-86e0-2ad205735685', +'ff13004f-3185-4171-a028-7e6cc7eb3758' +)`); + + await update(`update games set data = JSON_REPLACE(data, '$.isLastGame', TRUE) +where id ='ff13004f-3185-4171-a028-7e6cc7eb3758'`); +} + +export async function run(update: typeof query) { + console.log(`Running 004 ...`); + await fixBrokenRoundNumbers(update); +}