Prisma init
This commit is contained in:
133
src/lib/match.ts
133
src/lib/match.ts
@@ -1,5 +1,34 @@
|
||||
export class User {
|
||||
id?: string;
|
||||
name: string;
|
||||
sponsor?: string;
|
||||
roles: Array<string>;
|
||||
profile: UserProfile;
|
||||
|
||||
export enum BracketType {
|
||||
constructor(name: string) {
|
||||
this.name = name;
|
||||
this.roles = new Array<string>();
|
||||
this.profile = {};
|
||||
}
|
||||
}
|
||||
|
||||
export class UserProfile {
|
||||
|
||||
}
|
||||
|
||||
export interface Tournament {
|
||||
id: string;
|
||||
title: string;
|
||||
slug?: string;
|
||||
tournamentCreator: User;
|
||||
tournamentAdmins: Array<User>;
|
||||
events: Array<Event>;
|
||||
}
|
||||
|
||||
export interface Event {
|
||||
}
|
||||
|
||||
export enum PhaseType {
|
||||
DOUBLE_ELIM = "Double Elimination",
|
||||
SINGLE_ELIM = "Single Elimination",
|
||||
ROUND_ROBIN = "Round Robin",
|
||||
@@ -7,84 +36,34 @@ export enum BracketType {
|
||||
SWISS = "Swiss",
|
||||
}
|
||||
|
||||
export class BracketConfig {
|
||||
bracketType: BracketType;
|
||||
gamesPerSet: number;
|
||||
constructor(bracketType?: BracketType, gamesPerSet?: number) {
|
||||
if(bracketType)
|
||||
this.bracketType = bracketType;
|
||||
export interface Phase {
|
||||
id: string;
|
||||
brackets: Array<Bracket>;
|
||||
config: PhaseConfig;
|
||||
}
|
||||
|
||||
export interface Bracket {
|
||||
|
||||
}
|
||||
|
||||
export class PhaseConfig {
|
||||
phaseType: PhaseType;
|
||||
winningSetCount: number;
|
||||
numPhaseWinners: number;
|
||||
|
||||
constructor(phaseType?: PhaseType, winningSetCount?: number, numPhaseWinners?: number) {
|
||||
if(phaseType)
|
||||
this.phaseType = phaseType;
|
||||
else
|
||||
this.bracketType = BracketType.DOUBLE_ELIM;
|
||||
if(gamesPerSet)
|
||||
this.gamesPerSet = gamesPerSet;
|
||||
this.phaseType = PhaseType.DOUBLE_ELIM;
|
||||
if(winningSetCount)
|
||||
this.winningSetCount = winningSetCount;
|
||||
else
|
||||
this.gamesPerSet = 3;
|
||||
}
|
||||
}
|
||||
|
||||
export interface SetGame {
|
||||
p1Rounds?: number;
|
||||
p2Rounds?: number;
|
||||
|
||||
winner: MatchIdentity;
|
||||
}
|
||||
export interface BaseSet<T extends MatchIdentity> {
|
||||
id: string;
|
||||
p1: T | null;
|
||||
p2: T | null;
|
||||
|
||||
setGames: Array<SetGame>;
|
||||
}
|
||||
|
||||
export interface BaseBracket<T extends BaseSet<MatchIdentity>> {
|
||||
id: string;
|
||||
sets: Array<T>;
|
||||
config: BracketConfig;
|
||||
}
|
||||
|
||||
export interface Lookup<TKey, TValue> {
|
||||
key: TKey;
|
||||
value: TValue;
|
||||
}
|
||||
|
||||
export class OneOnOneBracket implements BaseBracket<OneOnOneSet> {
|
||||
id: string;
|
||||
sets = new Array<OneOnOneSet>();
|
||||
setLookup = new Array<Array<Lookup<string, OneOnOneSet>>>();
|
||||
config: BracketConfig;
|
||||
|
||||
constructor(id: string, config: BracketConfig) {
|
||||
this.id = id;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
completeSet(set: OneOnOneSet){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class OneOnOneSet implements BaseSet<Player> {
|
||||
id: string;
|
||||
p1: Player | null;
|
||||
p2: Player | null;
|
||||
setGames = new Array<SetGame>();
|
||||
|
||||
constructor(id: string, player1: Player | null = null, player2: Player | null = null) {
|
||||
this.id = id;
|
||||
this.p1 = player1;
|
||||
this.p2 = player2;
|
||||
}
|
||||
|
||||
addSetGame(setGame: SetGame){
|
||||
this.setGames.push(setGame);
|
||||
}
|
||||
|
||||
removeSetGame(setGame: SetGame) {
|
||||
const setGameIndex = this.setGames.indexOf(setGame);
|
||||
if(setGameIndex > -1) {
|
||||
this.setGames.splice(setGameIndex, 1);
|
||||
}
|
||||
this.winningSetCount = 2;
|
||||
if(numPhaseWinners)
|
||||
this.numPhaseWinners = numPhaseWinners;
|
||||
else
|
||||
this.numPhaseWinners = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +1,3 @@
|
||||
<script lang="ts">
|
||||
import BracketBoard from "$lib/components/BracketBoard.svelte";
|
||||
import { type Lookup, type Player, BracketConfig, OneOnOneBracket as BracketEntity, BracketType, OneOnOneSet } from "$lib/match";
|
||||
import OneOnOneBracket from "$lib/components/OneOnOne/OneOnOneBracket.svelte";
|
||||
|
||||
const config = new BracketConfig(BracketType.DOUBLE_ELIM, 3);
|
||||
const bracket = new BracketEntity("A1", config);
|
||||
const testPlayer1 = { id: "tp1", name: "Test Player 1" } as Player;
|
||||
const testPlayer2 = { id: "tp2", name: "Test Player 2" } as Player;
|
||||
const testPlayer3 = { id: "tp3", name: "Test Player 3" } as Player;
|
||||
const testPlayer4 = { id: "tp4", name: "Test Player 4" } as Player;
|
||||
const testSet1 = new OneOnOneSet("A1-1", testPlayer1, testPlayer2);
|
||||
const testSet2 = new OneOnOneSet("A1-2", testPlayer1, testPlayer2);
|
||||
const testSet3 = new OneOnOneSet("A1-3", null, null, testSet1.id, testSet2.id);
|
||||
bracket.sets.push(testSet1);
|
||||
const round1 = new Array<Lookup<string, OneOnOneSet>>();
|
||||
</script>
|
||||
|
||||
<BracketBoard>
|
||||
<OneOnOneBracket {bracket}>
|
||||
</OneOnOneBracket>
|
||||
</BracketBoard>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user