lobbies

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AnswerView = common.ParseTmplWithFuncs("templates/views/answer-view.html")
View Source
var ChooseUsernameView = common.ParseTmplWithFuncs("templates/views/choose-username-view.html")

Views are the templates that are rendered for the different states of the lobby All of them require ViewData as the data to render

View Source
var LobbiesTmpl = tmplParseWithBase("templates/lobbies/lobbies.html")
View Source
var LobbyErrorAlertTmpl = LobbyTmpl.Lookup("error-alert")
View Source
var LobbySettingsTmpl = WaitingRoomView.Lookup("lobby-settings")

This template is used to render the lobby settings inside waitingRoomView

View Source
var LobbyTmpl = tmplParseWithBase("templates/lobbies/lobby.html")
View Source
var QuestionView = common.ParseTmplWithFuncs("templates/views/question-view.html")
View Source
var WaitingRoomView = common.ParseTmplWithFuncs("templates/views/waiting-room-view.html")

Functions

func NewCancellableTimer

func NewCancellableTimer(d time.Duration) *cancellableTimer

func NewLobbiesRouter

func NewLobbiesRouter() http.Handler

Returns a handler for routes starting with /lobbies

Types

type ByScore

type ByScore []*User

ByScore implements sort.Interface for []*user based on the Score field User for calculating leaderboard

func (ByScore) Len

func (a ByScore) Len() int

func (ByScore) Less

func (a ByScore) Less(i, j int) bool

func (ByScore) Swap

func (a ByScore) Swap(i, j int)

type ClientID

type ClientID string

func NewClientID

func NewClientID() (ClientID, error)

type Lobby

type Lobby struct {
	CreatedAt       time.Time
	StartedAt       time.Time
	FinishedAt      time.Time
	Quiz            models.Quiz
	Host            *User
	Pin             string
	TimePerQuestion time.Duration // Time for players to answer a question
	TimeForReading  time.Duration // Time to read the question before answering is allowed
	Players         map[ClientID]*User
	State           LobbyState

	CurrentQuestionStartTime time.Time
	CurrentQuestionTimeout   time.Time
	ReadingTimeout           time.Time
	CurrentQuestionIdx       int
	CurrentQuestion          *models.Question
	PlayersAnswering         int     // Number of players who haven't submitted an answer
	Leaderboard              []*User // Players sorted by score
	// contains filtered or unexported fields
}

Lobby is a actively running game session

type LobbySettingsData

type LobbySettingsData struct {
	Quizzes []models.QuizMetadata
	Lobby   *Lobby
}

type LobbyState

type LobbyState int
const (
	LsWaitingForPlayers LobbyState = iota
	LsQuestion
	LsAnswer
)

func (LobbyState) View

func (state LobbyState) View() *template.Template

View returns the view template for the given state

type OnFinishData

type OnFinishData struct {
	PastGameID uint
	ViewData
}

type User

type User struct {
	Conn                 *websocket.Conn
	ClientID             ClientID
	Username             string
	SubmittedAnswerIdx   int
	AnswerSubmissionTime time.Time
	Score                int
	NewPoints            int
}

type ViewData

type ViewData struct {
	Lobby *Lobby
	User  *User
}

Jump to

Keyboard shortcuts

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