common

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Up is a direction
	Up = Direction(0)
	// Right is a direction
	Right = Direction(1)
	// Down is a direction
	Down = Direction(2)
	// Left is a direction
	Left = Direction(3)
)

Variables

View Source
var (
	// ErrElementNameInvalid is returned when a element name has invalid characters or too short
	ErrElementNameInvalid = fmt.Errorf("element name invalid")
	// ErrElementAlreadyExists is returned when a element already exists
	ErrElementAlreadyExists = fmt.Errorf("element already exists")
	// ErrElementNotFound is returned when a element is not loaded into the UI
	ErrElementNotFound = fmt.Errorf("element not found")
	// ErrFontNameInvalid is returned when a font name has invalid characters or too short
	ErrFontNameInvalid = fmt.Errorf("font name invalid")
	// ErrFontAlreadyExists is returned when a font already exists
	ErrFontAlreadyExists = fmt.Errorf("font already exists")
	// ErrFontNotFound is returned when a font was not found
	ErrFontNotFound = fmt.Errorf("font not found")
	// ErrFontCannotRemoveDefault is returned when you attempt to delete a font currently set as default
	ErrFontCannotRemoveDefault = fmt.Errorf("font is default, cannot remove")
	// ErrImageNameInvalid is returned when a image name has invalid characters or too short
	ErrImageNameInvalid = fmt.Errorf("image name invalid")
	// ErrImageAlreadyExists is returned when a image already exists
	ErrImageAlreadyExists = fmt.Errorf("image already exists")
	// ErrImageNotFound is returned when a image was not found
	ErrImageNotFound = fmt.Errorf("image not found")
	// ErrSceneNameInvalid is returned when a scene name has invalid characters or too short
	ErrSceneNameInvalid = fmt.Errorf("scene name invalid")
	// ErrSceneAlreadyExists is returned when a Scene already exists
	ErrSceneAlreadyExists = fmt.Errorf("scene already exists")
	// ErrSceneNotFound is returned when a scene is not loaded into the UI
	ErrSceneNotFound = fmt.Errorf("scene not found")
)
View Source
var (
	// ErrSliceNameInvalid is returned when a slice name has invalid characters or too short
	ErrSliceNameInvalid = fmt.Errorf("slice name invalid")
	// ErrSliceAlreadyExists is returned when a slice already exists
	ErrSliceAlreadyExists = fmt.Errorf("slice already exists")
	// ErrSliceNotFound is returned when a slice is not loaded into the UI
	ErrSliceNotFound = fmt.Errorf("slice not found")
)
View Source
var (
	// ErrNoNodesLoaded is returned when a path is called before any nodes are set
	ErrNoNodesLoaded = fmt.Errorf("no nodes are loaded")
	// ErrRouteNotFound is returned when all options are exhausted
	ErrRouteNotFound = fmt.Errorf("route not found")
)
View Source
var ZV = &Vector{0, 0}

ZV is a zero vector

Functions

func ColorToScale added in v0.0.11

func ColorToScale(clr color.Color) (float64, float64, float64, float64)

ColorToScale translates a color to ColorM

func DrawNineSlicing added in v0.0.11

func DrawNineSlicing(dst, src *ebiten.Image, sliceKey *SliceKey, width int, height int, geoM *ebiten.GeoM, colorM *ebiten.ColorM)

DrawNineSlicing will render slicing data

func DrawNineSlicingProgress added in v0.0.11

func DrawNineSlicingProgress(dst, src *ebiten.Image, sliceKey *SliceKey, width int, height int, value float64, geoM *ebiten.GeoM, colorM *ebiten.ColorM)

DrawNineSlicingProgress will render slicing data

func Index added in v0.0.11

func Index(gid uint32) uint32

Index strips a gid of rotation data

Types

type Animation added in v0.0.11

type Animation struct {
	//Counter tracks what animation frame is currently being played
	Counter int
	//Current sprite name being played
	CurrentName string
	//Speed to play animation
	Speed int
	//If the sheet has multiple sprites, which index of the bundle to use
	BundleIndex int
	CellWidth   float64
	CellHeight  float64
	Image       string
	Alpha       string
	Clips       [][]int
	BundleCount int
	Animations  map[string][][]float64
}

Animation handles animation details

type BoundStringCacheEntry added in v0.0.11

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

BoundStringCacheEntry is used for font boundings

type Direction added in v0.0.9

type Direction int

