Skip to content

Commit

Permalink
feat(event): add tournament mode and rounds
Browse files Browse the repository at this point in the history
  • Loading branch information
crispgm committed Aug 29, 2024
1 parent fca9336 commit 1032c68
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
5 changes: 3 additions & 2 deletions cmd/kicker-cli/cmd/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func createdBetween(created time.Time) bool {

func initEventInfoHeader() [][]string {
var table [][]string
header := []string{"ID", "Name", "Date Time", "Level", "Players", "Games", "Name Type", "Mode", "URL"}
header := []string{"ID", "Name", "Date Time", "Level", "Players", "Games", "Rounds", "Name Type", "Mode", "URL"}
if !globalNoHeaders {
table = append(table, header)
}
Expand Down Expand Up @@ -162,8 +162,9 @@ func showInfo(table *[][]string, e *entity.Event, t *model.Tournament, r *entity
strings.Join(levels, "|"),
fmt.Sprintf("%d", len(r.Players)),
fmt.Sprintf("%d", len(r.AllGames)),
fmt.Sprintf("%d", len(t.Rounds)),
t.NameType,
t.Mode,
t.TournamentMode(),
dashIfEmpty(e.URL),
})
}
45 changes: 44 additions & 1 deletion pkg/ktool/model/tournament.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package model

import "time"
import (
"fmt"
"time"
)

// Tournament .
type Tournament struct {
Expand Down Expand Up @@ -68,3 +71,43 @@ func (t Tournament) IsDYP() bool {
func (t Tournament) IsMonsterDYP() bool {
return t.NameType == NameTypeMonsterDYP
}

// PreliminaryMode .
func (t Tournament) PreliminaryMode() string {
if len(t.Rounds) == 0 {
return ""
}

return t.Mode
}

// EliminationMode .
func (t Tournament) EliminationMode() string {
if len(t.KnockOffs) == 0 {
return ""
}

ko := t.KnockOffs[0]
if len(ko.LeftLevels) > 0 {
return ModeDoubleElimination
}

return ModeElimination
}

// TournamentMode .
func (t Tournament) TournamentMode() string {
eMode := t.EliminationMode()
pMode := t.PreliminaryMode()
if eMode == "" && pMode == "" {
return t.Mode
}

if eMode == "" {
return pMode
} else if pMode == "" {
return eMode
}

return fmt.Sprintf("%s, %s", pMode, eMode)
}

0 comments on commit 1032c68

Please sign in to comment.