board

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 56 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package board lays a square or hex grid over the game world, with per-cell terrain (who may pass, how fast one goes) and occupancy. Entities on the board move at the pace the terrain and the game's mobility give them, solid cells push them out and veiled ones dim sight, and plugins/navigation builds pathfinding on top. A board stands only in a world with heights (world.Config.Heights).

Packages

What a game uses is this package and its public subpackages: cell (one cell: its id and kind, its ground and way, what stands on it, the moment cell.Now, its occupancy), unit (an entity on the board: unit.At, unit.Mover, unit.Standing), grid (the topology), look (how the board is drawn), ground (what its ground is to the other plugins) and network, water (ways across the board). The machinery is in plugins/board/internal.

Board, Layout and kinds

Plugin, built over a grid.Grid, a cell.Occupancy and the world plugin, seeds its terrain from a Layout when the Stage starts fresh. Every cell is an entity carrying cell.Plot, cell.Ground, cell.Way and cell.Built, saved with the game, so an effect on it is an effect on the terrain. Kinds are defined through Read.CellKinds.

Read and Write

The board's state is read through Plugin.Read and changed through Plugin.Write: Read(w) is worker w's of the game's pool (0 the game's own goroutine), each with queries and scratch of its own, so the workers read the board at once; Write is the game's goroutine's. Read(w).Board() reads the grid and the terrain (BoardRead), Write().Board() writes the terrain (BoardWrite). NewBoard is a board with no plugin, for a test.

Rules

