hbg

package
v0.0.0-...-47a16e8 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BaseLayer = iota
	CornersLayer
	EncroachmentsLayer
	AdornmentsLayer // AdornmentsLayer has trees, bushes, rocks, anything with a bit of three-dimensionality.
)

Variables

This section is empty.

Functions

func ConstructBackground

func ConstructBackground(terrain map[geom.Key]procedural.Code, baseTiles map[procedural.Code]BaseTile, encroachments EncroachmentsCollection, field *geom.Field, prng *rand.Rand, handler ComponentHandler)

ConstructBackground takes terrain and translates it into handler calls that define the hexes that compose a background.

Types

type BaseTile

type BaseTile struct {
	Code    procedural.Code `json:"code"`
	Texture string          `json:"texture"`

	Variations Options `json:"variations"`
}

type ComponentHandler

type ComponentHandler func(frames ComponentHandlerCall)

type ComponentHandlerCall

type ComponentHandlerCall struct {
	Frames []ComponentHandlerFrame
	X, Y   int
	Z      Layer
}

type ComponentHandlerFrame

type ComponentHandlerFrame struct {
	Texture    string
	Duration   time.Duration
	L, T, W, H int
}

type Corner

type Corner struct {
	Options Options
	Offset  Offset
	W       int
	H       int
}

type CornerCollection

type CornerCollection struct {
	Texture string
	Corners map[geom.DirectionType]Corner
}

func (CornerCollection) MarshalJSON

func (e CornerCollection) MarshalJSON() ([]byte, error)

func (*CornerCollection) UnmarshalJSON

func (e *CornerCollection) UnmarshalJSON(data []byte) error

type EdgeCollection

type EdgeCollection struct {
	Texture string                         `json:"texture"`
	Options map[geom.DirectionType]Options `json:"options"`
}

EdgeCollection maps the direction of neighbors to the appropriate encroachment info. type EdgeCollection map[geom.DirectionType]Options

func (EdgeCollection) MarshalJSON

func (e EdgeCollection) MarshalJSON() ([]byte, error)

func (*EdgeCollection) UnmarshalJSON

func (e *EdgeCollection) UnmarshalJSON(data []byte) error

UnmarshalJSON

type Encroachment

type Encroachment struct {
	Description string          `json:"description"`
	Over        procedural.Code `json:"over"`
	Adjacent    procedural.Code `json:"adjacent"`

	Edges   EdgeCollection   `json:"edges"`
	Corners CornerCollection `json:"corners"`
}

type EncroachmentsCollection

type EncroachmentsCollection map[string]Encroachment

EncroachmentsCollection is a mapping between the over and the adjacent codes of an encroachment, and the Encroachment itself. Keys are formatted as fmt.Sprintf("%s<-%s",over,adjacent). The idea is that there is one collection that is loaded in layers. First from core stuff built-in to the base game, then from a datafile if present, and also from an uncompressed directory structure potentially.

func (EncroachmentsCollection) Get

func (ec EncroachmentsCollection) Get(over, adjacent procedural.Code) *Encroachment

func (EncroachmentsCollection) Put

type Frame

type Frame struct {
	Duration time.Duration `json:"duration"`
	Left     int           `json:"left"`
	Top      int           `json:"top"`
}

func (Frame) MarshalJSON

func (f Frame) MarshalJSON() ([]byte, error)

func (*Frame) UnmarshalJSON

func (f *Frame) UnmarshalJSON(data []byte) error

type Intner

type Intner interface {
	Intn(int) int
}

Intner is anything that provides an Intn method -- i.e. a *rand.Rand.

type Layer

type Layer int

type Offset

type Offset struct {
	X int
	Y int
}

type Option

type Option struct {
	Chance      int     `json:"chance"`
	Frames      []Frame `json:"frames"`
	ExtraHeight int     `json:"extraHeight"`
	ExtraDepth  int     `json:"extraDepth"`
}

type Options

type Options []Option

func (Options) Roll

func (o Options) Roll(intn func(int) int) *Option

Roll the Options, taking the weighting of the relative Chances to pick one based on the randomized input from the passed intn function. Pass rand.Intn to quickly get non-reproducible, pseudo-random results. Will return nil if there are no Options. Will skip the call to the passed random number source if the collection of Options has less than 2 members.

Jump to

Keyboard shortcuts

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