sendou.ink/app/modules/brackets-manager/reset.ts
Kalle f19ec211d8
Swiss bracket format (#1723)
* Initial

* Swiss UI initial

* Start Swiss bracket

* Match up generation skeleton

* Bracket advancing

* Misc

* Progress

* Remove unneeded script

* Timed bans feature

* Add badge

* Add tournament logo

* Add Heavy Splatling MoveSpeed_Charge Closes #1461

* Require verified email for new account registration

* Weapon stats/builds use absolute URL

* Allow mod to ban users

* Prevent app from crashing on unhandled rejection

Context: https://github.com/remix-run/remix/issues/9178#issuecomment-2032102431

* Try changing authenticate call to match docs example

* Limit fresh account queue joining

* Fix tournament avatar not showing

* Limit when weapon shown on leaderboard

* Nuke reported weapons script

* FC scripts

* Increase tournament rules max length

* Add Discord URL to tournament page

* Hotfix reopen

* Fix matchAffectsAnotherBracket logic better

* Switch to Patreon API v2 Closes #1389

Also fixes problem with people who canceled not
getting access.

* Fix reset showing for first round

* Dropping out

* Progress

* Range inputs

* better way to create rounds

* Fix TODO

* E2E test

* Small round count info text

* Fix lint
2024-04-21 22:45:33 +03:00

64 lines
1.7 KiB
TypeScript

import { Status } from "~/modules/brackets-model";
import { BaseUpdater } from "./base/updater";
import * as helpers from "./helpers";
export class Reset extends BaseUpdater {
/**
* Resets the results of a match.
*
* This will update related matches accordingly.
*
* @param matchId ID of the match.
*/
public matchResults(matchId: number): void {
const stored = this.storage.select("match", matchId);
if (!stored) throw Error("Match not found.");
const stage = this.storage.select("stage", stored.stage_id);
if (!stage) throw Error("Stage not found.");
const group = this.storage.select("group", stored.group_id);
if (!group) throw Error("Group not found.");
const { roundNumber, roundCount } = this.getRoundPositionalInfo(
stored.round_id,
);
const matchLocation = helpers.getMatchLocation(stage.type, group.number);
const nextMatches =
stage.type !== "round_robin" && stage.type !== "swiss"
? this.getNextMatches(
stored,
matchLocation,
stage,
roundNumber,
roundCount,
)
: [];
if (
nextMatches.some(
(match) =>
match &&
match.status >= Status.Running &&
!helpers.isMatchByeCompleted(match),
)
)
throw Error("The match is locked.");
helpers.resetMatchResults(stored);
this.applyMatchUpdate(stored);
if (!helpers.isRoundRobin(stage) && !helpers.isSwiss(stage))
this.updateRelatedMatches(stored, true, true);
}
/**
* Resets the seeding of a stage.
*
* @param stageId ID of the stage.
*/
public seeding(stageId: number): void {
this.updateSeeding(stageId, null);
}
}