~whereswaldon/pointstar

ref: v0.0.1 pointstar/client/uistate.go -rw-r--r-- 1.5 KiB
1e806177Chris Waldon bugfix: avoid crashing when laying out help 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main

import (
	"gioui.org/layout"
	"gioui.org/widget"
	"git.sr.ht/~whereswaldon/pointstar/client/widgets"
	"git.sr.ht/~whereswaldon/pointstar/gamestate"
)

// UIState maintains the state of widgets in the UI between frame events
type UIState struct {
	// HasConnected indicates whether the UI has ever connected to a backend,
	// whereas Connected indicates whether it is *currently* connected
	HasConnected, Connected bool

	PlayButtons       [gamestate.MaxHandSize]widget.Button
	PassButton        widget.Button
	HelpButton        widget.Button
	StartButton       widget.Button
	NameEditor        widget.Editor
	NameSubmit        widget.Button
	AddAIPlayerButton widget.Button
	PlayerNum         int

	// store the widget state of the player's cards
	HandCardState [gamestate.MaxHandSize]widgets.Card

	// store the state of all played cards
	PlayedCardState [gamestate.MaxPlayers][gamestate.MaxHandSize]widgets.Card

	// whether or not the help screen is being displayed instead of the game interface
	DisplayingHelp bool
	// hold the state of a list of example cards
	HelpExampleCards layout.List

	HandList layout.List

	PlayedLists []layout.List

	Worker *WSWorker
}

// Update processes a new gamestate and carries out any necessary bookkeeping
// such as allocating structures for storing the UI state associated with a
// new player
func (u *UIState) Update(g *gamestate.GameState) {
	if len(u.PlayedLists) < len(g.Players) {
		u.PlayedLists = make([]layout.List, len(g.Players))
	}
}