state

package
v1.13.7 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DiffFrame = iota
	FullFrame
)
View Source
const Letters = "ABCDEFGHIJKLNMOPQRSTUVWXYZ"

Variables

This section is empty.

Functions

func Color

func Color(f FieldProvider) color.Color

func Coord

func Coord(f FieldProvider) *coord.Coord

func HasComment

func HasComment(f FieldProvider) bool

func IsMove

func IsMove(f FieldProvider) bool

func IsPass

func IsPass(f FieldProvider) bool

Types

type Command

type Command interface {
	Execute(*State) (*Frame, error)
}

func DecodeToCommand

func DecodeToCommand(evt event.Event) (Command, error)

func NewAddLabelCommand

func NewAddLabelCommand(crd *coord.Coord, label string) Command

func NewAddLetterCommand

func NewAddLetterCommand(crd *coord.Coord, letter string) Command

func NewAddNumberCommand

func NewAddNumberCommand(crd *coord.Coord, number int) Command

func NewAddSquareCommand

func NewAddSquareCommand(crd *coord.Coord) Command

func NewAddStoneCommand

func NewAddStoneCommand(crd *coord.Coord, color color.Color) Command

func NewAddTriangleCommand

func NewAddTriangleCommand(crd *coord.Coord) Command

func NewCommentCommand

func NewCommentCommand(text string) Command

func NewCopyCommand

func NewCopyCommand() Command

func NewCutCommand

func NewCutCommand() Command

func NewDownCommand

func NewDownCommand() Command

func NewDrawCommand

func NewDrawCommand(x0, y0, x1, y1 float64, color string) Command

func NewErasePenCommand

func NewErasePenCommand() Command

func NewFastForwardCommand

func NewFastForwardCommand() Command

func NewGotoCoordCommand

func NewGotoCoordCommand(crd *coord.Coord) Command

func NewGotoGridCommand

func NewGotoGridCommand(index int) Command

func NewGraftCommand

func NewGraftCommand(text string) Command

func NewLeftCommand

func NewLeftCommand() Command

func NewMarkDeadCommand

func NewMarkDeadCommand(crd *coord.Coord) Command

func NewPassCommand

func NewPassCommand(color color.Color) Command

func NewPasteCommand

func NewPasteCommand() Command

func NewRemoveMarkCommand

func NewRemoveMarkCommand(crd *coord.Coord) Command

func NewRemoveStoneCommand

func NewRemoveStoneCommand(crd *coord.Coord) Command

func NewRewindCommand

func NewRewindCommand() Command

func NewRightCommand

func NewRightCommand() Command

func NewScoreCommand

func NewScoreCommand() Command

func NewUpCommand

func NewUpCommand() Command

type FieldProvider

type FieldProvider interface {
	GetField(string) []string
}

type Frame

type Frame struct {
	Type      FrameType      `json:"type"`
	Diff      *coord.Diff    `json:"diff"`
	Marks     *Marks         `json:"marks"`
	Comments  []string       `json:"comments"`
	Metadata  *Metadata      `json:"metadata"`
	TreeJSON  *TreeJSON      `json:"tree"`
	BlackCaps int            `json:"black_caps"`
	WhiteCaps int            `json:"white_caps"`
	BlackArea []*coord.Coord `json:"black_area"`
	WhiteArea []*coord.Coord `json:"white_area"`
	Dame      []*coord.Coord `json:"dame"`
}

Frame provides the data for when the board needs to be updated (not the explorer)

type FrameType

type FrameType int

FrameType can be either DiffFrame or FullFrame

type Label

type Label struct {
	Coord *coord.Coord `json:"coord"`
	Text  string       `json:"text"`
}

Label can be any text, but typically single digits or letters

type Marks

type Marks struct {
	Current   *coord.Coord   `json:"current"`
	Squares   []*coord.Coord `json:"squares"`
	Triangles []*coord.Coord `json:"triangles"`
	Labels    []*Label       `json:"labels"`
	Pens      []*Pen         `json:"pens"`
}

