js

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2023 License: ISC Imports: 8 Imported by: 0

README

gruid-js

pkg.go.dev godocs.io

The gruid-js module provides a gruid Driver for making wasm gruid applications that run in the browser. The module's package is called js.

To build a browser application, you have to build it with the following variables:

GOOS=js GOARCH=wasm go build -o app.wasm /path/to/your/application

Then, you have to serve using an http server a directory containing the app.wasm file along with an index.html file such as the basic example one in files/index.html (the html page containing the canvas of your application), and the $(go env GOROOT)/misc/wasm/wasm_exec.js file of your Go distribution.

Documentation

Overview

Package js provides a Driver for making browser apps using wasm.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	TileManager TileManager // for retrieving tiles (required)
	Width       int         // initial screen width in cells (default: 80)
	Height      int         // initial screen height in cells (default: 24)
	AppCanvasId string      // application's canvas id (default: appcanvas)
	AppDivId    string      // application's div containing the canvas id (default: appdiv)
}

Config contains configurations options for the driver.

type Driver

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

Driver implements gruid.Driver using the syscall/js interface for the browser using javascript and wasm.

func NewDriver

func NewDriver(cfg Config) *Driver

NewDriver returns a new driver with given configuration options.

func (*Driver) ClearCache

func (dr *Driver) ClearCache()

ClearCache clears the tiles internal cache.

func (*Driver) Close

func (dr *Driver) Close()

Close implements gruid.Driver.Close.

func (*Driver) Flush

func (dr *Driver) Flush(frame gruid.Frame)

Flush implements gruid.Driver.Flush.

func (*Driver) Init

func (dr *Driver) Init() error

Init implements gruid.Driver.Init.

func (*Driver) PollMsgs

func (dr *Driver) PollMsgs(ctx context.Context, msgs chan<- gruid.Msg) error

PollMsgs implements gruid.Driver.PollMsgs. To avoid conflicts with browser or OS shortcuts, keydown events with modifier keys may not be reported. If the script screenfull is available, it binds F11 for a portable canvas fullscreen.

func (*Driver) SetTileManager

func (dr *Driver) SetTileManager(tm TileManager)

SetTileManager allows to change the used tile manager.

type TileManager

type TileManager interface {
	// GetImage returns the image to be used for a given cell style.
	GetImage(gruid.Cell) image.Image

	// TileSize returns the (width, height) in pixels of the tiles. Both
	// should be positive and non-zero.
	TileSize() gruid.Point
}

TileManager manages tiles fetching.

Jump to

Keyboard shortcuts

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