Skip to content

Commit

Permalink
feat(info): show score properly
Browse files Browse the repository at this point in the history
  • Loading branch information
crispgm committed Jul 17, 2024
1 parent 5d381eb commit 68208eb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
13 changes: 7 additions & 6 deletions cmd/kicker-cli/cmd/event_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/spf13/cobra"

"github.com/crispgm/kicker-cli/internal/entity"
"github.com/crispgm/kicker-cli/pkg/ktool/model"
)

var showScore bool
Expand Down Expand Up @@ -35,20 +36,20 @@ var eventInfoCmd = &cobra.Command{
table := initEventInfoHeader()
t, r := loadAndShowEventInfo(&table, instance.DataPath(), instance.Conf.Players, e)
_ = pterm.DefaultTable.WithHasHeader(!globalNoHeaders).WithData(table).WithBoxed(!globalNoBoxes).Render()
table = showGames(r.PreliminaryRounds)
table = showGames(r.PreliminaryRounds, t.Options)
if len(table) > 0 {
pterm.Println("Rounds:")
_ = pterm.DefaultTable.WithHasHeader(false).WithData(table).WithBoxed(!globalNoBoxes).Render()
}
sort.SliceStable(r.LoserBracket, func(i, j int) bool {
return true
})
table = showGames(r.LoserBracket)
table = showGames(r.LoserBracket, t.Options)
if len(table) > 0 {
pterm.Println("Loser Bracket:")
_ = pterm.DefaultTable.WithHasHeader(false).WithData(table).WithBoxed(!globalNoBoxes).Render()
}
table = showGames(r.WinnerBracket)
table = showGames(r.WinnerBracket, t.Options)
if len(table) > 0 {
pterm.Println("Winner Bracket:")
_ = pterm.DefaultTable.WithHasHeader(false).WithData(table).WithBoxed(!globalNoBoxes).Render()
Expand All @@ -62,14 +63,14 @@ var eventInfoCmd = &cobra.Command{
},
}

func showGames(games []entity.Game) [][]string {
func showGames(games []entity.Game, options model.Options) [][]string {
var table [][]string
if len(games) == 0 {
return table
}
numOfSets := len(games[0].Sets)
if numOfSets == 1 {
showScore = true
if numOfSets == 1 && options.FastInput {
showScore = false
}

if showScore {
Expand Down
2 changes: 2 additions & 0 deletions internal/converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ func (c Converter) convertPlayToGame(
game.Point2++
} else {
// draw
game.Point1++
game.Point2++
}
}
break // only support one discipline right now
Expand Down
6 changes: 6 additions & 0 deletions pkg/ktool/model/knockoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ type KnockOff struct {
Levels []Level `json:"levels"`
LeftLevels []Level `json:"leftLevels"`
Third Level `json:"third"`

Options Options `json:"options"`
ThirdPlace bool `json:"thirdPlace"`
Double bool `json:"double"`
Size int `json:"size"`
Finished bool `json:"bool"`
}

// Level .
Expand Down
1 change: 1 addition & 0 deletions pkg/ktool/model/tournament.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Options struct {
NumPoints int `json:"numPoints"`
NumSets int `json:"numSets"`
TwoAhead bool `json:"twoAhead"`
FastInput bool `json:"fastInput"`
Draw bool `json:"draw"`
PointsWin int `json:"pointsWin"`
PointsDraw int `json:"pointsDraw"`
Expand Down

0 comments on commit 68208eb

Please sign in to comment.