Documentation ¶
Index ¶
- func NewParseFunc[TileType Tile](parseTile func(r rune) (TileType, error), options ...MapOption) func([]byte) (*Map[TileType], error)
- func NewStreamingParseFunc[TileType Tile](parseTile func(r rune) (TileType, error), options ...MapOption) func([]byte) stream.Stream[*Map[TileType]]
- func Rotate[TileType Tile](m *Map[TileType], direction Direction)
- func Tilt[TileType Tile](m *Map[TileType], direction Direction, MovableTile TileType)
- type AnyTile
- type Direction
- type Map
- func (m *Map[TileType]) AddFlagAt(pos Pos, flag TileType)
- func (m *Map[TileType]) CaptureFrame(label string, delay int)
- func (m *Map[TileType]) Get(pos Pos) (rtn TileType, valid bool)
- func (m *Map[TileType]) InBounds(pos Pos) bool
- func (m *Map[TileType]) IndexOf(pos Pos) int
- func (m *Map[TileType]) Neighbours(pos Pos) (rtn []Pos)
- func (m *Map[TileType]) PositionOf(idx int) Pos
- func (m *Map[TileType]) RemoveFlagAt(pos Pos, flag TileType)
- func (m *Map[TileType]) SaveAnimationGIF(ctx *runner.Context) error
- func (m *Map[TileType]) Set(pos Pos, tile TileType) (valid bool)
- func (m *Map[TileType]) StartCapturingFrames(ctx *runner.Context)
- func (m *Map[TileType]) StopCapturingFrames(label string)
- func (m *Map[TileType]) String() string
- type MapOption
- type Pos
- type Tile
- type TileRender
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewParseFunc ¶
func NewParseFunc[TileType Tile](parseTile func(r rune) (TileType, error), options ...MapOption) func([]byte) (*Map[TileType], error)
NewParseFunc creates a new parser that will parse exactly one map from the given byte slice.
If more than one map is found, an error will be returned. If you want to parse multiple maps then use NewStreamingParseFunc.
func NewStreamingParseFunc ¶
func NewStreamingParseFunc[TileType Tile](parseTile func(r rune) (TileType, error), options ...MapOption) func([]byte) stream.Stream[*Map[TileType]]
NewStreamingParseFunc creates a new stream parser that will parse one or more maps from an original byte slice.
If you only need to parse a single map use NewParseFunc.
Types ¶
type AnyTile ¶
type AnyTile interface { // Valid returns true if this tile is a valid tile. Valid() bool // Rune should return the single rune that represents // this tile. Rune() rune // Colour is the colour of the tile when displayed // in an animation. Colour() color.Color }
AnyTile represents an untyped tile that can be used in a Map.
type Direction ¶
type Direction uint8
Direction represents a direction on a map.
func (Direction) FlipHorizontal ¶
type Map ¶
type Map[TileType Tile] struct { Width int // The width of the map Height int // The height of the map // Tiles are all the [Tile]'s that make up the map. // // The tiles are laid out by rows, such that // indexes 0 -> Width are row 1, and indexes // Width -> Width * 2 are row 2. Tiles []TileType // EmptyType represents empty space in the map and // is by default the zero value of [Tile]. EmptyType TileType TileRender TileRender // How to render the tiles TilePalette []color.Color // The palette of colours to use when rendering the tiles MinTileSize int // The minimum size of the map when rendered MaxTileSize int // The maximum size of the map when rendered Frames []frame[TileType] // The frames of the we've captured // contains filtered or unexported fields }
Map represents a two dimensional map of some set of Values.
The zero value of Tile is expected to be "empty" (i.e. in the case of flood filling, it's not a wall). If you want to change this override the [EmptyType] field.
func From2DSlices ¶
From2DSlices creates a new map from the given 2D slice of tiles. where the first index is the y position, and the second index is the x position.
func New ¶
New creates a new map with the given width and height will all tiles set to the zero value of Tile.
func (*Map[TileType]) AddFlagAt ¶
AddFlagAt adds the given flag to the tile at the given x, y position.
func (*Map[TileType]) CaptureFrame ¶
CaptureFrame captures the current state of the map as a frame with the given label and delay if and only if we are currently capturing frames. Otherwise this function does nothing.
func (*Map[TileType]) Get ¶
Get returns the tile at the given x, y position.
If the position is out of bounds, then valid will be false, and rtn will be the zero value of Tile.
Otherwise valid will be true, and rtn will be the tile at the given position.
func (*Map[TileType]) InBounds ¶
InBounds returns true if the given position is in bounds of the map.
func (*Map[TileType]) Neighbours ¶
Neighbours returns the neighbours of the given position.
func (*Map[TileType]) PositionOf ¶
PositionOf returns the x, y position of the given index.
func (*Map[TileType]) RemoveFlagAt ¶
RemoveFlagAt removes the given flag from the tile at the given x, y position.
func (*Map[TileType]) SaveAnimationGIF ¶
func (*Map[TileType]) Set ¶
Set sets the tile at the given x, y position.
If the position is out of bounds, then valid will be false, otherwise valid will be true.
func (*Map[TileType]) StartCapturingFrames ¶
StartCapturingFrames starts capturing frames for the map starting with the current state of the map
func (*Map[TileType]) StopCapturingFrames ¶
StopCapturingFrames stops capturing frames for the map
type MapOption ¶
type MapOption func(cfg *mapCfg)
MapOption represents an option that can be applied to a map
func WithColourPalette ¶
WithColourPalette sets the colour palette for the map
If not set, the map will compute the palette from the tiles by iterating from the zero value, until it gets false from a call to [Tile.Valid]
func WithMaxTileSize ¶
WithMaxTileSize sets the maximum tile size for the map when rendering
func WithMinTileSize ¶
WithMinTileSize sets the minimum tile size for the map when rendering
func WithTileRender ¶
func WithTileRender(render TileRender) MapOption
WithTileRender sets the tile render function for the map
If not set, the map will render each tile fully in the colour of the tile