diff --git a/src/components/play/FixtureScoreForm.vue b/src/components/play/FixtureScoreForm.vue index 3494703..d039410 100644 --- a/src/components/play/FixtureScoreForm.vue +++ b/src/components/play/FixtureScoreForm.vue @@ -120,12 +120,11 @@ const updateScores = (finish: boolean) => { isBye: false, })) - flyerStore.updateScores( + const isFinishedEarly = flyerStore.updateScores( currentPhase.value, fixture.value.id, newScores, - finish, - standings.value) + finish) toast.add({ severity: 'success', @@ -135,6 +134,10 @@ const updateScores = (finish: boolean) => { contentStyleClass: isSmallScreen.value ? 'flyer-toast-sm' : '', }) + if (isFinishedEarly) { + flyerStore.finishEarly(currentPhase.value, standings.value) + } + hide() } diff --git a/src/stores/flyer.ts b/src/stores/flyer.ts index 82bc630..db6208b 100644 --- a/src/stores/flyer.ts +++ b/src/stores/flyer.ts @@ -16,7 +16,7 @@ import type { Player } from "@/data/Player" import type { PlayerRecord } from "@/data/PlayerRecord" import type { Round } from "@/data/Round" import { RoundRobinScheduler } from "@/data/RoundRobinScheduler" -import { createPlayOffSettings, Format } from "@/data/Specification" +import { Format, createPlayOffSettings } from "@/data/Specification" import type { Table } from "@/data/Table" import type { TieBreakerInfo } from "@/data/TieBreakerInfo" import { WinnerStaysOnScheduler } from "@/data/WinnerStaysOnScheduler" @@ -246,7 +246,6 @@ export const useFlyerStore = defineStore("flyer", () => { fixtureId: string, scores: Score[], finishFixture: boolean, - currentRanking: PlayerRecord[], addEvent = true, ) => { for (const r of phase.rounds) { @@ -262,9 +261,7 @@ export const useFlyerStore = defineStore("flyer", () => { } if (winsRequiredReached(phase)) { - cancelRemaining() - finishPhase(phase, currentRanking) - return + return true } const winnerId = getWinner(r.fixtures[idx]) @@ -280,6 +277,8 @@ export const useFlyerStore = defineStore("flyer", () => { } } } + + return false } const addTable = (name: string, costPerHour: number) => { @@ -355,6 +354,15 @@ export const useFlyerStore = defineStore("flyer", () => { return false } + const finishEarly = (phase: Phase, ranking: PlayerRecord[]) => { + if (phase.settings.format !== Format.WinnerStaysOn) { + return + } + + cancelRemaining() + finish(ranking) + } + const cancelRemaining = () => { if (!flyer.value) { return @@ -453,9 +461,14 @@ export const useFlyerStore = defineStore("flyer", () => { startFixture(phase, fixture.id, false) updateComment(phase, fixture.id, "AUTO-COMPLETED") - updateScores(phase, fixture.id, newScores, true, currentRanking, false) + + const isFinishedEarly = updateScores(phase, fixture.id, newScores, true, false) addPhaseEvent(phase, `Fixture ${fixture.id} was auto-completed.`, PhaseEventLevel.Internal) + + if (isFinishedEarly) { + finishEarly(phase, currentRanking) + } } const autoCompletePhase = ( @@ -518,6 +531,7 @@ export const useFlyerStore = defineStore("flyer", () => { updateScores, addTable, generateRound, + finishEarly, finishPhase, cancelRemaining, addPlayOff,