canvas

package
v0.0.0-...-c857007 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2020 License: MIT Imports: 9 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
	// contains filtered or unexported fields
}

Canvas is the object which draws the game

func (*Canvas) GameStatus

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

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

func (*Canvas) InitDom

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

InitDom regesters canvas dom functions.

func (*Canvas) MoveCursor

func (c *Canvas) MoveCursor(pp pixelPosition)

MoveCursor should be called whenever the cursor moves, regardless of if a move is being made.

func (*Canvas) MoveEnd

func (c *Canvas) MoveEnd(pp pixelPosition)

MoveEnd should be called when a move is done being made at the specified coordinates.

func (*Canvas) MoveStart

func (c *Canvas) MoveStart(pp pixelPosition)

MoveStart should be called when a move is started to be made at the specified coordinates.

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) Redraw

func (c *Canvas) Redraw()

Redraw draws the canvas

func (*Canvas) StartSwap

func (c *Canvas) StartSwap()

StartSwap start a swap move

func (*Canvas) UpdateSize

func (c *Canvas) UpdateSize()

UpdateSize sets the draw properties of the canvas for it's current size in the window. TODO: allow tileLength to be changed

type Config

type Config struct {
	TileLength int
}

Config contains the parameters to create a Canvas

func (Config) New

func (cfg Config) New(board *board.Board, parentDiv, element *js.Value) *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 Socket

type Socket interface {
	Send(m game.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