Marks provides data for any marks on the board

type Metadata

type Metadata struct {
	Size   int            `json:"size"`
	Fields []fields.Field `json:"fields"`
}

Metadata provides the size of the board plus any fields (usually from the root node)

type NodeJSON

type NodeJSON struct {
	Color   color.Color `json:"color"`
	Down    []int       `json:"down"`
	Depth   int         `json:"depth"`
	Comment bool        `json:"comment"`
}

NodeJSON is a key component of TreeJSON

type Pen

type Pen struct {
	X0    float64 `json:"x0"`
	Y0    float64 `json:"y0"`
	X1    float64 `json:"x1"`
	Y1    float64 `json:"y1"`
	Color string  `json:"color"`
}

Pen contains a start and end coordinate plus a color

type State

type State struct {
	// contains filtered or unexported fields
}

as a rule, anything that would need to get sent to new connections should be stored here

func FromSGF

func FromSGF(data string) (*State, error)

func NewEmptyState

func NewEmptyState(size int) *State

func NewState

func NewState(size int) *State

func (*State) AddNode

func (s *State) AddNode(crd *coord.Coord, col color.Color) *coord.Diff

func (*State) AddStones

func (s *State) AddStones(moves []*coord.Stone)

func (*State) AddStonesToTrunk

func (s *State) AddStonesToTrunk(t int, moves []*coord.Stone)

func (*State) AnyMove

func (s *State) AnyMove()

func (*State) Board

func (s *State) Board() *board.Board

func (*State) Current

func (s *State) Current() *tree.TreeNode

func (*State) EditKomi

func (s *State) EditKomi(value string)

func (*State) EditPlayerBlack

func (s *State) EditPlayerBlack(value string)

func (*State) EditPlayerWhite

func (s *State) EditPlayerWhite(value string)

func (*State) GenerateFullFrame

func (s *State) GenerateFullFrame(t TreeJSONType) *Frame

func (*State) GenerateTreeOnly

func (s *State) GenerateTreeOnly(t TreeJSONType) *Frame

func (*State) GetColorAt

func (s *State) GetColorAt(t int) color.Color

func (*State) GetNextIndex

func (s *State) GetNextIndex() int

func (*State) Head

func (s *State) Head() *tree.TreeNode

func (*State) HeadColor

func (s *State) HeadColor() color.Color

func (*State) Nodes

func (s *State) Nodes() map[int]*tree.TreeNode

func (*State) PushHead

func (s *State) PushHead(x, y int, col color.Color) bool

func (*State) Root

func (s *State) Root() *tree.TreeNode

func (*State) Save

func (s *State) Save() *StateJSON

func (*State) SetLocation

func (s *State) SetLocation(loc string)

func (*State) SetNextIndex

func (s *State) SetNextIndex(i int)

func (*State) SetPrefs

func (s *State) SetPrefs(prefs map[string]int)

SetPrefs takes a map and sets

func (*State) Size

func (s *State) Size() int

func (*State) ToSGF

func (s *State) ToSGF() string

func (*State) ToSGFIX

func (s *State) ToSGFIX() string

type StateJSON

type StateJSON struct {
	SGF       string         `json:"sgf"`
	Location  string         `json:"loc"`
	Prefs     map[string]int `json:"prefs"`
	NextIndex int            `json:"next_index"`
}

type TreeJSON

type TreeJSON struct {
	Nodes     map[int]*NodeJSON `json:"nodes"`
	Current   int               `json:"current"`
	Preferred []int             `json:"preferred"`
	Depth     int               `json:"depth"`
	Up        int               `json:"up"`
	Root      int               `json:"root"`
}

TreeJSON is the basic struct to encode information about the explorer this makes up one part of a Frame

type TreeJSONType

type TreeJSONType int

TreeJSONType defines some options for how much data to send in a TreeJSON

const (
	CurrentOnly TreeJSONType = iota
	CurrentAndPreferred
	PartialNodes
	Full
)

Jump to

Keyboard shortcuts

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