Direction represents a direction

func (Direction) String added in v0.0.9

func (d Direction) String() string

type Edge added in v0.0.9

type Edge struct {
	Dest   *Node
	Action Direction
	// contains filtered or unexported fields
}

Edge represents an edge of an node

func (*Edge) String added in v0.0.9

func (e *Edge) String() string

type Font added in v0.0.11

type Font struct {
	Face                font.Face
	Height              int
	Name                string
	Language            language.Tag
	BoundStringCache    map[font.Face]map[string]*BoundStringCacheEntry
	RenderingLineHeight int
}

Font contains related data for loading a font file

func (*Font) DrawText added in v0.0.11

func (f *Font) DrawText(dst *ebiten.Image, str string, ox, oy float64, scale float64, textAlign int, color color.Color, displayTextRuneCount int)

DrawText draws a text

type GID added in v0.0.11

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

GID represents a global ID, uses rotation padding on the last 3 bytes

func NewGID added in v0.0.11

func NewGID(gid uint32) (g GID)

NewGID returns a GID

func (GID) D added in v0.0.11

func (g GID) D() bool

D returns true if diagonal flagged

func (GID) H added in v0.0.11

func (g GID) H() bool

H reads if the tile should be changed horizontal

func (GID) Index added in v0.0.11

func (g GID) Index() uint32

Index returns an index without flipping data

func (GID) Rotation added in v0.0.11

func (g GID) Rotation() (rotation int)

Rotation returns the rotation of the object. Can only be 0, 90, 180, or 270

func (GID) SetD added in v0.0.11

func (g GID) SetD(val bool)

SetD changes the horizontal flag

func (GID) SetH added in v0.0.11

func (g GID) SetH(val bool)

SetH changes the horizontal flag

func (GID) SetRotation added in v0.0.11

func (g GID) SetRotation(rotation int) (err error)

SetRotation sets the rotation of a tile clockwise, supports 0, 90, 180, 270

func (GID) SetV added in v0.0.11

func (g GID) SetV(val bool)

SetV changes the horizontal flag

func (GID) SetValue added in v0.0.11

func (g GID) SetValue() uint32

SetValue sets the true GID value packed with rotation data

func (GID) V added in v0.0.11

func (g GID) V() bool

V returns true if a vertical rotation is in place

func (GID) Value added in v0.0.11

func (g GID) Value() uint32

Value returns the true GID value packed with rotation data

type Image added in v0.0.11

type Image struct {
	Name        string
	EbitenImage *ebiten.Image
	Slices      map[string]*Slice
	Animation   *Animation
}

Image is a base type representing a nebiten image with added details on how to render. An image is not rendered, instead placed into a cache

func (*Image) AddSlice added in v0.0.11

func (img *Image) AddSlice(s *Slice) error

AddSlice adds a 9slicing to an image

func (*Image) RemoveSlice added in v0.0.11

func (img *Image) RemoveSlice(s *Slice) error

RemoveSlice removes 9slicing data from an image

func (*Image) Slice added in v0.0.11

func (img *Image) Slice(name string) (*Slice, error)

Slice returns a 9 slice based on name

type Item added in v0.0.9

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

Item represents a node item

type LerpColor added in v0.0.11

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

LerpColor handles color lerp interpolations

func (*LerpColor) EndFunc added in v0.0.11

func (lc *LerpColor) EndFunc() func()

EndFunc returns the end function

func (*LerpColor) Init added in v0.0.11

func (lc *LerpColor) Init(start time.Time, startColor color.Color, endColor color.Color, duration time.Duration, endFunc func(), isDestroyedAtEnd bool)

Init sets up a new lerp

func (*LerpColor) IsDestroyed added in v0.0.11

func (lc *LerpColor) IsDestroyed() bool

IsDestroyed returns if enabled

func (*LerpColor) IsEnabled added in v0.0.11

func (lc *LerpColor) IsEnabled() bool

IsEnabled returns if enabled

func (*LerpColor) IsEndFuncSet added in v0.0.11

func (lc *LerpColor) IsEndFuncSet() bool

IsEndFuncSet returns true if EndFunc exists

func (*LerpColor) Lerp added in v0.0.11

func (lc *LerpColor) Lerp() (newColor color.Color)

Lerp returns a color

func (*LerpColor) SetEndFunc added in v0.0.11

func (lc *LerpColor) SetEndFunc(endFunc func())

SetEndFunc sets a function to call on end of lerp

