canvas

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Rendered for js/wasm

Overview

Package canvas contains the logic to draw the game.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Canvas

type Canvas struct {
	Socket Socket

	MainColor  string
	DragColor  string
	TileColor  string
	ErrorColor string
	// contains filtered or unexported fields
}

Canvas is the object which draws the game.

func (Canvas) DesiredWidth added in v1.2.0

func (c Canvas) DesiredWidth() int

DesiredWidth is width the canvas needs to safely draw the board. Uses the TileLength, numCols, and badding

func (*Canvas) InitDom

func (c *Canvas) InitDom(ctx context.Context, wg *sync.WaitGroup)

InitDom registers canvas dom functions by adding an event listeners to the canvas element.

func (Canvas) NumCols

func (c Canvas) NumCols() int

NumCols the number of columns the canvas can draw.

func (Canvas) NumRows

func (c Canvas) NumRows() int

NumRows the number of rows the canvas can draw.

func (Canvas) ParentDivOffsetWidth

func (c Canvas) ParentDivOffsetWidth() int

ParentDivOffsetWidth is the offsetWidth of the parent div.

func (*Canvas) Redraw

func (c *Canvas) Redraw()

Redraw draws the canvas

func (*Canvas) SetGameStatus

func (c *Canvas) SetGameStatus(s game.Status)

SetGameStatus sets the gameStatus for the canvas. The canvas is redrawn afterwards to clean up drawing artifacts

func (*Canvas) SetTileLength

func (c *Canvas) SetTileLength(tileLength int)

SetTileLength sets the drawing size of the tiles length/height.

func (*Canvas) StartSwap

func (c *Canvas) StartSwap()

StartSwap start a swap move.

func (Canvas) TileLength

func (c Canvas) TileLength() int

TileLength is the drawing size of the tiles length/height.

func (*Canvas) UpdateSize

func (c *Canvas) UpdateSize(width int)

UpdateSize sets the draw properties of the canvas for it's current size in the window.

type Config

type Config struct {
	TileLength int
	MainColor  string
	DragColor  string
	TileColor  string
	ErrorColor string
}

Config contains the parameters to create a Canvas.

func (Config) New

func (cfg Config) New(dom DOM, log Log, board *board.Board, canvasParentDivQuery string) *Canvas

New Creates a canvas from the config.

type Context

type Context interface {
	SetFont(name string)
	SetLineWidth(width float64)
	SetFillColor(name string)
	SetStrokeColor(name string)
	FillText(text string, x, y int)
	ClearRect(x, y, width, height int)
	FillRect(x, y, width, height int)
	StrokeRect(x, y, width, height int)
}

Context handles the drawing of the canvas.

type DOM added in v1.2.0

type DOM interface {
	QuerySelector(query string) js.Value
	SetChecked(query string, checked bool)
	NewJsEventFunc(fn func(event js.Value)) js.Func
	ReleaseJsFuncsOnDone(ctx context.Context, wg *sync.WaitGroup, jsFuncs map[string]js.Func)
}

DOM interacts with the page.

type Log added in v1.2.0

type Log interface {
	Error(text string)
	Info(text string)
}

Log is notify users about changes to the game.

type Socket

type Socket interface {
	Send(m message.Message)
}

Socket sends messages to the server.

Jump to

Keyboard shortcuts

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