models

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: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRaceToInvalid  = errors.New("invalid race to amount")
	ErrRaceToNotFound = errors.New("handicap for race to not found")
)
View Source
var (
	ErrFlagIDInvalid = errors.New("invalid flag id")
	ErrFlagNotFound  = errors.New("flag not found")
)
View Source
var (
	// ErrInvalidPlayerNumber - Invalid player number.
	ErrInvalidPlayerNumber = errors.New("invalid player number")
	// ErrInvalidPlayerID - Invalid player ID.
	ErrInvalidPlayerID = errors.New("invalid player id")
	// ErrInvalidTeamNumber - Invalid team number.
	ErrInvalidTeamNumber = errors.New("invalid team number")
	// ErrInvalidRaceTo - Invalid race to number.
	ErrInvalidRaceTo = errors.New("invalid race to number")
)
View Source
var (
	ErrPlayerIDInvalid                = errors.New("invalid player id")
	ErrPlayerFargoObservableIDInvalid = errors.New("invalid fargo observable id")
	ErrPlayerNotFound                 = errors.New("player not found")
	ErrPlayerHasIDAlready             = errors.New("player already has an id")
)
View Source
var (
	ErrTeamIDInvalid = errors.New("invalid team id")
	ErrTeamNotFound  = errors.New("team not found")
)

Functions

This section is empty.

Types

type FargoHotHandicap

type FargoHotHandicap struct {
	ID              uint  `json:"id" gorm:"primarykey"`
	RaceTo          int   `json:"race_to" gorm:"index"`
	DifferenceStart uint  `json:"difference_start"`
	DifferenceEnd   *uint `json:"difference_end"`
	WinsHigher      uint  `json:"wins_higher"`
	WinsLower       uint  `json:"wins_lower"`
}

FargoHotHandicap is a handicap for the specified race to.

type FargoHotHandicaps

type FargoHotHandicaps []FargoHotHandicap

FargoHotHandicaps are an array of FargoHotHandicap.

func (*FargoHotHandicaps) LoadByRaceTo

func (f *FargoHotHandicaps) LoadByRaceTo(database *gorm.DB, raceTo int) error

LoadByRaceTo loads handicaps for the supplied race to.

type Flag

type Flag struct {
	ID        uint   `json:"id,omitempty" gorm:"primarykey"`
	Country   string `json:"country,omitempty" gorm:"size:100"`
	ImagePath string `json:"image_path,omitempty" gorm:"size:100"`

	CreatedAt *time.Time      `json:"created_at,omitempty"`
	UpdatedAt *time.Time      `json:"updated_at,omitempty"`
	DeletedAt *gorm.DeletedAt `json:"deleted_at,omitempty" gorm:"index"`
}

Flag is a country flag for a pool player.

func (*Flag) LoadByID

func (f *Flag) LoadByID(database *gorm.DB, id int) error

LoadByID loads a flag by ID.

type Game

type Game struct {
	ID        uint       `json:"id,omitempty" gorm:"primarykey"`
	Table     int        `json:"table" gorm:"column:table_num"`
	Type      GameType   `json:"type"`
	VsMode    GameVsMode `json:"vs_mode"`
	RaceTo    int        `json:"race_to"`
	ScoreOne  int        `json:"score_one"`
	ScoreTwo  int        `json:"score_two"`
	Completed bool       `json:"completed"`

	PlayerOneID *uint `json:"player_one_id,omitempty"`
	PlayerTwoID *uint `json:"player_two_id,omitempty"`
	TeamOneID   *uint `json:"team_one_id,omitempty"`
	TeamTwoID   *uint `json:"team_two_id,omitempty"`

	PlayerOne *Player `json:"player_one,omitempty" gorm:"foreignKey:player_one_id"`
	PlayerTwo *Player `json:"player_two,omitempty" gorm:"foreignKey:player_two_id"`
	TeamOne   *Team   `json:"team_one,omitempty" gorm:"foreignKey:team_one_id"`
	TeamTwo   *Team   `json:"team_two,omitempty" gorm:"foreignKey:team_two_id"`

	UseFargoHotHandicap bool              `json:"use_fargo_hot_handicap"`
	FargoHotHandicapID  *uint             `json:"fargo_hot_handicap_id,omitempty"`
	FargoHotHandicap    *FargoHotHandicap `json:"fargo_hot_handicap,omitempty" gorm:"foreignKey:fargo_hot_handicap_id"`

	CreatedAt *time.Time      `json:"created_at,omitempty"`
	UpdatedAt *time.Time      `json:"updated_at,omitempty"`
	DeletedAt *gorm.DeletedAt `json:"deleted_at,omitempty" gorm:"index"`
	// contains filtered or unexported fields
}

Game is the current state of the game being played.

func NewGame

func NewGame(db *gorm.DB, table int) *Game

NewGame returns a new Game with default settings.

func (*Game) DecrementRaceTo

func (g *Game) DecrementRaceTo() error

DecrementRaceTo decreases the RaceTo of the game by one. Minimum value will always be 1.

func (*Game) DecrementScore

func (g *Game) DecrementScore(playerNum int) error

DecrementScore decreases the score for the specified player by one.

func (*Game) IncrementRaceTo

func (g *Game) IncrementRaceTo() error

IncrementRaceTo increases the RaceTo of the game by one.

func (*Game) IncrementScore

func (g *Game) IncrementScore(playerNum int) error

IncrementScore increases the score for the specified player by one.

func (*Game) LoadLatest

func (g *Game) LoadLatest(table int) *Game

func (*Game) Reset

func (g *Game) Reset() error