Every step the board runs the rules of its moments, which the roles obey: a unit.Standing for every entity on the board (the cell under it, its kind on the unit's level, whether it has Fallen where its domain may not be), none for one on no cell (below), and a cell.Now for every cell. The board names its places for cond.At and act.At: Around(n) are the cells within n rings of those under the entity and the entities standing on them (0: those under it alone), Ahead(n) the cells one to n steps in front of a unit, the way it faces (a cell faces nowhere). The same pass writes every unit's steering.Pace from the ground under it.

Entities standing on the board

A lever, a trapdoor, a gate, a plate is an entity standing still on a cell: NewEntities binds a game's rows of them and Entities.Define makes a kind, carrying cell.On and whatever the game gives besides, a cell.Floor, a cell.Wall, a cell.Rail, the roles it plays. The board gathers them on the cells' entities every step (cell.Built), and BoardRead.Kind and BoardRead.Bare are the cells with them. What each kind carries beyond what it is given is its StandingTemplate's (world.Plugin.Roster): standing still, its shadow Baked into the ground's shade (light.Shadow); a unit's is a live patch. Every cell carries what its CellTemplate asks besides the board's own. A Floor with a Height is a storey, raised over the cell (a deck) or sunk under it with the room Clear over it (a tunnel's floor), and gives the cell a level beside its ground, up to cell.Levels of them, a Floor naming its Storey; a Floor Standing, with its room Clear, is a storey at any height, a house's room built on the ground, the cell's ground shut and its foundation solid under it. A room of whole cells is walled round them but where its Links lead, on into its storey or out by its Door (BoardRead.Rooms, BoardRead.Dug, BoardRead.Housed) (BoardRead.KindAt, BoardRead.KindFor, BoardRead.CellFor, BoardRead.LevelFor); one with a Width and Links is a band (BoardRead.DecksOver, BoardRead.Reaches), its railings never stepped across (BoardRead.Fenced); a step along it takes a body no wider than its BoardRead.Lane. BoardRead.Limits is what a cell limits a body by beyond its kind, a floor's load and a wall's gap (BoardRead.Limited). A unit's box past a cell takes a footprint of cells a side (unit.Footprint), up to DefaultFootprint unless Plugin.WithFootprint sets another (NewUnits panics past it): an odd one laid round the cell its unit is At, an even one from it right and down, its unit standing on the corner its middle cells share (unit.Place). BoardRead.Railed says whether a railing runs along a cell's own band. Plugin.UnitKinds lists the kinds of unit defined over the board (UnitKind).

Bridges

A bridge, the cells whose Graded bands join along their links, runs straight and level from a head to a head, its deck Bridges.Clearance over the ground between (Plugin.WithBridges). A level laying one that breaks the rules fails with its file and line; one broken later is not built, said in the log. Where one may be built is plugins/bridges'.

Level

A game's map is a YAML file; kinds stay in the game's code, the file names them.

board:
  default: grass
  legend:
    ".": grass
    "~": {kind: water, plays: [lake], group: lake}
  cells: |
    ..~~..
  entities:
    - {kind: trapdoor, group: west trapdoors, at: [2, 0]}
relief:
  cells: |
    0 0 2.5 2.5 0 0
ways:
  roads: {road: {width: 12, paths: [[[0, 0], [5, 0]]]}}
  rivers:
    - [{at: [1, 0], kind: brook, width: 3}, [1, 1]]
units:
  - {kind: scout, side: player, name: ann, start: [0, 1]}

Plugin.Lay seeds the board out of the file in the Spawn section and hands back a Level: its relief for a topography's Seed (Level.Heights), the kinds it lays its cells as for what a game stands by them there, where the board has no cells yet (Level.Kind), and its entities, which Spawn seeds the world with a type of row at a time, the row's fields tagged yaml being the entry's keys:

level, err := s.board.Lay(mapFile, "map.yaml")
s.topography.Seed(level.Heights())
return board.Spawn[unitRow](level, board.Sides{PlayerSide: {players.Give{To: s.player.ID}}})

A Sides is the commands the game gives its entities as they are made. An error says the file and the line; an entity no Spawn took fails the board's Populate. A road never runs over a river: a point {onto: [x, y]} leads it onto the bridge or the ford standing there. With a relief every cell of a Graded road lies level or on an even ramp (ground.RoadFits), by its corners on either grid. A hex relief given by cells bends the cell where level ground turns into a ramp, a corner being the mean of three cells, so a road climbing there leads onto a bridge or a ford at its ends.

Commands

Grid shows or hides the board's grid (Write.ShowGrid from a scene); Holds the cells the occupancy holds (Write.ShowHolds, each an outline over its cell). Neither has a key: hand the board to players.NewPlugin for the settings screen.

Ways

A cell.Way is what runs across a cell over its ground, a band Width wide from the cell's middle out towards each neighbour its Links name. BoardRead.Way and BoardWrite.SetWay read and write them, BoardRead.Along tells a step along a way from one over the ground beside it, BoardRead.Bare is that ground. BoardRead.CellVersion and BoardRead.Changes count the changes, so whoever keeps something worked out of a cell knows when it is stale; BoardWrite.Touch counts one made beyond the board. BoardRead.Passage and BoardRead.CellPassage count only the changes to what a step over a cell reads, so a route worked out stands while what stands on a cell sways or a cell is painted anew.

Heights, ground and occupancy

The board is flat: what is high or steep is its Map's (plugins/topography), which says how steep every step is (Map.Rise); how fast a unit goes over it is the game's cell.Mobility, given with Plugin.WithMotion and read by the pace and the planner alike (Read.Pace), so what the planner refuses the unit never walks. The board is the ground the other plugins meet: Read.Heights, Read.Footing, Read.Cover for sight, and its Solid cells the solid ground collision pushes colliders out of (Plugin.WithCollision). Its cell.Occupancy tracks who holds each cell; the board has every unit hold the cell it stands on and lets go of the holds of whoever left the world. A unit travelling the abstract graph (sector.Abstract) holds none and keeps its whole pace, and an aggregate its parts stand for (world.Unfolded) holds none: each is on no cell. A part laid off its aggregate, or an aggregate folded, holding no cell yet where its domain may not stand or another holds, is moved onto the nearest cell that takes it, a few rings round at most, before it is told where it stands.

Drawing

The board's own Map is the simple map: a flat ground seen from above, every kind in its sprite, the ways as bands, laid on the GPU every frame and lit per pixel under the light plugin by its distant light, the shadows it baked and the lamps, as each cell takes them (cell.Kind.Takes). Plugin.WithMap puts another in. How a kind looks is its tile's, gathered on the board's Atlas once the Stage is set up, every sprite the cell's size across (a game declaring looks by hand closes its own before, Plugin.NewAtlas); a state of the ground is an effect on its cells, shown as a cover (Plugin.Covering, Slot.Under). In a world cut into sectors the cells drawn are those of the sectors a camera sees: plainly, undressed and with no grid where it sees them coarsely, under the sheet of what stands there laid flat from L4 (world.Read.Sheet), fading into the fog before its sight's end. Write.Miniature is the board flat from above as one picture, a minimap's ground.

Tiles and figures

A Tile is a kind of cell in one piece: Define its cell.Kind and the roles its cells play, Look its look on the board's Atlas and its covers under effects, and, Stateful or Ruled, its own effects and rules. A Figure is a kind of entity standing on the board the same way: Define over the board (NewUnits, NewEntities), Look on the world's atlas as any figure's. Plugin.Tiles and Plugin.Figures, called in the Stage's Figures link, hand them on to the world's figures, which the Stage leads through its sections; Atlas.Looks declares the tiles' looks, then the surfaces', the world atlas's the figures'.

Surface

A Surface is how the board looks beyond its tiles: its Look sets on the board's Atlas the Line the grid is drawn in (Atlas.Grid) and how wide a cell held is outlined (Atlas.Holds). Plugin.Surfaces, called in the Stage's Figures link, notes them, a later setting taking the place of an earlier; none draws DefaultGridLine and DefaultHoldWidth.

Vocabulary

Moments, for a role's rules: unit.Standing (every unit a step; places Around, Ahead; its words unit.Fallen, unit.StandingOn, unit.OnKind) and cell.Now (every cell a step; places Around). Knobs, for an effect's Alter: cell.Ground (a cell's kind), cell.Floor, cell.Wall, cell.Rail (what stands on it). Commands, a player's: Grid, Holds (looks).

Index

Examples

Constants

View Source
const DefaultFootprint = 3

DefaultFootprint is the most cells a side a unit's footprint takes on a board: a box past a cell narrower than three cells.

View Source
const DefaultHoldWidth = 2

DefaultHoldWidth is how many pixels wide a cell held is outlined when no surface says otherwise.

Variables

View Source
var (
	StandingTemplate = kind.NewTemplate("standing", world.EntityTemplate)
	CellTemplate     = kind.NewTemplate("cell", nil)
)

The board's templates: a kind standing still on it, and its cells.

Functions

func Ahead added in v0.3.0

func Ahead(steps int) host.Places

Ahead are the places on the cells one to steps in front of a unit, the way it faces, the nearest first: whom cond.At and act.At turn a rule of unit.Standing to.

func Around added in v0.3.0

func Around(rings int) host.Places

Around are the places within rings of where a unit stands, those under its box first, or of a cell: whom cond.At and act.At turn a rule of unit.Standing or cell.Now to, 0 the cell itself.

func Each added in v0.3.0

func Each[R any](level *Level, f func(kind string, row R, at string) error) error

Each hands f, in the file's order, every row of R the level's entities have, with the kind it names and the file and line it is written at, and takes them as Spawn does; f's error ends the walk.

func NewBoard

func NewBoard(g grid.Grid) (*BoardRead, *BoardWrite)

NewBoard is a board over g with no plugin, every cell of the zero kind until it is set: what reads it and what writes it.

func Spawn added in v0.3.0

func Spawn[R any](level *Level, sides Sides) error

Spawn seeds the world with the entities of level whose kinds have rows of R, sides being the commands of the sides the entries name; an entity no Spawn takes fails the board's Populate.

Types

type Atlas added in v0.3.0

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

Atlas is the board's looks under construction: Add each kind's look by its name, chain Under for its covers, set the surface's Grid and Holds, then Close it: the board takes it as its looks.

func (*Atlas) Add added in v0.3.0

func (a *Atlas) Add[L render.Look](kind string, look L) Slot

Add takes look on as the look of the cell kind named kind: a SpriteDrawer drawn once into the sheet, or a MaterialID worked out per pixel every frame. An unknown kind panics by name.

func (*Atlas) Atlas added in v0.3.0

func (a *Atlas) Atlas() *render.Image

Atlas is the baked sheet.

func (*Atlas) Close added in v0.3.0

func (a *Atlas) Close()

Close lays the sheet out, bakes it and hands it to the board (Write.SetAtlas); call once, after the last look.

func (*Atlas) Grid added in v0.3.0

func (a *Atlas) Grid(l Line)

Grid sets the line the board's grid is drawn in.

func (*Atlas) Holds added in v0.3.0

func (a *Atlas) Holds(width float32)

Holds sets how many pixels wide a cell held is outlined.

func (*Atlas) Looks added in v0.3.0

func (a *Atlas) Looks() *Atlas

Looks declares every tile's look on the atlas, in the order the tiles were noted, then every surface's, and hands the atlas back to Close.

func (*Atlas) UV added in v0.3.0

func (a *Atlas) UV(id render.SpriteID) (sx0, sy0, sx1, sy1 float32)

UV is a sprite's rectangle on the sheet.

func (*Atlas) White added in v0.3.0

func (a *Atlas) White() (u, v float32)

White is the white texel plain colours sample.

type Atmosphere added in v0.3.0

type Atmosphere interface {
	DrawnAir() air.Weather
}

Atmosphere is the weather over a flat board as the frame drawn reads it: what leans what sways and whose clouds shade the ground; plugins/atmosphere's Read. The light is the light plugin's.

type BoardRead added in v0.4.0

type BoardRead struct {
	grid.Grid
	// contains filtered or unexported fields
}

BoardRead reads a board, its grid and its terrain, on one goroutine at a time: the main one's through the board's own queries, a Fork's through queries of its own.

func (*BoardRead) Along added in v0.4.0

func (r *BoardRead) Along(from, to cell.ID) bool

Along reports whether a way or a Floor's band runs from from to its neighbour to, so a step between them goes along it rather than over the ground beside it.

func (*BoardRead) Bare added in v0.4.0

func (r *BoardRead) Bare(c cell.ID) cell.Kind

Bare is c's kind bare of what runs across it, a way or a bridge: the ground a step beside them crosses; off the board, the zero kind.

func (*BoardRead) Built added in v0.4.0

func (r *BoardRead) Built(c cell.ID) cell.Built

Built is what the entities standing on c build over it as of the board's last step; none off the board.

func (*BoardRead) CellEntity added in v0.4.0

func (r *BoardRead) CellEntity(c cell.ID) (uid.UID64, bool)

CellEntity is the entity of cell c; false off the board or before the ECS is set up.

func (*BoardRead) CellFingerprint added in v0.21.0

func (r *BoardRead) CellFingerprint(c cell.ID) uint64

CellFingerprint is a number of what a step over c reads of it, its passage and the height under its middle, the same on every run for the same cell: a file kept of what was worked out over the board, a hierarchy of its routes, is good where its cells match.

func (*BoardRead) CellFor added in v0.4.0

func (r *BoardRead) CellFor(p geom.Vec, feet, reach float32) (cell.ID, bool)

CellFor is the cell whoever stands at p with its feet at feet and steps reach high is on: the cell of the highest deck over p within reach, else the cell under p. Feet at +Inf stand on any deck.

func (*BoardRead) CellPassage added in v0.11.0

func (r *BoardRead) CellPassage(c cell.ID) uint64

CellPassage is the Passage at which c's passage last changed; it only grows.

func (*BoardRead) CellVersion added in v0.4.0

func (r *BoardRead) CellVersion(c cell.ID) uint64

CellVersion counts the changes to c alone; it only grows.

func (*BoardRead) Changes added in v0.4.0

func (r *BoardRead) Changes() uint64

Changes counts the changes to the board's cells: while it stays as it was, no cell has changed.

func (*BoardRead) DecksOver added in v0.4.0

func (r *BoardRead) DecksOver(p geom.Vec, visit func(c cell.ID, f cell.Floor))

DecksOver calls visit with every Floor over p and the cell it is built on, a neighbour's band reaching over p too.

func (*BoardRead) Dug added in v0.22.0

func (r *BoardRead) Dug() bool

Dug reports whether a room is dug under the ground of any cell of the board.

func (*BoardRead) Fenced added in v0.4.0

func (r *BoardRead) Fenced(from, to cell.ID, d cell.Domain, level cell.Level) bool

Fenced reports whether a railing keeping d off stands across the step from from to its neighbour to on level.

func (*BoardRead) FloorDip added in v0.22.0

func (r *BoardRead) FloorDip(c cell.ID, f cell.Floor) float32

FloorDip is how far under its middle the band f of c, raised or sunk, lies at its lowest edge: it climbs evenly on to the floors and the ground its links name.

func (*BoardRead) Fork added in v0.4.0

func (r *BoardRead) Fork() *BoardRead

Fork reads the same board through queries and scratch of its own, for another goroutine.

func (*BoardRead) Housed added in v0.22.0

func (r *BoardRead) Housed() bool

Housed reports whether a room stands on the ground of any cell of the board.

func (*BoardRead) Kind added in v0.4.0

func (r *BoardRead) Kind(c cell.ID) cell.Kind

Kind is c's terrain kind as whoever crosses it meets it, its Way and what is built over it included; off the board, the zero kind admitting nobody.

func (*BoardRead) KindAt added in v0.4.0

func (r *BoardRead) KindAt(c cell.ID, level cell.Level) cell.Kind

KindAt is c's kind on level; Kind on a cell of one level.

func (*BoardRead) KindFor added in v0.4.0

func (r *BoardRead) KindFor(c cell.ID, p geom.Vec, feet, reach float32) cell.Kind

KindFor is c's kind at p, a point in c, on the level of whoever has its feet at feet and steps reach high: a deck over p within reach, else what lies under.

func (*BoardRead) Lane added in v0.4.0

func (r *BoardRead) Lane(from, to cell.ID, d cell.Domain, level cell.Level) float32

Lane is how wide a body may be across the step from from to its neighbour to in d where a deck's band runs along it on level; +Inf where no band narrows the step. The railings keeping d off are taken off the band's width.

func (*BoardRead) LevelFor added in v0.4.0

func (r *BoardRead) LevelFor(p geom.Vec, feet, reach float32) (c cell.ID, level cell.Level,
	ok bool)

LevelFor is CellFor and the level whoever stands there stands on.

func (*BoardRead) Limited added in v0.13.0

func (r *BoardRead) Limited() bool

Limited reports whether a floor's Load or a wall's Gap limits whom a cell takes anywhere on the board.

func (*BoardRead) Limits added in v0.13.0

func (r *BoardRead) Limits(c cell.ID, d cell.Domain, level cell.Level) (load float32,
	gap cell.Gap)

Limits are what c limits a body moving in d by beyond its kind on level: the Load of the floor carrying it where its ground would not, and the Gap of the wall keeping d off; zero where nothing does.

func (*BoardRead) Map added in v0.4.0

func (r *BoardRead) Map() MapRead

Map is what the board is drawn and priced by, its cells' kinds read through r: the plugin's, or the simple map on a board no plugin runs.

func (*BoardRead) NarrowestDeck added in v0.4.0

func (r *BoardRead) NarrowestDeck() float32

NarrowestDeck is how wide the narrowest Floor running as a band is; 0 for none.

func (*BoardRead) NearDeck added in v0.4.0

func (r *BoardRead) NearDeck(p geom.Vec) bool

NearDeck reports whether a Floor lies over any of the cell under p.

func (*BoardRead) Ordinal added in v0.4.0

func (r *BoardRead) Ordinal(c cell.ID) (int, bool)

Ordinal is c's slot in a table of one per cell.

func (*BoardRead) Passage added in v0.11.0

func (r *BoardRead) Passage() uint64

Passage counts the changes to what a step over the cells reads (who a cell admits and at what pace, its way, what is built over it, its heights): while it stays as it was, no cell's passage changed. It only grows.

func (*BoardRead) Railed added in v0.14.0

func (r *BoardRead) Railed(c cell.ID, d cell.Domain, level cell.Level) bool

Railed reports whether a railing keeping d off runs along c's own band on level: a band running on through c, a head carrying none.

func (*BoardRead) Reaches added in v0.4.0

func (r *BoardRead) Reaches(c, n cell.ID) bool

Reaches reports whether c's Floor runs out towards its neighbour n; through a corner only along a link.

func (*BoardRead) ReachesOn added in v0.22.0

func (r *BoardRead) ReachesOn(c, n cell.ID, level cell.Level) bool

ReachesOn is Reaches of the floor making c's level.

func (*BoardRead) Rooms added in v0.22.0

func (r *BoardRead) Rooms() bool

Rooms reports whether a floor of the board has a room over it, dug or standing.

func (*BoardRead) Shape added in v0.4.0

func (r *BoardRead) Shape() (grid.Shape, bool)

Shape is the board's grid's shape when it is one of grid.DefaultGrids; false for any other.

func (*BoardRead) States added in v0.4.0

func (r *BoardRead) States(c cell.ID) tag.Tags[effect.States]

States are the markers of the effects on c now.

func (*BoardRead) Storeyed added in v0.22.0

func (r *BoardRead) Storeyed() bool

Storeyed reports whether a floor gives any cell of the board a level beside its ground.

func (*BoardRead) ThinnestDeck added in v0.4.0

func (r *BoardRead) ThinnestDeck() float32

ThinnestDeck is how thick the thinnest raised band's slab is; 0 for none.

func (*BoardRead) Version added in v0.4.0

func (r *BoardRead) Version() uint64

Version counts the changes to the terrain; it starts over with a load.

func (*BoardRead) Way added in v0.4.0

func (r *BoardRead) Way(c cell.ID) cell.Way

Way is what runs across c; the zero Way off the board or where nothing does.

type BoardWrite added in v0.4.0

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

BoardWrite writes a board's terrain, on the game's goroutine.

func (*BoardWrite) Set added in v0.4.0

func (w *BoardWrite) Set(c cell.ID, kind cell.Kind)

Set assigns c's terrain kind, taking effect immediately.

func (*BoardWrite) SetAll added in v0.4.0

func (w *BoardWrite) SetAll(kind cell.Kind)

SetAll resets every cell's terrain kind to kind.

func (*BoardWrite) SetWay added in v0.4.0

func (w *BoardWrite) SetWay(c cell.ID, way cell.Way)

SetWay lays w across c, the zero Way taking what ran there away; it takes effect immediately.

func (*BoardWrite) Touch added in v0.4.0

func (w *BoardWrite) Touch(c cell.ID)

Touch counts a change to c made beyond the board, its heights shaped by a topography.

type Bridges added in v0.3.0

type Bridges struct{ Clearance float32 }

Bridges is what a bridge keeps to besides running straight and level from a head to a head: its deck Clearance over the ground under the middle of every cell between at least.

type Drawn added in v0.5.0

type Drawn interface {
	look.Board
	Way(c cell.ID) cell.Way
	States(c cell.ID) tag.Tags[effect.States]
	Version() uint64
}

Drawn is the board as the frame drawn reads it: a look.Board, and each cell's way, the markers of the effects on it and the count of the changes to the kinds' looks.

type Entities added in v0.3.0

type Entities[P any] struct {
	// contains filtered or unexported fields
}

Entities makes a game's kinds of entities standing on the board, a lever, a trapdoor, a gate: each stands still on the cell its row names, in a box of the Shape's Size at the cell's middle.

func NewEntities added in v0.3.0

func NewEntities[P any](brd *Plugin, shape Shape, at func(row P) cell.ID) *Entities[P]

NewEntities binds a game's rows of entities standing on the board to it: shape is their body, at the cell a row stands one on.

func (*Entities[P]) Define added in v0.3.0

func (e *Entities[P]) Define(name string, extra ...comp.Comp)

Define registers one kind of entity standing on the board, its entities carrying extra besides, in place of what the roster's Standing template gives and of a Z as tall as its shape; one standing off the board panics as it is spawned.

func (*Entities[P]) Named added in v0.3.0

func (e *Entities[P]) Named(name string) kind.Of[P]

Named is the kind of entity defined as name.

type Figure added in v0.3.0

type Figure interface {
	Define(b *Plugin)
	Look(a *world.Atlas, w *world.Plugin)
}

Figure is a kind of entity standing on the board in one piece: what it is, defined over the board in the Kinds section (NewUnits, NewEntities), and how it looks, declared on the world's atlas in a scene as any figure's. One with states of its own is Stateful, one with roles and rules of its own Ruled.

type Grid

type Grid struct{ Shown bool }

Grid shows the board's grid, or hides it (Settings.Grid). The settings screen alone.

func (Grid) Command added in v0.3.0

func (Grid) Command()

type Holds added in v0.3.0

type Holds struct{ Shown bool }

Holds shows the cells the occupancy holds, or hides them (Settings.Holds). The settings screen alone.

func (Holds) Command added in v0.3.0

func (Holds) Command()

type Layout

type Layout struct {
	Default string
	Cells   []cell.Entry
	Ways    []cell.WayEntry
}

Layout is a board's initial terrain for Write.Seed: Default fills every cell, each of Cells overrides one and each of Ways lays a cell.Way across a cell.

type Level added in v0.3.0

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

Level is a board laid out of a file by Plugin.Lay, its entities waiting for Spawn.

func (*Level) Heights added in v0.3.0

func (l *Level) Heights() func(p geom.Vec) float32

Heights is the ground's heights the level's relief gives, in world units; nil for a level without one.

func (*Level) Kind added in v0.22.0

func (l *Level) Kind(c cell.ID) (name string, crossed bool)

Kind is the name of the kind the level lays the cell c as and whether it lays a way across it: what a game standing things by its board reads in the Spawn section, where the board has no cells yet.

type Line added in v0.3.0

type Line struct {
	Color color.RGBA
	Width float32
}

Line is a line of the board's surface: its colour and its width in screen pixels, 0 for none.

func DefaultGridLine added in v0.3.0

func DefaultGridLine(g grid.Grid) Line

DefaultGridLine is the line the grid g is drawn in when no surface says otherwise.

type Map added in v0.3.0

type Map interface {
	// Look is how the cells lie on the screen through a camera.
	Look() look.Look
	// Heights is the height of the ground at any point; nil on a flat map.
	Heights() ground.Heights
	// Dressing lays over the tiles what lies on them beyond their sprites; nil for nothing.
	Dressing() look.Dressing
	// Top is the height of c's corners as drawn (top-left, top-right, bottom-left, bottom-right)
	// with height, its kind's, standing on them, and of its ground; zero on a flat map.
	Top(c cell.ID, height float32) (corners [4]float32, level float32)
	// Rise is how steep the step from one cell to its neighbour is: the ground's rise between
	// their middles over the run, negative downhill; 0 on a flat map.
	Rise(from, to cell.ID) float64
}

Map is what a board is drawn by and how its ground lies beyond what its cells say, given by WithMap: how it looks, its heights and how steep a step is.

type MapRead added in v0.4.0

type MapRead interface {
	look.Map
	Rise(from, to cell.ID) float64
}

MapRead is a board's Map as a BoardRead reads it: a look.Map, a cell's kind read by the BoardRead, and how steep a step is.

type Plugin

type Plugin struct {
	*world.Self

	Res Resources
	// contains filtered or unexported fields
}

Plugin wires a Board into a Game; it depends on world, and hands collision its solid ground.

func NewPlugin

func NewPlugin(g grid.Grid, occupancy cell.Occupancy, worldPlugin *world.Plugin) *Plugin

NewPlugin builds a board over g with the given occupancy, slowing worldPlugin's entities; a world without heights panics.

func (*Plugin) Covering added in v0.3.0

func (p *Plugin) Covering(e effect.Effect) render.SpriteID

Covering is the slot of the board's atlas laid over the cells under the effect e, issued the first time it is asked for. Add what it shows to the atlas before it is closed; Slot.Under does both.

func (*Plugin) DefaultBindings added in v0.3.0

func (p *Plugin) DefaultBindings() []control.Binding

DefaultBindings are none: the grid and the cells held are the settings screen's.

func (*Plugin) EventHandler

func (p *Plugin) EventHandler() control.EventHandler

EventHandler is nil: the board handles no input of its own.

func (*Plugin) Figures added in v0.3.0

func (p *Plugin) Figures(figures ...Figure)

Figures notes the figures standing on the board among the world's, which the Stage leads through its sections: defined over the board, looked on the world's atlas. Called in the Stage's Figures link.

func (*Plugin) Install

func (p *Plugin) Install(ctx plugin.Installer) error

func (*Plugin) KindTemplates added in v0.3.0

func (p *Plugin) KindTemplates(r *kind.Roster)

KindTemplates is what the board asks of the kinds a game defines: of a unit, where it starts and the domains it moves in; of a kind standing on it, lying as it is, Fixed and casting a Baked shadow.

func (*Plugin) Lay added in v0.3.0

func (p *Plugin) Lay(fsys fs.FS, path string) (*Level, error)

Lay seeds the board out of the YAML level at path of fsys and keeps its entities for Spawn.

func (*Plugin) Name

func (p *Plugin) Name() string

func (*Plugin) NewAtlas added in v0.3.0

func (p *Plugin) NewAtlas(size int) *Atlas

NewAtlas starts the board's atlas for looks declared by hand, every sprite drawn size x size (the drawn size is the cell's box, this is resolution); Dress is the tiles' way.

func (*Plugin) Populate

func (p *Plugin) Populate() error

Populate applies the seeded Layout; an unknown kind name, or an entity of the level laid that no Spawn took, is an error and changes nothing.

func (*Plugin) Publish added in v0.5.0

func (p *Plugin) Publish()

RunPlan runs the board's step; call it after collision's RunPlan. Publish hands the frame drawn next the board's cells as they stand.

func (*Plugin) Queues added in v0.3.0

func (p *Plugin) Queues() []command.CommandQueue

Queues are where Grid and Holds land.

func (*Plugin) Read added in v0.4.0

func (p *Plugin) Read(w int) *Read

Read reads the board's state on worker w of the game's pool, 0 the game's own goroutine; the other workers' reads come with Use.

func (*Plugin) Restore added in v0.3.0

func (p *Plugin) Restore()

Restore takes the Settings loaded and shows what they say.

func (*Plugin) RunPlan

func (p *Plugin) RunPlan(ctx goke.RunCtx, d time.Duration)

func (*Plugin) Serializable

func (p *Plugin) Serializable() plugin.Serializable

Serializable is the board's Settings, kept whole; the terrain is the cells' entities, saved with the ECS.

func (*Plugin) Settings added in v0.3.0

func (p *Plugin) Settings() []control.Setting

Settings are the grid and the cells held (plugin.Tunable).

func (*Plugin) Surfaces added in v0.3.0

func (p *Plugin) Surfaces(surfaces ...Surface)

Surfaces notes the board's surfaces, each Look in the order noted after the tiles', a later setting taking the place of an earlier; none draws the defaults. Called in the Stage's Figures link.

func (*Plugin) Swap added in v0.5.0

func (p *Plugin) Swap()

Swap has the cells published last drawn.

func (*Plugin) Tiles added in v0.3.0

func (p *Plugin) Tiles(tiles ...Tile)

Tiles notes the tiles among the world's figures, which the Stage leads through its sections, and keeps them for the board atlas's Looks. Called in the Stage's Figures link.

func (*Plugin) UnitKinds added in v0.13.0

func (p *Plugin) UnitKinds() []UnitKind

UnitKinds are the kinds of unit defined over the board so far, in the order defined.

func (*Plugin) WithAtmosphere added in v0.3.0

func (p *Plugin) WithAtmosphere(a Atmosphere) *Plugin

WithAtmosphere puts the board under a's weather: what sways leans with the wind and the clouds' shadows lie on its ground. Call it after any other Map or Look is set, before the first frame.

func (*Plugin) WithBridges added in v0.3.0

func (p *Plugin) WithBridges(b Bridges) *Plugin

WithBridges has the board's bridges keep to b; zero has the deck no lower than the ground.

func (*Plugin) WithCollision added in v0.3.0

func (p *Plugin) WithCollision(c *collision.Plugin) *Plugin

WithCollision makes the board's Solid cells the solid ground c pushes colliders out of; call before Use.

func (*Plugin) WithFootprint added in v0.14.0

func (p *Plugin) WithFootprint(cells int) *Plugin

WithFootprint has the board take units whose footprint takes up to cells cells a side (unit.Footprint; DefaultFootprint without): the wider, the wider the planner's work round every cell changed. Call before NewUnits.

func (*Plugin) WithLog added in v0.3.0

func (p *Plugin) WithLog(l *log.Logger) *Plugin

WithLog has the board write a line to l for a unit fallen where its domain may not be; call before Use.

func (*Plugin) WithMap added in v0.3.0

func (p *Plugin) WithMap(m Map) *Plugin

WithMap has the board drawn and priced by m in place of the simple map. Call before Use.

Example

A game gives the board a map of its own: how it looks, how high its ground lies and how steep a step is.

package main

import (
	"fmt"
	"math"

	"github.com/kjkrol/aabbworld/geom"
	"github.com/kjkrol/gram/plugins/board"
	"github.com/kjkrol/gram/plugins/board/cell"
	"github.com/kjkrol/gram/plugins/board/grid"
	"github.com/kjkrol/gram/plugins/board/ground"
	"github.com/kjkrol/gram/plugins/board/look"
	"github.com/kjkrol/gram/plugins/world"
)

// ramp is a game's own map: flat to the eye, the ground rising a unit every ten eastwards
type ramp struct{ g grid.Grid }

func (ramp) Look() look.Look           { return look.Flat }
func (r ramp) Heights() ground.Heights { return rise{} }
func (ramp) Dressing() look.Dressing   { return nil }

func (r ramp) Top(c cell.ID, height float32) (corners [4]float32, level float32) {
	at := r.g.CellCenter(c)
	w, _ := r.g.CellBounds()
	west, east := (at.X-w/2)/10+height, (at.X+w/2)/10+height
	return [4]float32{west, east, west, east}, at.X / 10
}

func (r ramp) Rise(from, to cell.ID) float64 {
	a, b := r.g.CellCenter(from), r.g.CellCenter(to)
	run := math.Hypot(float64(b.X-a.X), float64(b.Y-a.Y))
	if run == 0 {
		return 0
	}
	return float64(b.X-a.X) / 10 / run
}

type rise struct{}

func (rise) At(p geom.Vec) float32 { return p.X / 10 }
func (rise) Step() float32         { return 32 }

// A game gives the board a map of its own: how it looks, how high its ground lies and how steep
// a step is.
func main() {
	w := world.NewPlugin(world.Config{
		Space:    world.SpaceCfg{Width: 320, Height: 320},
		Entities: world.EntitiesCfg{MaxCount: 1, MinSize: 1, MaxSize: 32},
		Heights:  true,
	})
	g := grid.DefaultGrids{}.Square(10, 10, 32)
	b := board.NewPlugin(g, &cell.SingleOccupancy{}, w).WithMap(ramp{g})
	fmt.Println(b.Read(0).Heights().At(geom.NewVec(160, 0)))
}
Output:
16

func (*Plugin) WithMotion added in v0.3.0

func (p *Plugin) WithMotion(m *motion.Plugin, mobility cell.Mobility) *Plugin

WithMotion has m move the board's units as mobility paces them (cell.DefaultHiking, or the game's own); a board without them has no units. Call before Use.

func (*Plugin) Write added in v0.4.0

func (p *Plugin) Write() *Write

Write changes the board's state, on the game's goroutine.

type Read added in v0.4.0

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

Read reads the board's state on one goroutine at a time: Plugin.Read(w), worker w's.

func (*Read) Atlas added in v0.4.0

func (r *Read) Atlas() render.AtlasSource

Atlas is the sprite sheet the board's renderer draws the cells from; nil before it is closed.

func (*Read) Board added in v0.4.0

func (r *Read) Board() *BoardRead

Board reads the board: its grid and its terrain.

func (*Read) CellKinds added in v0.4.0

func (r *Read) CellKinds() cell.Kinds

CellKinds are the kinds of cells registered.

func (*Read) Cover added in v0.4.0

func (r *Read) Cover() ground.Cover

Cover is what stands on the board and holds sight back.

func (*Read) Drawn added in v0.5.0

func (r *Read) Drawn() Drawn

Drawn is the board as the frame drawn reads it: its cells as last published, the live board before any was.

func (*Read) DrawnHeights added in v0.5.0

func (r *Read) DrawnHeights() ground.Heights

DrawnHeights is the height of the ground as the frame drawn holds it, for what draws: the Map's DrawnHeights where it has them, its Heights else; nil on a flat map.

func (*Read) Flat added in v0.7.0

func (r *Read) Flat(to cell.ID, k cell.Kind, level cell.Level, d cell.Domain) float64

Flat is Pace with no slope: the share on to's kind k on level, on the level.

func (*Read) Footing added in v0.4.0

func (r *Read) Footing() ground.Surfaces

Footing is where whoever moves over the board stands, the ground or a deck; nil on a flat map.

func (*Read) Fork added in v0.4.0

func (r *Read) Fork() *Read

Fork reads the same state through queries and scratch of its own, for another goroutine.

func (*Read) GridShown added in v0.4.0

func (r *Read) GridShown() bool

GridShown reports whether the grid is drawn.

func (*Read) Heights added in v0.4.0

func (r *Read) Heights() ground.Heights

Heights is the board's ground heights, its Map's; nil on a flat map.

func (*Read) HoldsShown added in v0.4.0

func (r *Read) HoldsShown() bool

HoldsShown reports whether the cells held are drawn.

func (*Read) Mobility added in v0.7.0

func (r *Read) Mobility() cell.Mobility

Mobility is what the board's units move by, given with WithMotion; nil on a board without units.

func (*Read) Occupancy added in v0.4.0

func (r *Read) Occupancy() cell.OccupancyRead

Occupancy is who holds the cells: the occupancy the plugin was built with.

func (*Read) Pace added in v0.7.0

func (r *Read) Pace(from, to cell.ID, k cell.Kind, level cell.Level, d cell.Domain) float64

Pace is the share of its top speed a unit moving in d keeps on the step from from onto to's kind k on level, the step's slope the Map's on the ground and the floors' own over it or under it; 0 refuses the step.

func (*Read) Sloped added in v0.7.0

func (r *Read) Sloped() bool

Sloped reports whether the Map has heights, so a step's pace may depend on its slope.

func (*Read) World added in v0.4.0

func (r *Read) World() *world.Plugin

World is the world the board lies over: its registers, for a figure defined over the board.

type Resources

type Resources struct {
	Render   *look.RenderState
	Settings Settings
}

Resources is board's published state; Render is nil until the atlas is closed.

type Ruled added in v0.3.0

type Ruled interface{ Rules(b *Plugin) }

Ruled is a Figure or a Tile with roles and rules of its own, defined in the Rules section.

type Settings added in v0.3.0

type Settings struct {
	Grid  bool
	Holds bool
}

Settings is what the board lets the players adjust, saved with the game: the looks of the grid and of the cells held.

type Shape added in v0.3.0

type Shape struct{ Size, Width, Height float32 }

Shape is a unit's body: the side of its box, Width across it where the box is no square (0: Size, square), and how tall it stands.

func (Shape) Box added in v0.3.0

func (s Shape) Box(c geom.Vec) plane.AABB

Box is the shape's box centred on c: Width across, Size down the screen.

type Sides added in v0.3.0

type Sides map[string][]command.Command

Sides are the commands the entities of each side a level names give themselves as they are made, by the side's name.

type Slot added in v0.3.0

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

Slot is one kind's look added to the board's Atlas.

func (Slot) Under added in v0.3.0

func (s Slot) Under(e effect.Effect, draw render.SpriteDrawer) Slot

Under adds the cover laid over the cells under e, one drawer an effect.

type Stateful added in v0.3.0

type Stateful interface{ Effects(b *Plugin) }

Stateful is a Figure or a Tile with effects of its own, defined in the Effects section.

type Surface added in v0.3.0

type Surface interface {
	Look(a *Atlas, b *Plugin)
}

Surface is how the board looks beyond its tiles: its Look sets on the board's atlas the line of the grid and the width of the cells held, the defaults standing in the rest.

type Tile added in v0.3.0

type Tile interface {
	Define(b *Plugin)
	Look(a *Atlas, b *Plugin)
}

Tile is a kind of cell in one piece: what it is, defined in the Kinds section, and how it looks and what covers it under an effect, declared on the board's atlas in a scene. Stateful and Ruled as a Figure is.

type UnitKind added in v0.13.0

type UnitKind struct {
	Name  string
	Mover unit.Mover
	Shape Shape
}

UnitKind is a kind of unit defined over the board: its name, how it moves and its body.

func (UnitKind) Z added in v0.13.0

func (k UnitKind) Z() world.Z

Z is the place in height the kind's units carry: the Shape's Height, their Altitude the board's to write.

type Units added in v0.3.0

type Units[P any] struct {
	// contains filtered or unexported fields
}

Units makes a game's unit kinds over the board, deriving Position, At, Layers and Z from where a row says the unit stands, its Mover and the Shape.

func NewUnits added in v0.3.0

func NewUnits[P any](brd *Plugin, shape Shape, at func(row P) geom.Vec) *Units[P]

NewUnits binds a game's rows to the board: shape is the units' body, at reads a unit's centre from its row. A unit bigger than a cell is planned where every cell its footprint takes takes it (unit.Footprint); a footprint past the board's (WithFootprint), or a board without motion and a mobility (Plugin.WithMotion), panics.

func (*Units[P]) Define added in v0.3.0

func (u *Units[P]) Define(
	name string,
	mover unit.Mover,
	steering steering.Steering,
	extra ...comp.Comp,
)

Define registers one kind of unit: how it moves, its steering profile and whatever else the game gives its entities. A unit standing off the board panics when spawned.

func (*Units[P]) Named added in v0.3.0

func (u *Units[P]) Named(name string) kind.Of[P]

Named is the kind of unit defined as name.

type Write added in v0.4.0

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

Write changes the board's state, on the game's goroutine.

func (*Write) Board added in v0.4.0

func (w *Write) Board() *BoardWrite

Board writes the board's terrain.

func (*Write) Miniature added in v0.4.0

func (w *Write) Miniature() (img *render.Image, perUnit float32)

Miniature is the board drawn flat from above, perUnit pixels a world unit, for a minimap to lay under its marks, as the frame drawn holds it; nil before the board's atlas is closed. It is drawn anew as the board changes and as the sun's light on it does.

func (*Write) Occupancy added in v0.4.0

func (w *Write) Occupancy() cell.Occupancy

Occupancy is who holds the cells, to take and let go of them.

func (*Write) Seed added in v0.4.0

func (w *Write) Seed(layout Layout)

Seed sets the terrain applied when the Stage starts fresh.

func (*Write) SetAtlas added in v0.4.0

func (w *Write) SetAtlas(atlas render.AtlasSource)

SetAtlas takes atlas as the board's looks for the board's renderer; a *Atlas's Close calls it, a foreign render.AtlasSource is given by hand. nil panics.

func (*Write) ShowGrid added in v0.4.0

func (w *Write) ShowGrid(shown bool)

ShowGrid draws the grid over the board, or not, as the Grid command switches it (Settings.Grid); shown from the start.

func (*Write) ShowHolds added in v0.4.0

func (w *Write) ShowHolds(shown bool)

ShowHolds shows the cells the occupancy holds, each an outline in its holder's colour, or hides them (Settings.Holds).

Directories

Path Synopsis
Package cell is a board's cell as a place: what it is, who may stand on it, what runs across it and the moment of it rules are written for.
Package cell is a board's cell as a place: what it is, who may stand on it, what runs across it and the moment of it rules are written for.
Package grid is a board's topology: a Grid answers which cells neighbour which and in which direction, where a cell lies, how far apart two are, which cells a box covers and every cell in turn; DefaultGrids makes a square or a hex one.
Package grid is a board's topology: a Grid answers which cells neighbour which and in which direction, where a cell lies, how far apart two are, which cells a box covers and every cell in turn; DefaultGrids makes a square or a hex one.
Package ground is what a board's ground is to the other plugins: the height of it at a point (Heights; a Profile knows it along a ray exactly), what stands on it and holds sight back (Cover, walked along a ray) and where whoever moves over it stands (Surfaces: the ground or a deck, and the deck over it).
Package ground is what a board's ground is to the other plugins: the height of it at a point (Heights; a Profile knows it along a ray exactly), what stands on it and holds sight back (Cover, walked along a ray) and where whoever moves over it stands (Surfaces: the ground or a deck, and the deck over it).
internal
boardtest
Package boardtest is what the board's tests share: an installer without an engine, a world of world, collision, board and vision ticked as a demo ticks them, the rows of its units, a game of one stage.
Package boardtest is what the board's tests share: an installer without an engine, a world of world, collision, board and vision ticked as a demo ticks them, the rows of its units, a game of one stage.
draw
Package draw is what the board draws by itself: the simple map's Bands, the ways and the covers the tile map lays over the tiles, and the Clouds' shadows on a flat board's ground under an atmosphere.
Package draw is what the board draws by itself: the simple map's Bands, the ways and the covers the tile map lays over the tiles, and the Clouds' shadows on a flat board's ground under an atmosphere.
field
Package field is a board's ground as the other plugins meet it: the cover that holds sight back along a ray (ground.Cover), kept as the cells change, and the solid ground collision pushes colliders out of and never over (collision.Field), read from the cells' terrain.
Package field is a board's ground as the other plugins meet it: the cover that holds sight back along a ray (ground.Cover), kept as the cells change, and the solid ground collision pushes colliders out of and never over (collision.Field), read from the cells' terrain.
grids
Package grids is the board's default grids, square and hex, with what the board's own parts read of them: the fields, Fold, SetWrap.
Package grids is the board's default grids, square and hex, with what the board's own parts read of them: the fields, Fold, SetWrap.
moments
Package moments runs the board's passes over its units and cells: Rules hosts the rules of a unit.Standing and of a cell.Now and runs them every step, telling each which cells lie round it (AroundPlaces) and, a unit, in front of it (AheadPlaces).
Package moments runs the board's passes over its units and cells: Rules hosts the rules of a unit.Standing and of a cell.Now and runs them every step, telling each which cells lie round it (AroundPlaces) and, a unit, in front of it (AheadPlaces).
occupancy
Package occupancy keeps a board's cell.Occupancy true to the world: KeepSystem has every unit hold the cell it stands on, following it wherever it goes, and lets go of the holds of whoever left the world; PlaceSystem moves a part laid off its aggregate onto a cell taking it; View draws the cells held.
Package occupancy keeps a board's cell.Occupancy true to the world: KeepSystem has every unit hold the cell it stands on, following it wherever it goes, and lets go of the holds of whoever left the world; PlaceSystem moves a part laid off its aggregate onto a cell taking it; View draws the cells held.
terrain
Package terrain is the state of a board's cells every part of the board reads: a seed until the ECS is set up, then the cells' entities, with the counts of changes to them and the dictionary of the kinds a game defined (Kinds).
Package terrain is the state of a board's cells every part of the board reads: a seed until the ECS is set up, then the cells' entities, with the counts of changes to them and the dictionary of the kinds a game defined (Kinds).
Package look is how a board is drawn.
Package look is how a board is drawn.
Package network is what runs from cell to cell across a board, rivers and roads, as a graph over its grid: the cells it runs through (Network.Set, a Node of a board kind, a width and a fade) and which neighbours each runs on to; a road [Network.Link]s its cells both ways, water [Network.Flow]s down to where it leaves the network.
Package network is what runs from cell to cell across a board, rivers and roads, as a graph over its grid: the cells it runs through (Network.Set, a Node of a board kind, a width and a fade) and which neighbours each runs on to; a road [Network.Link]s its cells both ways, water [Network.Flow]s down to where it leaves the network.
Package unit is an entity on a board: the cell it is At, how it moves over the cells and what it weighs (a Mover) and where it stands at a step as a rule gets it (Standing, with its Heading, so a rule's board.Ahead(n) turns to the cells in front of it; its words Fallen where its domain may not be, StandingOn a cell under an effect, OnKind a cell of a kind).
Package unit is an entity on a board: the cell it is At, how it moves over the cells and what it weighs (a Mover) and where it stands at a step as a rule gets it (Standing, with its Heading, so a rule's board.Ahead(n) turns to the cells in front of it; its words Fallen where its domain may not be, StandingOn a cell under an effect, OnKind a cell of a kind).
Package water works out the running water of a relief: where the rain on it gathers and runs to the sea, the brooks, streams and rivers it makes, the channels they cut and the fords across them.
Package water works out the running water of a relief: where the rain on it gathers and runs to the sea, the brooks, streams and rivers it makes, the channels they cut and the fords across them.

Jump to

Keyboard shortcuts

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