feat: support double-elimination series games
This commit is contained in:
1 parent
2ee8c3807b
commit
e188828423
16 files changed
+1176
-234
No files matched your search
@@ -34,6 +34,7 @@ const MATCH_SHORT_CODE_GENERATION_ATTEMPTS = 20;
|
||||
const DEFAULT_MATCH_LIST_LIMIT = 50;
|
||||
const MAX_MATCH_LIST_LIMIT = 200;
|
||||
const DOUBLE_ELIMINATION_PARTICIPANT_COUNTS = [20, 40] as const;
|
||||
const DEFAULT_DOUBLE_ELIMINATION_SERIES_GAME_COUNT = 3;
|
||||
|
||||
interface DoubleEliminationConfigInput {
|
||||
doubleEliminationResetFinalEnabled?: boolean;
|
||||
@@ -109,21 +110,18 @@ interface DoubleEliminationAdminParams {
|
||||
actorUserId: mongoose.Types.ObjectId;
|
||||
}
|
||||
|
||||
interface SwapDoubleEliminationSeedsParams
|
||||
extends DoubleEliminationAdminParams {
|
||||
interface SwapDoubleEliminationSeedsParams extends DoubleEliminationAdminParams {
|
||||
leftSeedNumber: number;
|
||||
rightSeedNumber: number;
|
||||
}
|
||||
|
||||
interface ApplyDoubleEliminationWalkoverParams
|
||||
extends DoubleEliminationAdminParams {
|
||||
interface ApplyDoubleEliminationWalkoverParams extends DoubleEliminationAdminParams {
|
||||
bracketMatchId: string;
|
||||
winnerTeamIndex: number;
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
interface CancelDoubleEliminationActionParams
|
||||
extends DoubleEliminationAdminParams {
|
||||
interface CancelDoubleEliminationActionParams extends DoubleEliminationAdminParams {
|
||||
bracketMatchId: string;
|
||||
reason?: string;
|
||||
}
|
||||
@@ -529,9 +527,9 @@ export class MatchService {
|
||||
return await this.throwJoinFailure(MatchModel, params.matchId, user);
|
||||
}
|
||||
|
||||
private normalizeMatchConfig<T extends Partial<Match> & DoubleEliminationConfigInput>(
|
||||
input: T,
|
||||
): Partial<Match> {
|
||||
private normalizeMatchConfig<
|
||||
T extends Partial<Match> & DoubleEliminationConfigInput,
|
||||
>(input: T): Partial<Match> {
|
||||
const patch = this.stripMatchConfigInput(input);
|
||||
const gameMode = (patch.gameMode ?? 'pair') as MatchGameMode;
|
||||
const maxParticipants = patch.maxParticipants ?? 10;
|
||||
@@ -550,7 +548,9 @@ export class MatchService {
|
||||
...patch,
|
||||
gameMode,
|
||||
maxParticipants,
|
||||
gameCount: 1,
|
||||
gameCount: this.normalizeDoubleEliminationSeriesGameCount(
|
||||
patch.gameCount ?? DEFAULT_DOUBLE_ELIMINATION_SERIES_GAME_COUNT,
|
||||
),
|
||||
roundRobinMaxRounds: undefined,
|
||||
gameSchedule: [],
|
||||
doubleElimination: {
|
||||
@@ -575,13 +575,20 @@ export class MatchService {
|
||||
};
|
||||
}
|
||||
|
||||
private stripMatchConfigInput<T extends Partial<Match> & DoubleEliminationConfigInput>(
|
||||
input: T,
|
||||
): Partial<Match> {
|
||||
private stripMatchConfigInput<
|
||||
T extends Partial<Match> & DoubleEliminationConfigInput,
|
||||
>(input: T): Partial<Match> {
|
||||
const { doubleEliminationResetFinalEnabled: _ignored, ...patch } = input;
|
||||
return patch;
|
||||
}
|
||||
|
||||
private normalizeDoubleEliminationSeriesGameCount(gameCount: number): number {
|
||||
if (!Number.isInteger(gameCount) || gameCount < 1) {
|
||||
return DEFAULT_DOUBLE_ELIMINATION_SERIES_GAME_COUNT;
|
||||
}
|
||||
return gameCount % 2 === 0 ? gameCount + 1 : gameCount;
|
||||
}
|
||||
|
||||
private async loadDoubleEliminationMatch(params: {
|
||||
matchId: mongoose.Types.ObjectId;
|
||||
communityId: mongoose.Types.ObjectId;
|
||||
@@ -836,7 +843,10 @@ export class MatchService {
|
||||
private async throwJoinFailure(
|
||||
MatchModel: mongoose.Model<Match>,
|
||||
matchId: mongoose.Types.ObjectId,
|
||||
user: { _id: mongoose.Types.ObjectId; communityId: mongoose.Types.ObjectId },
|
||||
user: {
|
||||
_id: mongoose.Types.ObjectId;
|
||||
communityId: mongoose.Types.ObjectId;
|
||||
},
|
||||
): Promise<never> {
|
||||
const match = await MatchModel.findById(matchId);
|
||||
if (!match) throw new NotFoundException('Match not found.');
|
||||
@@ -864,7 +874,10 @@ export class MatchService {
|
||||
private async throwCancelJoinFailure(
|
||||
MatchModel: mongoose.Model<Match>,
|
||||
matchId: mongoose.Types.ObjectId,
|
||||
user: { _id: mongoose.Types.ObjectId; communityId: mongoose.Types.ObjectId },
|
||||
user: {
|
||||
_id: mongoose.Types.ObjectId;
|
||||
communityId: mongoose.Types.ObjectId;
|
||||
},
|
||||
): Promise<never> {
|
||||
const match = await MatchModel.findById(matchId);
|
||||
if (!match) throw new NotFoundException('Match not found.');
|
||||
|
||||
Reference in new issue
Block a user