Reset will reset a game to a new one, while keeping some information about the existing one.

func (*Game) ResetScore

func (g *Game) ResetScore() error

ResetScore resets the current game score.

func (*Game) Save

func (g *Game) Save(completed bool) error

Save saves the game to the database.

func (*Game) SetPlayer

func (g *Game) SetPlayer(playerNum int, player *Player) error

SetPlayer sets the player number to the specified player.

func (*Game) SetPlayerFlag

func (g *Game) SetPlayerFlag(playerNum int, flag *Flag) error

SetPlayerFlag sets the flag to the specified player.

func (*Game) SetPlayerName

func (g *Game) SetPlayerName(playerNum int, name string) error

SetPlayerName sets the name to the specified player.

func (*Game) SetRaceTo

func (g *Game) SetRaceTo(raceTo int) error

SetRaceTo sets the race to a specified amount.

func (*Game) SetTeam

func (g *Game) SetTeam(teamNum int, team *Team) error

SetTeam sets the team number to the specified team.

func (*Game) SetType

func (g *Game) SetType(t GameType) error

SetType sets the Type of the current game.

func (*Game) SetUseFargoHotHandicap

func (g *Game) SetUseFargoHotHandicap(use bool) error

SetUseFargoHotHandicap updates if we are using fargo hot handicap for the current game.

func (*Game) SetVsMode

func (g *Game) SetVsMode(mode GameVsMode) error

SetVsMode changes the current GameVsMode of the game.

func (*Game) UnsetPlayer

func (g *Game) UnsetPlayer(playerNum int) error

UnsetPlayer unsets a player for the specified player num.

func (*Game) WinningPlayerNum

func (g *Game) WinningPlayerNum() int

WinningPlayerNum returns the winning player number (1 or 2) or if no winner, returns 0.

type GameType

type GameType uint

GameType is the type of pool gaming being played.

const (
	// EightBall is an 8 ball game.
	EightBall GameType = iota
	// NineBall is a 9 ball game.
	NineBall
	// TenBall is a 10 ball game.
	TenBall
)

func (GameType) IsValid

func (m GameType) IsValid() bool

IsValid returns if the GameType is valid.

func (GameType) String

func (m GameType) String() string

String returns the human readable version.

type GameVsMode

type GameVsMode int

GameVsMode is the type of players to be used.

const (
	// OneVsOne is one player vs one player.
	OneVsOne GameVsMode = iota
	// ScotchDoubles is a team of two players vs a team of two players.
	ScotchDoubles
)

func (GameVsMode) IsValid

func (m GameVsMode) IsValid() bool

IsValid returns if the GameVsMode is valid.

func (GameVsMode) String

func (m GameVsMode) String() string

String returns the human readable version.

type Player

type Player struct {
	ID                uint   `json:"id,omitempty" gorm:"primarykey"`
	Name              string `json:"name,omitempty" gorm:"size:100"`
	FlagID            uint   `json:"flag_id,omitempty"`
	Flag              *Flag  `json:"flag,omitempty" gorm:"foreignKey:flag_id"`
	FargoID           uint   `json:"fargo_id,omitempty"`
	FargoObservableID uint   `json:"fargo_observable_id,omitempty"`
	FargoRating       uint   `json:"fargo_rating,omitempty"`

	CreatedAt *time.Time      `json:"created_at,omitempty"`
	UpdatedAt *time.Time      `json:"updated_at,omitempty"`
	DeletedAt *gorm.DeletedAt `json:"deleted_at,omitempty" gorm:"index"`
}

Player is a pool player.

func (*Player) Create

func (p *Player) Create(database *gorm.DB) error

Create adds the player to the database.

func (*Player) Delete

func (p *Player) Delete(database *gorm.DB) error

Delete removes the current player from the database.

func (*Player) LoadByFargoObservableID

func (p *Player) LoadByFargoObservableID(database *gorm.DB, id int) error

LoadByFargoObservableID loads a player by Fargo observable ID.

func (*Player) LoadByID

func (p *Player) LoadByID(database *gorm.DB, id int) error

LoadByID loads a player by ID.

func (*Player) Update

func (p *Player) Update(database *gorm.DB) error

Update updates the current player in the database.

type Team

type Team struct {
	ID      uint          `json:"id,omitempty" gorm:"primarykey"`
	Name    string        `json:"name,omitempty" gorm:"size:100"`
	Players []*TeamPlayer `json:"players,omitempty" gorm:"foreignKey:team_id"`

	CreatedAt *time.Time      `json:"created_at,omitempty"`
	UpdatedAt *time.Time      `json:"updated_at,omitempty"`
	DeletedAt *gorm.DeletedAt `json:"deleted_at,omitempty" gorm:"index"`
}

Team is a team of pool players.

func (*Team) LoadByID

func (t *Team) LoadByID(database *gorm.DB, id int) error

LoadByID loads a team by ID.

type TeamPlayer

type TeamPlayer struct {
	ID       uint `json:"id,omitempty" gorm:"primarykey"`
	TeamID   uint `json:"team_id,omitempty"`
	PlayerID uint `json:"player_id,omitempty"`
	Captain  bool `json:"captain,omitempty"`

	Team   *Team   `json:"team,omitempty"`
	Player *Player `json:"player,omitempty"`

	CreatedAt *time.Time      `json:"created_at,omitempty"`
	UpdatedAt *time.Time      `json:"updated_at,omitempty"`
	DeletedAt *gorm.DeletedAt `json:"deleted_at,omitempty" gorm:"index"`
}

TeamPlayer is a player on a team.

Jump to

Keyboard shortcuts

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