func (*LerpColor) SetIsDestroyed added in v0.0.11

func (lc *LerpColor) SetIsDestroyed(isDestroyed bool)

SetIsDestroyed sets if destroyed on next frame or not

func (*LerpColor) SetIsEnabled added in v0.0.11

func (lc *LerpColor) SetIsEnabled(isEnabled bool)

SetIsEnabled sets if enabled or not

type LerpPosition added in v0.0.11

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

LerpPosition handles vector lerp interpolations

func (*LerpPosition) EndFunc added in v0.0.11

func (lc *LerpPosition) EndFunc() func()

EndFunc returns the end function

func (*LerpPosition) Init added in v0.0.11

func (lc *LerpPosition) Init(start time.Time, startPositionX, startPositionY, endPositionX, endPositionY float64, duration time.Duration, isEnabled bool, endFunc func(), isDestroyedAtEnd bool)

Init sets up a new lerp

func (*LerpPosition) IsDestroyed added in v0.0.11

func (lc *LerpPosition) IsDestroyed() bool

IsDestroyed returns if enabled

func (*LerpPosition) IsEnabled added in v0.0.11

func (lc *LerpPosition) IsEnabled() bool

IsEnabled returns if enabled

func (*LerpPosition) IsEndFuncSet added in v0.0.11

func (lc *LerpPosition) IsEndFuncSet() bool

IsEndFuncSet returns true if EndFunc exists

func (*LerpPosition) Lerp added in v0.0.11

func (lc *LerpPosition) Lerp() (x float64, y float64)

Lerp returns a position

func (*LerpPosition) SetEndFunc added in v0.0.11

func (lc *LerpPosition) SetEndFunc(endFunc func())

SetEndFunc sets a function to call on end of lerp

func (*LerpPosition) SetIsDestroyed added in v0.0.11

func (lc *LerpPosition) SetIsDestroyed(isDestroyed bool)

SetIsDestroyed sets if destroyed on next frame or not

func (*LerpPosition) SetIsEnabled added in v0.0.11

func (lc *LerpPosition) SetIsEnabled(isEnabled bool)

SetIsEnabled sets if enabled or not

type Node added in v0.0.9

type Node struct {
	X, Y       int
	IsCollider bool
	Cost       float64
}

Node represents an element in the grid

func (*Node) Copy added in v0.0.9

func (n *Node) Copy() *Node

Copy creates a copy of node

func (*Node) Heuristic added in v0.0.9

func (n *Node) Heuristic(goalX, goalY int) float64

Heuristic is a euclidean norm

func (*Node) String added in v0.0.9

func (n *Node) String() string

func (*Node) Success added in v0.0.9

func (n *Node) Success(goalX, goalY int) bool

Success returns true when we meet a goal

type Path added in v0.0.9

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

Path represents a navigation mesh

func NewPath added in v0.0.9

func NewPath() (p *Path)

NewPath returns a new path system

func (*Path) Neighbors added in v0.0.9

func (p *Path) Neighbors(nodeX int, nodeY int) (neighbors []*Edge)

Neighbors returns edge neighbors of a position

func (*Path) NewNode added in v0.0.9

func (p *Path) NewNode(ix int, iy int, isCollider bool, cost float64)

NewNode adds a new node

func (*Path) Node added in v0.0.9

func (p *Path) Node(x int, y int) *Node

Node returns a node at a coordinate

func (*Path) Route added in v0.0.10

func (p *Path) Route(startX, startY, endX, endY int) (path []*Edge, err error)

Route using astar

type PriorityQueue added in v0.0.9

type PriorityQueue []*Item

PriorityQueue is an array of items

func (PriorityQueue) Len added in v0.0.9

func (pq PriorityQueue) Len() int

func (PriorityQueue) Less added in v0.0.9

func (pq PriorityQueue) Less(i, j int) bool

func (*PriorityQueue) Pop added in v0.0.9

func (pq *PriorityQueue) Pop() interface{}

Pop removes an item from a queue

func (*PriorityQueue) Push added in v0.0.9

func (pq *PriorityQueue) Push(x interface{})

Push add an item to a queue

func (PriorityQueue) Swap added in v0.0.9

func (pq PriorityQueue) Swap(i, j int)

type Rectangle

type Rectangle struct {
	Min, Max Vector
}

Rectangle is a 2D rectangle aligned with the axes of the coordinate system. It is defined by two points, Min and Max.

