challonge

package
v0.0.0-...-b8f7dfc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 17 Imported by: 0

README

Challonge Integration

Uses the Challonge API to load tournaments, update matches, and automatically update the overlays.

Steps

  1. Select Tournament
    • Get list of incomplete tournaments via Challonge.
  2. Setup Tournament x Validates all player names are in the correct format. "FirstName LastName - FargoRating (FargoID)" x Validates all players in the tournament exist in the database.
    • Checks if tournament is multi-stage (v2 api), and double elimination. x Set Game type for each stage, and race for each stage / side. x Set number of max tables to use. x Toggle handicapped tournament.
  3. Start Tournament x Loads the selected tournament.
    • Turns on tournament mode flag to lockout changes to overlay (nice to have). x Changes all tables to the settings for tournament. (Game Type, Race (A/B Side), Unset Players) x Loads first matches in to tables. x While tables are empty. x Get next match x Set empty table to game data. (players, resets score)
      • Mark match as in progress on Challonge (v2 api). x Set score to 0-0 on Challonge.
  4. Scoring x When updating scores on the tablets, update the score on Challonge as well.
  5. Match is completed x Player confirms match is completed on tablet. x Save game to database. x Mark match as completed with winner and score on Challonge. x Check if we should be staying at the same amount of tables. (temp solution) x Check if another match still needs to be played. x If yes, get next match and load to same table, otherwise reduce the number of tables.
  6. Skipping a match
    • Admin can skip a match on a table.
    • Check if another match still needs to be played.
    • Get next match and load to same table.
  7. Allow chop in finals.
    • Admin has a way to submit score of 0-0 in case players chop. This allows the tournament to complete, but doesn't get entered as wins or losses into Fargo.
  8. Complete tournament x When final game is saved, it should attempt to complete the tournament.
    • Unloads the tournament.

Other nice to haves: - Admin can swap matches between two tables.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Challonge

type Challonge struct {
	Tournament *Tournament `json:"tournament"`
	Settings   *Settings   `json:"settings"`

	// PlayersMap is a map of challonge player ids to players in the db.
	PlayersMap map[int]*models.Player `json:"-"`

	// CurrentMatches is a map of table number to match.
	CurrentMatches map[int]*Match `json:"-"`
	// contains filtered or unexported fields
}

Challonge stores the current challonge instance.

func NewChallonge

func NewChallonge(apiKey string, username string, db *gorm.DB, overlay *overlayPkg.Overlay, tables map[int]*state.State) *Challonge

NewChallonge returns a new Challonge.

func (*Challonge) Continue

func (c *Challonge) Continue(table int) error

Continue completes a game, and sets up the next match for the tournament.

func (*Challonge) GetTournamentByID

func (c *Challonge) GetTournamentByID(id int) (*Tournament, error)

GetTournamentByID returns a tournament by id.

func (*Challonge) GetTournamentList

func (c *Challonge) GetTournamentList() ([]*Tournament, error)

GetTournamentList returns a list of incomplete tournaments on Challonge account.

func (*Challonge) InTournamentMode

func (c *Challonge) InTournamentMode() bool

InTournamentMode returns if a tournament is currently loaded.

func (*Challonge) LoadTournament

func (c *Challonge) LoadTournament(id int, settings *Settings) error

loadTournament loads a tournament by id.

func (*Challonge) UnloadTournament

func (c *Challonge) UnloadTournament()

UnloadTournament unsets the current tournament.

func (*Challonge) UpdateMatchScore

func (c *Challonge) UpdateMatchScore(table int) error

UpdateMatchScore updates a match score on challonge.

type Config

type Config struct {
	APIKey   string
	Username string
}

Config is the configuration required for Challonge.

func NewConfig

func NewConfig(apiKey string, username string) *Config

NewConfig returns a new Config.

type Match

type Match struct {
	ID                 int        `json:"id"`
	TournamentID       int        `json:"tournament_id"`
	State              string     `json:"state"`
	Player1ID          *int       `json:"player1_id"`
	Player2ID          *int       `json:"player2_id"`
	ScoresCsv          string     `json:"scores_csv"`
	Round              int        `json:"round"`
	Identifier         string     `json:"identifier"`
	SuggestedPlayOrder int        `json:"suggested_play_order"`
	UnderwayAt         *time.Time `json:"underway_at"`
}

Match is a set to be played within a Tournament.

func (*Match) IsOnASide

func (m *Match) IsOnASide() bool

IsOnASide returns if the round is on the A side or not.

func (*Match) Refresh

func (m *Match) Refresh(username string, apiKey string) error

Refreshes a match with new data from Challonge. Should only be used when a match was completed.

func (*Match) ReportWinner

func (m *Match) ReportWinner(username string, apiKey string, playerID int, scoresCsv string) error

ReportWinner reports the winner of the match to challonge.

func (*Match) SetInProgress

func (m *Match) SetInProgress(username string, apiKey string) error

SetInProgress sets the match to in progress on Challonge.

func (*Match) UpdateScore

func (m *Match) UpdateScore(username string, apiKey string, scoresCsv string) error

UpdateScore updates the score for a match.

type MatchResp

type MatchResp struct {
	Match Match `json:"match"`
}

type MatchesResp

type MatchesResp []struct {
	Match Match `json:"match"`
}

type Participant

type Participant struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

type ParticipantsResp

type ParticipantsResp []struct {
	Participant Participant `json:"participant"`
}

type Settings

type Settings struct {
	MaxTables     int             `json:"max_tables"`
	GameType      models.GameType `json:"game_type"`
	ShowOverlay   bool            `json:"show_overlay"`
	ShowFlags     bool            `json:"show_flags"`
	ShowFargo     bool            `json:"show_fargo"`
	ShowScore     bool            `json:"show_score"`
	IsHandicapped bool            `json:"is_handicapped"`
	ASideRaceTo   int             `json:"a_side_race_to"`
	BSideRaceTo   int             `json:"b_side_race_to"`
}

type Tournament

type Tournament struct {
	ID                int        `json:"id"`
	Name              string     `json:"name"`
	URL               string     `json:"url"`
	TournamentType    string     `json:"tournament_type"`
	ParticipantsCount int        `json:"participants_count"`
	Rounds            int        `json:"rounds"`
	Matches           []*Match   `json:"matches"`
	CreatedAt         time.Time  `json:"created_at"`
	CompletedAt       *time.Time `json:"completed_at"`

	Participants []*Participant `json:"participants"`
}

Tournament is a tournament bracket on the Challonge account.

func (*Tournament) CompleteIfPossible

func (t *Tournament) CompleteIfPossible(username, apiKey string) error

CompleteIfPossible attempts to complete the tournament.

func (*Tournament) CountParallelMatches

func (t *Tournament) CountParallelMatches() int

CountParallelMatches returns a count of the maximum number of matches that could be played in parallel.

func (*Tournament) GetNextMatch

func (t *Tournament) GetNextMatch() *Match

GetNextMatch returns the first incomplete match in the tournament bracket.

func (*Tournament) HasMoreMatches

func (t *Tournament) HasMoreMatches() bool

HasMoreMatches returns if there are more matches that need to be completed in the tournament.

func (*Tournament) RemainingMatches

func (t *Tournament) RemainingMatches() int

RemainingMatches returns the number of matches yet to be played.

func (*Tournament) Validate

func (t *Tournament) Validate() error

Validate checks to make sure the tournament is in a valid format.

type TournamentResp

type TournamentResp struct {
	Tournament Tournament `json:"tournament"`
}

type TournamentsResp

type TournamentsResp []struct {
	Tournament Tournament `json:"tournament"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL