feat: add double elimination match mode
This commit is contained in:
1 parent
b9aaf55193
commit
e12f182e7f
19 files changed
+3415
-58
No files matched your search
@@ -32,11 +32,16 @@ export const MATCH_STATUSES: MatchStatus[] = [
|
||||
export type TeamSide = 'blue' | 'red';
|
||||
export const TEAM_SIDES: TeamSide[] = ['blue', 'red'];
|
||||
|
||||
export type MatchGameMode = 'pair' | 'bracket' | 'round-robin';
|
||||
export type MatchGameMode =
|
||||
| 'pair'
|
||||
| 'bracket'
|
||||
| 'round-robin'
|
||||
| 'double-elimination';
|
||||
export const MATCH_GAME_MODES: MatchGameMode[] = [
|
||||
'pair',
|
||||
'bracket',
|
||||
'round-robin',
|
||||
'double-elimination',
|
||||
];
|
||||
|
||||
export type CommunityRole = 'owner' | 'admin' | 'member';
|
||||
@@ -47,13 +52,15 @@ export type TournamentCodeState =
|
||||
| 'reserved'
|
||||
| 'used'
|
||||
| 'expired'
|
||||
| 'released';
|
||||
| 'released'
|
||||
| 'voided';
|
||||
export const TOURNAMENT_CODE_STATES: TournamentCodeState[] = [
|
||||
'available',
|
||||
'reserved',
|
||||
'used',
|
||||
'expired',
|
||||
'released',
|
||||
'voided',
|
||||
];
|
||||
export type TournamentMapType = 'SUMMONERS_RIFT';
|
||||
export const TOURNAMENT_MAP_TYPES: TournamentMapType[] = ['SUMMONERS_RIFT'];
|
||||
@@ -445,6 +452,7 @@ export interface TournamentCode extends MongooseTimestamps {
|
||||
state: TournamentCodeState;
|
||||
matchId?: mongoose.Types.ObjectId;
|
||||
gameNumber?: number;
|
||||
bracketMatchId?: string;
|
||||
reservedAt?: Date;
|
||||
usedAt?: Date;
|
||||
releasedAt?: Date;
|
||||
@@ -497,6 +505,7 @@ export interface MatchGameResultParticipant {
|
||||
|
||||
export interface MatchGameResult {
|
||||
gameNumber: number;
|
||||
bracketMatchId?: string;
|
||||
riotMatchId: string;
|
||||
blueTeamIndex: number;
|
||||
redTeamIndex: number;
|
||||
@@ -508,6 +517,7 @@ export interface MatchGameResult {
|
||||
}
|
||||
|
||||
export interface MatchSeriesResult {
|
||||
bracketMatchId?: string;
|
||||
teamAIndex: number;
|
||||
teamBIndex: number;
|
||||
teamAWins: number;
|
||||
@@ -515,6 +525,118 @@ export interface MatchSeriesResult {
|
||||
winnerTeamIndex?: number;
|
||||
}
|
||||
|
||||
export type DoubleEliminationBracketSide =
|
||||
| 'winner'
|
||||
| 'loser'
|
||||
| 'grand-final'
|
||||
| 'reset-final';
|
||||
export const DOUBLE_ELIMINATION_BRACKET_SIDES: DoubleEliminationBracketSide[] =
|
||||
['winner', 'loser', 'grand-final', 'reset-final'];
|
||||
|
||||
export type DoubleEliminationBracketMatchState =
|
||||
| 'pending'
|
||||
| 'ready'
|
||||
| 'completed';
|
||||
export const DOUBLE_ELIMINATION_BRACKET_MATCH_STATES: DoubleEliminationBracketMatchState[] =
|
||||
['pending', 'ready', 'completed'];
|
||||
|
||||
export type DoubleEliminationCompletionType = 'riot-result' | 'walkover';
|
||||
export const DOUBLE_ELIMINATION_COMPLETION_TYPES: DoubleEliminationCompletionType[] =
|
||||
['riot-result', 'walkover'];
|
||||
|
||||
export type DoubleEliminationEventType =
|
||||
| 'bracket-created'
|
||||
| 'seeds-reshuffled'
|
||||
| 'seeds-swapped'
|
||||
| 'bracket-match-completed'
|
||||
| 'bracket-match-cancelled'
|
||||
| 'walkover-awarded'
|
||||
| 'walkover-cancelled'
|
||||
| 'reset-final-created'
|
||||
| 'riot-result-cancelled';
|
||||
export const DOUBLE_ELIMINATION_EVENT_TYPES: DoubleEliminationEventType[] = [
|
||||
'bracket-created',
|
||||
'seeds-reshuffled',
|
||||
'seeds-swapped',
|
||||
'bracket-match-completed',
|
||||
'bracket-match-cancelled',
|
||||
'walkover-awarded',
|
||||
'walkover-cancelled',
|
||||
'reset-final-created',
|
||||
'riot-result-cancelled',
|
||||
];
|
||||
|
||||
export interface DoubleEliminationSeed {
|
||||
seedNumber: number;
|
||||
teamIndex: number;
|
||||
}
|
||||
|
||||
export interface DoubleEliminationBracketMatchSource {
|
||||
type: 'seed' | 'winner' | 'loser';
|
||||
seedNumber?: number;
|
||||
bracketMatchId?: string;
|
||||
}
|
||||
|
||||
export interface DoubleEliminationBracketMatchDestination {
|
||||
bracketMatchId: string;
|
||||
position: 'A' | 'B';
|
||||
}
|
||||
|
||||
export interface DoubleEliminationWalkover {
|
||||
winnerTeamIndex: number;
|
||||
reason?: string;
|
||||
awardedBy?: mongoose.Types.ObjectId;
|
||||
awardedAt: Date;
|
||||
cancelledBy?: mongoose.Types.ObjectId;
|
||||
cancelledAt?: Date;
|
||||
cancelReason?: string;
|
||||
active: boolean;
|
||||
}
|
||||
|
||||
export interface DoubleEliminationBracketMatch {
|
||||
bracketMatchId: string;
|
||||
gameNumber: number;
|
||||
bracketSide: DoubleEliminationBracketSide;
|
||||
roundNumber: number;
|
||||
matchNumber: number;
|
||||
state: DoubleEliminationBracketMatchState;
|
||||
teamAIndex?: number;
|
||||
teamBIndex?: number;
|
||||
teamASource?: DoubleEliminationBracketMatchSource;
|
||||
teamBSource?: DoubleEliminationBracketMatchSource;
|
||||
winnerAdvancesTo?: DoubleEliminationBracketMatchDestination;
|
||||
loserAdvancesTo?: DoubleEliminationBracketMatchDestination;
|
||||
winnerTeamIndex?: number;
|
||||
loserTeamIndex?: number;
|
||||
completedBy?: DoubleEliminationCompletionType;
|
||||
completedAt?: Date;
|
||||
walkover?: DoubleEliminationWalkover;
|
||||
}
|
||||
|
||||
export interface DoubleEliminationPlacements {
|
||||
firstTeamIndex?: number;
|
||||
secondTeamIndex?: number;
|
||||
thirdTeamIndex?: number;
|
||||
}
|
||||
|
||||
export interface DoubleEliminationEvent {
|
||||
type: DoubleEliminationEventType;
|
||||
bracketMatchId?: string;
|
||||
actorUserId?: mongoose.Types.ObjectId;
|
||||
reason?: string;
|
||||
createdAt: Date;
|
||||
}
|
||||
|
||||
export interface DoubleEliminationBracket {
|
||||
teamCount: 4 | 8;
|
||||
resetFinalEnabled: boolean;
|
||||
resetFinalCreated: boolean;
|
||||
seeds: DoubleEliminationSeed[];
|
||||
bracketMatches: DoubleEliminationBracketMatch[];
|
||||
placements: DoubleEliminationPlacements;
|
||||
events: DoubleEliminationEvent[];
|
||||
}
|
||||
|
||||
export interface MatchGameAssignment {
|
||||
gameNumber: number;
|
||||
roundNumber?: number;
|
||||
@@ -564,6 +686,7 @@ export interface Match extends MongooseTimestamps {
|
||||
teams: MatchTeam[];
|
||||
result?: MatchResult;
|
||||
resultPollState?: MatchResultPollState;
|
||||
doubleElimination?: DoubleEliminationBracket;
|
||||
legacyImported?: boolean;
|
||||
legacyImportSource?: {
|
||||
importedAt: Date;
|
||||
@@ -1351,6 +1474,7 @@ export const TournamentCodeSchema = new Schema<TournamentCode>(
|
||||
},
|
||||
matchId: { type: Schema.Types.ObjectId, ref: 'match' },
|
||||
gameNumber: { type: Number },
|
||||
bracketMatchId: { type: String },
|
||||
reservedAt: { type: Date },
|
||||
usedAt: { type: Date },
|
||||
releasedAt: { type: Date },
|
||||
@@ -1369,6 +1493,7 @@ export const TournamentCodeSchema = new Schema<TournamentCode>(
|
||||
TournamentCodeSchema.index({ code: 1 }, { unique: true });
|
||||
TournamentCodeSchema.index({ state: 1, expiresAt: 1 });
|
||||
TournamentCodeSchema.index({ matchId: 1, gameNumber: 1 });
|
||||
TournamentCodeSchema.index({ matchId: 1, bracketMatchId: 1 }, { sparse: true });
|
||||
TournamentCodeSchema.index({ state: 1, uploadedAt: -1 });
|
||||
TournamentCodeSchema.index({ riotMatchId: 1 }, { sparse: true });
|
||||
|
||||
@@ -1428,6 +1553,7 @@ const MatchGameResultParticipantSubSchema =
|
||||
const MatchGameResultSubSchema = new Schema<MatchGameResult>(
|
||||
{
|
||||
gameNumber: { type: Number, required: true },
|
||||
bracketMatchId: { type: String, required: false },
|
||||
riotMatchId: { type: String, required: true },
|
||||
blueTeamIndex: { type: Number, required: true, min: 1 },
|
||||
redTeamIndex: { type: Number, required: true, min: 1 },
|
||||
@@ -1446,6 +1572,7 @@ const MatchGameResultSubSchema = new Schema<MatchGameResult>(
|
||||
|
||||
const MatchSeriesResultSubSchema = new Schema<MatchSeriesResult>(
|
||||
{
|
||||
bracketMatchId: { type: String, required: false },
|
||||
teamAIndex: { type: Number, required: true, min: 1 },
|
||||
teamBIndex: { type: Number, required: true, min: 1 },
|
||||
teamAWins: { type: Number, required: true, default: 0 },
|
||||
@@ -1465,6 +1592,158 @@ const MatchGameAssignmentSubSchema = new Schema<MatchGameAssignment>(
|
||||
{ _id: false },
|
||||
);
|
||||
|
||||
const DoubleEliminationSeedSubSchema = new Schema<DoubleEliminationSeed>(
|
||||
{
|
||||
seedNumber: { type: Number, required: true, min: 1 },
|
||||
teamIndex: { type: Number, required: true, min: 1 },
|
||||
},
|
||||
{ _id: false },
|
||||
);
|
||||
|
||||
const DoubleEliminationBracketMatchSourceSubSchema =
|
||||
new Schema<DoubleEliminationBracketMatchSource>(
|
||||
{
|
||||
type: {
|
||||
type: String,
|
||||
enum: ['seed', 'winner', 'loser'],
|
||||
required: true,
|
||||
},
|
||||
seedNumber: { type: Number, required: false, min: 1 },
|
||||
bracketMatchId: { type: String, required: false },
|
||||
},
|
||||
{ _id: false },
|
||||
);
|
||||
|
||||
const DoubleEliminationBracketMatchDestinationSubSchema =
|
||||
new Schema<DoubleEliminationBracketMatchDestination>(
|
||||
{
|
||||
bracketMatchId: { type: String, required: true },
|
||||
position: { type: String, enum: ['A', 'B'], required: true },
|
||||
},
|
||||
{ _id: false },
|
||||
);
|
||||
|
||||
const DoubleEliminationWalkoverSubSchema =
|
||||
new Schema<DoubleEliminationWalkover>(
|
||||
{
|
||||
winnerTeamIndex: { type: Number, required: true, min: 1 },
|
||||
reason: { type: String, required: false },
|
||||
awardedBy: { type: Schema.Types.ObjectId, ref: 'user' },
|
||||
awardedAt: { type: Date, required: true },
|
||||
cancelledBy: { type: Schema.Types.ObjectId, ref: 'user' },
|
||||
cancelledAt: { type: Date },
|
||||
cancelReason: { type: String },
|
||||
active: { type: Boolean, required: true, default: true },
|
||||
},
|
||||
{ _id: false },
|
||||
);
|
||||
|
||||
const DoubleEliminationBracketMatchSubSchema =
|
||||
new Schema<DoubleEliminationBracketMatch>(
|
||||
{
|
||||
bracketMatchId: { type: String, required: true },
|
||||
gameNumber: { type: Number, required: true, min: 1 },
|
||||
bracketSide: {
|
||||
type: String,
|
||||
enum: DOUBLE_ELIMINATION_BRACKET_SIDES,
|
||||
required: true,
|
||||
},
|
||||
roundNumber: { type: Number, required: true, min: 1 },
|
||||
matchNumber: { type: Number, required: true, min: 1 },
|
||||
state: {
|
||||
type: String,
|
||||
enum: DOUBLE_ELIMINATION_BRACKET_MATCH_STATES,
|
||||
required: true,
|
||||
},
|
||||
teamAIndex: { type: Number, required: false, min: 1 },
|
||||
teamBIndex: { type: Number, required: false, min: 1 },
|
||||
teamASource: {
|
||||
type: DoubleEliminationBracketMatchSourceSubSchema,
|
||||
required: false,
|
||||
},
|
||||
teamBSource: {
|
||||
type: DoubleEliminationBracketMatchSourceSubSchema,
|
||||
required: false,
|
||||
},
|
||||
winnerAdvancesTo: {
|
||||
type: DoubleEliminationBracketMatchDestinationSubSchema,
|
||||
required: false,
|
||||
},
|
||||
loserAdvancesTo: {
|
||||
type: DoubleEliminationBracketMatchDestinationSubSchema,
|
||||
required: false,
|
||||
},
|
||||
winnerTeamIndex: { type: Number, required: false, min: 1 },
|
||||
loserTeamIndex: { type: Number, required: false, min: 1 },
|
||||
completedBy: {
|
||||
type: String,
|
||||
enum: DOUBLE_ELIMINATION_COMPLETION_TYPES,
|
||||
required: false,
|
||||
},
|
||||
completedAt: { type: Date, required: false },
|
||||
walkover: {
|
||||
type: DoubleEliminationWalkoverSubSchema,
|
||||
required: false,
|
||||
},
|
||||
},
|
||||
{ _id: false },
|
||||
);
|
||||
|
||||
const DoubleEliminationPlacementsSubSchema =
|
||||
new Schema<DoubleEliminationPlacements>(
|
||||
{
|
||||
firstTeamIndex: { type: Number, required: false, min: 1 },
|
||||
secondTeamIndex: { type: Number, required: false, min: 1 },
|
||||
thirdTeamIndex: { type: Number, required: false, min: 1 },
|
||||
},
|
||||
{ _id: false },
|
||||
);
|
||||
|
||||
const DoubleEliminationEventSubSchema = new Schema<DoubleEliminationEvent>(
|
||||
{
|
||||
type: {
|
||||
type: String,
|
||||
enum: DOUBLE_ELIMINATION_EVENT_TYPES,
|
||||
required: true,
|
||||
},
|
||||
bracketMatchId: { type: String, required: false },
|
||||
actorUserId: { type: Schema.Types.ObjectId, ref: 'user' },
|
||||
reason: { type: String, required: false },
|
||||
createdAt: { type: Date, required: true },
|
||||
},
|
||||
{ _id: false },
|
||||
);
|
||||
|
||||
const DoubleEliminationBracketSubSchema =
|
||||
new Schema<DoubleEliminationBracket>(
|
||||
{
|
||||
teamCount: { type: Number, enum: [4, 8], required: true },
|
||||
resetFinalEnabled: { type: Boolean, required: true, default: false },
|
||||
resetFinalCreated: { type: Boolean, required: true, default: false },
|
||||
seeds: {
|
||||
type: [DoubleEliminationSeedSubSchema],
|
||||
required: true,
|
||||
default: [],
|
||||
},
|
||||
bracketMatches: {
|
||||
type: [DoubleEliminationBracketMatchSubSchema],
|
||||
required: true,
|
||||
default: [],
|
||||
},
|
||||
placements: {
|
||||
type: DoubleEliminationPlacementsSubSchema,
|
||||
required: true,
|
||||
default: () => ({}),
|
||||
},
|
||||
events: {
|
||||
type: [DoubleEliminationEventSubSchema],
|
||||
required: true,
|
||||
default: [],
|
||||
},
|
||||
},
|
||||
{ _id: false },
|
||||
);
|
||||
|
||||
const MatchResultSubSchema = new Schema<MatchResult>(
|
||||
{
|
||||
winnerTeamIndex: { type: Number, required: false, min: 1 },
|
||||
@@ -1595,6 +1874,10 @@ export const MatchSchema = new Schema<Match>(
|
||||
type: MatchResultPollStateSubSchema,
|
||||
required: false,
|
||||
},
|
||||
doubleElimination: {
|
||||
type: DoubleEliminationBracketSubSchema,
|
||||
required: false,
|
||||
},
|
||||
legacyImported: { type: Boolean, required: false, default: false },
|
||||
legacyImportSource: {
|
||||
type: MatchLegacyImportSourceSubSchema,
|
||||
|
||||
Reference in new issue
Block a user