The invariant should hold, that Max's components are greater or equal than Min's components respectively.

func Rect

func Rect(x0 float64, y0 float64, x1 float64, y1 float64) Rectangle

Rect returns a rectangle

func RectImageCopy

func RectImageCopy(srcRect image.Rectangle) *Rectangle

RectImageCopy converts an image rectangle to model rect

func (*Rectangle) Dx

func (r *Rectangle) Dx() float64

Dx returns r's width

func (*Rectangle) Dy

func (r *Rectangle) Dy() float64

Dy returns r's height

func (*Rectangle) String

func (r *Rectangle) String() string

String returns the string representation of the rectangle

type Slice added in v0.0.11

type Slice struct {
	Name string      `xml:"name"`
	Keys []*SliceKey `xml:"key"`
}

Slice represents a 9 slicing instruction set within an image

type SliceKey added in v0.0.11

type SliceKey struct {
	Frame  int
	Bounds struct {
		X int
		Y int
		W int
		H int
	}
	Center struct {
		X int
		Y int
		W int
		H int
	}
	Pivot struct {
		X int
		Y int
	}
}

SliceKey represents each slice's key data

type Vector

type Vector struct {
	X, Y float64
}

Vector is a 2D vector type with X and Y coordinates

func NewVectorFromPoint

func NewVectorFromPoint(point image.Point) *Vector

NewVectorFromPoint converts an image point to a vector

func Unit

func Unit(angle float64) *Vector

Unit returns a vector of length 1 facing the given angle.

func Vect

func Vect(x, y float64) Vector

Vect returns a 2D vector based on two points

func (*Vector) Add

func (v *Vector) Add(nv *Vector) *Vector

Add returns the sum of vectors u and v.

func (*Vector) Angle

func (v *Vector) Angle() float64

Angle returns the angle between the vector u and the x-axis. The result is in range [-Pi, Pi].

func (*Vector) Copy

func (v *Vector) Copy() *Vector

Copy creates a copy of provided vector

func (*Vector) Cross

func (v *Vector) Cross(nv *Vector) float64

Cross return the cross product of vector u and v.

func (*Vector) Dot

func (v *Vector) Dot(nv *Vector) float64

Dot returns the dot product of vector u and v.

func (*Vector) Equal

func (v *Vector) Equal(nv *Vector) bool

Equal returns true if both vectors are at the same location

func (*Vector) Len

func (v *Vector) Len() float64

Len returns the length of the vector.

func (*Vector) Lerp

func (v *Vector) Lerp(a *Vector, b *Vector, t float64) *Vector

Lerp returns a linear interpolation between vector a and b.

This function basically returns a point along the line between a and b and t chooses which one. If t is 0, then a will be returned, if t is 1, b will be returned. Anything between 0 and 1 will return the appropriate point between a and b and so on.

func (*Vector) Map

func (v *Vector) Map(f func(float64) float64) *Vector

Map applies the function f to both x and y components of the vector u and returns the modified vector.

u := pixel.V(10.5, -1.5)
v := nv.Map(math.Floor)   // v is Vector(10, -2), both components of u floored

func (*Vector) Normal

func (v *Vector) Normal() *Vector

Normal returns a vector normal to nv. Equivalent to nv.Rotated(math.Pi / 2), but faster.

func (*Vector) Project

func (v *Vector) Project(nv *Vector) *Vector

Project returns a projection (or component) of vector u in the direction of vector v.

Behaviour is undefined if v is a zero vector.

func (*Vector) Rotated

func (v *Vector) Rotated(angle float64) *Vector

Rotated returns the vector u rotated by the given angle in radians.

func (*Vector) Scaled

func (v *Vector) Scaled(s float64) *Vector

Scaled returns the vector u multiplied by c.

func (*Vector) ScaledXY

func (v *Vector) ScaledXY(nv *Vector) *Vector

ScaledXY returns the vector u multiplied by c.

func (*Vector) String

func (v *Vector) String() string

String returns the string representation of the vector

func (*Vector) Sub

func (v *Vector) Sub(nv *Vector) *Vector

Sub returns the difference betweeen vectors u and v.

func (*Vector) Unit

func (v *Vector) Unit() *Vector

Unit returns a vector of length 1 facing the direction of u (has the same angle).

func (*Vector) XY

func (v *Vector) XY() (x, y float64)

XY returns the components of the vector in two return values.

Jump to

Keyboard shortcuts

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