core

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package core contains lower level component systems.

Index

Constants

View Source
const (
	// SNSoloDrawable is the system name of a drawable without as DrawLayer component
	SNSoloDrawable = "primen.DrawableSystem"
	// SNDrawLayerDrawable is the system name of a drawable with as DrawLayer component
	SNDrawLayerDrawable = "primen.DrawLayerDrawableSystem"
	// CNDrawable is the component name of a drawable
	CNDrawable = "primen.DrawableComponent"
)
View Source
const (
	CNDrawFunc       = "tau/core.DrawFuncComponent"
	SNDrawFunc       = "tau/core.DrawFuncSystem"
	SNDrawFuncAfter  = "tau/core.DrawFuncAfterSystem"
	SNDrawFuncBefore = "tau/core.DrawFuncBeforeSystem"
)
View Source
const (
	// SNDrawLayer is the system name
	SNDrawLayer = "primen.DrawLayerSystem"
	// CNDrawLayer is the component signature name
	CNDrawLayer = "primen.DrawLayerComponent"
	// SNDrawLayerSprite is the system name
	SNDrawLayerSprite = "primen.DrawLayerSpriteSystem"
)
View Source
const (
	// ZIndexTop is to set the ZIndex at the top
	ZIndexTop = int64(math.MinInt64)
	// ZIndexBottom is to set the ZIndex at the bottom
	ZIndexBottom = int64(math.MinInt64 + 1)
)
View Source
const (
	SNTag = "primen.TagSystem"
	CNTag = "primen.TagComponent"
)
View Source
const (
	CNFunc       = "tau/core.FuncComponent"
	SNFunc       = "tau/core.FuncSystem"
	SNFuncAfter  = "tau/core.FuncAfterSystem"
	SNFuncBefore = "tau/core.FuncBeforeSystem"
)
View Source
const (
	SNRotationTransform = "primen.RotationTransformSystem"
	CNRotation          = "primen.RotationComponent"
)
View Source
const (
	SNSpriteAnimation     = "primen.SpriteAnimationSystem"
	SNSpriteAnimationLink = "primen.SpriteAnimationLinkSystem"
	CNSpriteAnimation     = "primen.SpriteAnimationComponent"
)
View Source
const (
	SNTransform       = "primen.TransformSystem"
	SNTransformSprite = "primen.TransformSpriteSystem"
	CNTransform       = "primen.TransformComponent"
)
View Source
const (
	// DefaultImageOptions key passed to the default world (&ebiten.DrawImageOptions{})
	DefaultImageOptions string = "default_image_options"
)

Variables

View Source
var (
	// DebugDraw enables to see debug lines and stats
	DebugDraw = false
)

Functions

func Clamp

func Clamp(x, min, max float64) float64

Clamp returns x clamped to the interval [min, max].

If x is less than min, min is returned. If x is more than max, max is returned. Otherwise, x is returned.

func DrawLayerSystemExec

func DrawLayerSystemExec(ctx Context)

DrawLayerSystemExec is the main function of the DrawLayerSystem

func FindWithTag

func FindWithTag(w *ecs.World, tag string, tags ...string) []ecs.Entity

func NewWorld

func NewWorld(e Engine) *ecs.World

NewWorld creates a new world

func RegisterComponentSystem

func RegisterComponentSystem(cs ComponentSystem)

func RotationTransformSystemExec

func RotationTransformSystemExec(ctx Context)

RotationTransformSystemExec is the main function of the RotationTransformSystem

func SetupSystem

func SetupSystem(w *ecs.World, cs ComponentSystem)

func SpriteAnimationLinkSystemExec

func SpriteAnimationLinkSystemExec(ctx Context)

SpriteAnimationLinkSystemExec is what glues the animation and sprite together

func SpriteAnimationSystemExec

func SpriteAnimationSystemExec(ctx Context)

SpriteAnimationSystemExec is the main function of the SpriteSystem

func StartDefaults

func StartDefaults(e Engine)

func TagSystemExec

func TagSystemExec(ctx Context)

TagSystemExec is the main function of the TagSystem

func TransformSpriteSystemExec

func TransformSpriteSystemExec(ctx Context)

TransformSpriteSystemExec is the main function of the TransformSpriteSystem

func TransformSystemExec

func TransformSystemExec(ctx Context)

TransformSystemExec is the main function of the TransformSystem

func UpsertComponent

func UpsertComponent(w *ecs.World, comp ecs.NewComponentInput) *ecs.Component

Types

type AfterDrawFuncComponentSystem added in v0.3.0

type AfterDrawFuncComponentSystem struct {
	BaseComponentSystem
}

func (*AfterDrawFuncComponentSystem) Components added in v0.3.0

func (cs *AfterDrawFuncComponentSystem) Components(w *ecs.World) []*ecs.Component

Components returns the component signature(s)

func (*AfterDrawFuncComponentSystem) SystemExec added in v0.3.0

func (cs *AfterDrawFuncComponentSystem) SystemExec() SystemExecFn

SystemExec returns the exec func

func (*AfterDrawFuncComponentSystem) SystemName added in v0.3.0

func (cs *AfterDrawFuncComponentSystem) SystemName() string

SystemName returns the system name

func (*AfterDrawFuncComponentSystem) SystemPriority added in v0.3.0

func (cs *AfterDrawFuncComponentSystem) SystemPriority() int

SystemPriority returns the system priority

func (*AfterDrawFuncComponentSystem) SystemTags added in v0.3.0

func (cs *AfterDrawFuncComponentSystem) SystemTags() []string

type AfterFuncComponentSystem

type AfterFuncComponentSystem struct {
	BaseComponentSystem
}

func (*AfterFuncComponentSystem) Components

func (cs *AfterFuncComponentSystem) Components(w *ecs.World) []*ecs.Component

Components returns the component signature(s)

func (*AfterFuncComponentSystem) SystemExec

func (cs *AfterFuncComponentSystem) SystemExec() SystemExecFn

SystemExec returns the exec func

func (*AfterFuncComponentSystem) SystemName

func (cs *AfterFuncComponentSystem) SystemName() string

SystemName returns the system name

func (*AfterFuncComponentSystem) SystemPriority

func (cs *AfterFuncComponentSystem) SystemPriority() int

SystemPriority returns the system priority

type AnimClipMode

type AnimClipMode byte

AnimClipMode determines how time is treated outside of the keyframed range of an animation clip.

const (
	// AnimOnce - When time reaches the end of the animation clip, the clip will automatically
	// stop playing and time will be reset to beginning of the clip.
	AnimOnce AnimClipMode = 0
	// AnimLoop - When time reaches the end of the animation clip, time will continue at the beginning.
	AnimLoop AnimClipMode = 1
	// AnimPingPong - When time reaches the end of the animation clip, time will ping pong back between beginning
	// and end.
	AnimPingPong AnimClipMode = 2
	// AnimClampForever - Plays back the animation. When it reaches the end, it will keep playing the last frame
	// and never stop playing.
	//
	// When playing backwards it will reach the first frame and will keep playing that. This is useful for code
	// that uses the Playing bool to avoid activating said trigger.
	AnimClampForever AnimClipMode = 3
)

type Animation added in v0.3.0

type Animation interface {
	Each(fn func(i int, clip AnimationClip) bool)
	GetClip(index int) AnimationClip
	GetClipEvents(index int) []*AnimationEvent
	GetClipImage(clipindex, frame int) *ebiten.Image
	GetClipRect(clipindex, frame int) image.Rectangle
	GetClipOffset(clipindex, frame int) (x, y float64)
	Count() int
}

Animation is a shared container of clips (reusable)

type AnimationClip added in v0.3.0

type AnimationClip interface {
	GetName() string
	GetFPS() float64
	GetImage(frame int) *ebiten.Image
	GetFrameCount() int
	GetMode() AnimClipMode
	GetEndedEvent() *AnimationEvent
	GetEvents() []*AnimationEvent
	GetRect(frame int) image.Rectangle
	GetOffset(frame int) (x, y float64)
}

AnimationClip is the data os an animation clip (reusable)

type AnimationEvent added in v0.3.0

type AnimationEvent struct {
	Name  string
	Value string
}

AnimationEvent holds a name and value to pass to listeners when the event is triggered

type AnimationEventFn

type AnimationEventFn func(name, value string)

AnimationEventFn is a valid AnimationEvent function

type AnimationEventID

type AnimationEventID int64

AnimationEventID is the id oa an animation listener instance

type AnimationEventListeners

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

AnimationEventListeners groups AnimationEvent listeners

func (*AnimationEventListeners) Add

Add a new listener

func (*AnimationEventListeners) AddCatchAll

AddCatchAll adds a wildcard listener

func (*AnimationEventListeners) Clear

func (ae *AnimationEventListeners) Clear()

Clear removes all event listeners

func (*AnimationEventListeners) Dispatch

func (ae *AnimationEventListeners) Dispatch(name, value string)

Dispatch triggers all compatible listeners with the event

func (*AnimationEventListeners) Remove

Remove a listener by ID

type BaseComponentSystem

type BaseComponentSystem struct {
}

func (*BaseComponentSystem) ExcludeComponents

func (cs *BaseComponentSystem) ExcludeComponents(w *ecs.World) []*ecs.Component

func (*BaseComponentSystem) SystemExec

func (cs *BaseComponentSystem) SystemExec() SystemExecFn

func (*BaseComponentSystem) SystemInit

func (cs *BaseComponentSystem) SystemInit() SystemInitFn

func (*BaseComponentSystem) SystemPriority

func (cs *BaseComponentSystem) SystemPriority() int

func (*BaseComponentSystem) SystemTags

func (cs *BaseComponentSystem) SystemTags() []string

type BasicCS

type BasicCS struct {
	SysName       string
	SysPriority   int
	SysInit       SystemInitFn
	SysExec       SystemExecFn
	SysTags       []string
	GetComponents func(w *ecs.World) []*ecs.Component
}

func (*BasicCS) BasicCS

func (cs *BasicCS) BasicCS() int

func (*BasicCS) Components

func (cs *BasicCS) Components(w *ecs.World) []*ecs.Component

func (*BasicCS) ExcludeComponents

func (cs *BasicCS) ExcludeComponents(w *ecs.World) []*ecs.Component

func (*BasicCS) SystemExec

func (cs *BasicCS) SystemExec() SystemExecFn

func (*BasicCS) SystemInit

func (cs *BasicCS) SystemInit() SystemInitFn

func (*BasicCS) SystemName

func (cs *BasicCS) SystemName() string

func (*BasicCS) SystemPriority

func (cs *BasicCS) SystemPriority() int

func (*BasicCS) SystemTags

func (cs *BasicCS) SystemTags() []string

type BeforeDrawFuncComponentSystem added in v0.3.0

type BeforeDrawFuncComponentSystem struct {
	BaseComponentSystem
}

func (*BeforeDrawFuncComponentSystem) Components added in v0.3.0

func (cs *BeforeDrawFuncComponentSystem) Components(w *ecs.World) []*ecs.Component

Components returns the component signature(s)

func (*BeforeDrawFuncComponentSystem) SystemExec added in v0.3.0

SystemExec returns the exec func

func (*BeforeDrawFuncComponentSystem) SystemName added in v0.3.0

func (cs *BeforeDrawFuncComponentSystem) SystemName() string

SystemName returns the system name

func (*BeforeDrawFuncComponentSystem) SystemPriority added in v0.3.0

func (cs *BeforeDrawFuncComponentSystem) SystemPriority() int

SystemPriority returns the system priority

func (*BeforeDrawFuncComponentSystem) SystemTags added in v0.3.0

func (cs *BeforeDrawFuncComponentSystem) SystemTags() []string

type BeforeFuncComponentSystem

type BeforeFuncComponentSystem struct {
	BaseComponentSystem
}

func (*BeforeFuncComponentSystem) Components

func (cs *BeforeFuncComponentSystem) Components(w *ecs.World) []*ecs.Component

Components returns the component signature(s)

func (*BeforeFuncComponentSystem) SystemExec

func (cs *BeforeFuncComponentSystem) SystemExec() SystemExecFn

SystemExec returns the exec func

func (*BeforeFuncComponentSystem) SystemName

func (cs *BeforeFuncComponentSystem) SystemName() string

SystemName returns the system name

func (*BeforeFuncComponentSystem) SystemPriority

func (cs *BeforeFuncComponentSystem) SystemPriority() int

SystemPriority returns the system priority

type ColorMatrix added in v0.4.0

type ColorMatrix interface {
	Reset() ColorMatrix
	M() *ebiten.ColorM
	MV() ebiten.ColorM
	RotateHue(theta float64) ColorMatrix
	ChangeHSV(hueTheta float64, saturationScale float64, valueScale float64) ColorMatrix
	Apply(clr color.Color) ColorMatrix
}

func ColorM added in v0.4.0

func ColorM() ColorMatrix

func ColorM2 added in v0.4.0

func ColorM2(m ebiten.ColorM) ColorMatrix

func ColorTint added in v0.4.0

func ColorTint(c color.Color) ColorMatrix

type ComponentSystem

type ComponentSystem interface {
	SystemName() string
	SystemPriority() int
	SystemInit() SystemInitFn
	SystemExec() SystemExecFn
	SystemTags() []string
	Components(w *ecs.World) []*ecs.Component
	ExcludeComponents(w *ecs.World) []*ecs.Component
}

type Context

type Context interface {
	ecs.Context
	Engine() Engine
	FPS() float64
	Frame() int64
	IsDrawingSkipped() bool
	Renderer() DrawManager
}

Context is the context passed to every system update function.

type DrawFn added in v0.3.0

type DrawFn func(ctx Context, e ecs.Entity)

type DrawFunc added in v0.3.0

type DrawFunc struct {
	Fn       DrawFn
	AfterFn  DrawFn
	BeforeFn DrawFn
}

type DrawFuncComponentSystem added in v0.3.0

type DrawFuncComponentSystem struct {
	BaseComponentSystem
}

func (*DrawFuncComponentSystem) Components added in v0.3.0

func (cs *DrawFuncComponentSystem) Components(w *ecs.World) []*ecs.Component

Components returns the component signature(s)

func (*DrawFuncComponentSystem) SystemExec added in v0.3.0

func (cs *DrawFuncComponentSystem) SystemExec() SystemExecFn

func (*DrawFuncComponentSystem) SystemName added in v0.3.0

func (cs *DrawFuncComponentSystem) SystemName() string

SystemName returns the system name

func (*DrawFuncComponentSystem) SystemPriority added in v0.3.0

func (cs *DrawFuncComponentSystem) SystemPriority() int

SystemPriority returns the system priority

func (*DrawFuncComponentSystem) SystemTags added in v0.3.0

func (cs *DrawFuncComponentSystem) SystemTags() []string

type DrawLayer

type DrawLayer struct {
	Layer  LayerIndex
	ZIndex int64
	// contains filtered or unexported fields
}

DrawLayer component data

type DrawLayerComponentSystem

type DrawLayerComponentSystem struct {
	BaseComponentSystem
}

DrawLayerComponentSystem component system

func (*DrawLayerComponentSystem) Components

func (cs *DrawLayerComponentSystem) Components(w *ecs.World) []*ecs.Component

Components returns the component signature(s)

func (*DrawLayerComponentSystem) ExcludeComponents

func (cs *DrawLayerComponentSystem) ExcludeComponents(w *ecs.World) []*ecs.Component

ExcludeComponents returns the components that must not be present in this system

func (*DrawLayerComponentSystem) SystemExec

func (cs *DrawLayerComponentSystem) SystemExec() SystemExecFn

SystemExec returns the system exec fn

func (*DrawLayerComponentSystem) SystemInit

func (cs *DrawLayerComponentSystem) SystemInit() SystemInitFn

SystemInit returns the system init

func (*DrawLayerComponentSystem) SystemName

func (cs *DrawLayerComponentSystem) SystemName() string

SystemName returns the system name

func (*DrawLayerComponentSystem) SystemPriority

func (cs *DrawLayerComponentSystem) SystemPriority() int

SystemPriority returns the system priority

type DrawLayerDrawableComponentSystem

type DrawLayerDrawableComponentSystem struct {
	BaseComponentSystem
}

DrawLayerDrawableComponentSystem handles drawables with a draw layer

func (*DrawLayerDrawableComponentSystem) Components

func (cs *DrawLayerDrawableComponentSystem) Components(w *ecs.World) []*ecs.Component

Components returns the component signature(s)

func (*DrawLayerDrawableComponentSystem) SystemExec

SystemExec returns the system exec fn

func (*DrawLayerDrawableComponentSystem) SystemInit

SystemInit returns the system init

func (*DrawLayerDrawableComponentSystem) SystemName

func (cs *DrawLayerDrawableComponentSystem) SystemName() string

SystemName returns the system name

func (*DrawLayerDrawableComponentSystem) SystemPriority

func (cs *DrawLayerDrawableComponentSystem) SystemPriority() int

SystemPriority returns the system priority

func (*DrawLayerDrawableComponentSystem) SystemTags

func (cs *DrawLayerDrawableComponentSystem) SystemTags() []string

type DrawManager added in v0.4.0

type DrawManager interface {
	DrawImageXY(image *ebiten.Image, x, y float64)
	DrawImage(image *ebiten.Image, m GeoMatrix)
	DrawImageC(image *ebiten.Image, m GeoMatrix, c ColorMatrix)
	DrawImageComp(image *ebiten.Image, m GeoMatrix, mode ebiten.CompositeMode)
	DrawImageCComp(image *ebiten.Image, m GeoMatrix, c ColorMatrix, mode ebiten.CompositeMode)
	DrawImageRaw(image *ebiten.Image, opt *ebiten.DrawImageOptions)
	Screen() *ebiten.Image
}

type Drawable

type Drawable interface {
	Update(ctx Context)
	Draw(m DrawManager)
	Destroy()
	IsDisabled() bool
	Size() (w, h float64)
	SetTransformMatrix(m GeoMatrix)
	ClearTransformMatrix()
	SetOffset(x, y float64)
}

Drawable is the basis of all ebiten drawable items (sprites, texts, shapes)

type DrawableImager

type DrawableImager interface {
	Drawable
	GetImage() *ebiten.Image
	SetImage(img *ebiten.Image)
}

DrawableImager is a Drawable with Get and Set image funcs

type Engine

type Engine interface {
	AddWorld(w *ecs.World, priority int)
	RemoveWorld(w *ecs.World) bool
	Default() *ecs.World
	Run() error
	Ready() <-chan struct{}
	Get(key string) interface{}
	Set(key string, value interface{})
	UpdateFrame() int64
	DrawFrame() int64
	Width() int
	Height() int
	AddEventListener(eventName string, fn EventFn) EventID
	RemoveEventListener(id EventID) bool
	DispatchEvent(eventName string, data interface{})
}

type EntitySet

type EntitySet interface {
	Add(elements ...ecs.Entity)
	Remove(elements ...ecs.Entity)
	Contains(elements ...ecs.Entity) bool
	Values() []ecs.Entity
	SetBase
}

func NewEntitySet

func NewEntitySet(values ...ecs.Entity) EntitySet

NewEntitySet instantiates a new empty set and adds the entities (if present)

type EntitySortedList

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

func NewEntitySortedList

func NewEntitySortedList(mincap int) *EntitySortedList

func (*EntitySortedList) AddOrUpdate

func (sl *EntitySortedList) AddOrUpdate(key ecs.Entity, value SLVal) bool

func (*EntitySortedList) Delete

func (sl *EntitySortedList) Delete(key ecs.Entity) bool

func (*EntitySortedList) Each

func (sl *EntitySortedList) Each(fn func(key ecs.Entity, value SLVal) bool)

Each iterates on all entries, sorted.

Do not delete or add entries while looping (it is read locked while looping).

func (*EntitySortedList) FirstValue

func (sl *EntitySortedList) FirstValue() SLVal

func (*EntitySortedList) Get

func (sl *EntitySortedList) Get(key ecs.Entity) (SLVal, bool)

func (*EntitySortedList) LastValue

func (sl *EntitySortedList) LastValue() SLVal

func (*EntitySortedList) Reset

func (sl *EntitySortedList) Reset()

Reset clears the list.

type Event

type Event struct {
	Engine Engine
	Data   interface{}
}

type EventFn

type EventFn func(eventName string, e Event)

type EventID

type EventID int64

type EventManager

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

func (*EventManager) Deregister

func (m *EventManager) Deregister(id EventID) bool

func (*EventManager) Dispatch

func (m *EventManager) Dispatch(eventName string, engine Engine, data interface{})

func (*EventManager) Register

func (m *EventManager) Register(eventName string, fn EventFn) EventID

type Func

type Func struct {
	Fn       UpdateFn
	AfterFn  UpdateFn
	BeforeFn UpdateFn
}

type FuncComponentSystem

type FuncComponentSystem struct {
	BaseComponentSystem
}

func (*FuncComponentSystem) Components

func (cs *FuncComponentSystem) Components(w *ecs.World) []*ecs.Component

Components returns the component signature(s)

func (*FuncComponentSystem) SystemExec

func (cs *FuncComponentSystem) SystemExec() SystemExecFn

func (*FuncComponentSystem) SystemName

func (cs *FuncComponentSystem) SystemName() string

SystemName returns the system name

func (*FuncComponentSystem) SystemPriority

func (cs *FuncComponentSystem) SystemPriority() int

SystemPriority returns the system priority

type GeoMatrix added in v0.4.0

type GeoMatrix interface {
	Translate(tx, ty float64) GeoMatrix
	Scale(sx, sy float64) GeoMatrix
	Rotate(theta float64) GeoMatrix
	Concat(m ebiten.GeoM) GeoMatrix
	M() *ebiten.GeoM
	MV() ebiten.GeoM
	Reset() GeoMatrix
}

func GeoM added in v0.4.0

func GeoM() GeoMatrix

func GeoM2 added in v0.4.0

func GeoM2(m ebiten.GeoM) GeoMatrix

type Label added in v0.3.0

type Label struct {
	Text         string
	Face         font.Face
	Area         image.Point
	Color        color.Color
	Filter       ebiten.Filter
	DrawDisabled bool // if true, the DrawableSystem will not draw this
	//
	X           float64 // logical X position
	Y           float64 // logical Y position
	Angle       float64 // radians
	ScaleX      float64 // logical X scale (1 = 100%)
	ScaleY      float64 // logical Y scale (1 = 100%)
	OriginX     float64 // X origin (0 = left; 0.5 = center; 1 = right)
	OriginY     float64 // Y origin (0 = top; 0.5 = middle; 1 = bottom)
	OffsetX     float64 // Text rendering offset X (pixel unit)
	OffsetY     float64 // Text rendering offset Y (pixel unit)
	FaceOffsetX int     // Text rendering offset X (pixel unit)
	FaceOffsetY int     // Text rendering offset Y (pixel unit)
	// contains filtered or unexported fields
}

func (*Label) ClearTransformMatrix added in v0.3.0

func (l *Label) ClearTransformMatrix()

func (*Label) ComputedSize added in v0.3.0

func (l *Label) ComputedSize() image.Point

func (*Label) Destroy added in v0.3.0

func (l *Label) Destroy()

func (*Label) Draw added in v0.3.0

func (l *Label) Draw(renderer DrawManager)

Draw is called by the Drawable systems

func (*Label) FontFaceHeight added in v0.3.0

func (l *Label) FontFaceHeight() int

FontFaceHeight returns the font height

func (*Label) IsDisabled added in v0.3.0

func (l *Label) IsDisabled() bool

func (*Label) ResetTextOffset added in v0.3.0

func (l *Label) ResetTextOffset()

ResetTextOffset sets the text offset to default (0, l.FontFaceHeight())

func (*Label) SetDirty added in v0.3.0

func (l *Label) SetDirty()

func (*Label) SetOffset added in v0.3.0

func (l *Label) SetOffset(x, y float64)

func (*Label) SetTransformMatrix added in v0.3.0

func (l *Label) SetTransformMatrix(m GeoMatrix)

SetTransformMatrix is used by TransformSystem to set a custom transform

func (*Label) Size added in v0.3.0

func (l *Label) Size() (w, h float64)

Size returns the real size of the label

func (*Label) Update added in v0.3.0

func (l *Label) Update(ctx Context)

Update does some computation before drawing

type LayerIndex

type LayerIndex int64

LayerIndex is the layer index

type LayerTuple

type LayerTuple struct {
	Index LayerIndex
	Items *EntitySortedList
}

LayerTuple is returned when fetching all layers

type Middleware

type Middleware func(next SystemExecFn) SystemExecFn

Middleware is a system middleware

func MidSkipFrames

func MidSkipFrames(n int) Middleware

MidSkipFrames is a System middleware that skips n frames and then executes the next function in the system function stack

type Observer

type Observer interface {
	EventName() string
	OnEvent(e Event)
}

type PcAnimClip added in v0.3.0

type PcAnimClip struct {
	// The name of an animation is not allowed to be changed during runtime
	// but since this is part of a component (and components shouldn't have logic),
	// it is a public member.
	Name       string
	Frames     []PcFrame
	Events     []*AnimationEvent //TODO: link
	Fps        float64
	ClipMode   AnimClipMode
	EndedEvent *AnimationEvent //TODO: link
}

PcAnimClip is a pre-computed animation clip.

func (PcAnimClip) GetEndedEvent added in v0.3.0

func (c PcAnimClip) GetEndedEvent() *AnimationEvent

func (PcAnimClip) GetEvents added in v0.3.0

func (c PcAnimClip) GetEvents() []*AnimationEvent

func (PcAnimClip) GetFPS added in v0.3.0

func (c PcAnimClip) GetFPS() float64

func (PcAnimClip) GetFrameCount added in v0.3.0

func (c PcAnimClip) GetFrameCount() int

func (PcAnimClip) GetImage added in v0.3.0

func (c PcAnimClip) GetImage(frame int) *ebiten.Image

func (PcAnimClip) GetMode added in v0.3.0

func (c PcAnimClip) GetMode() AnimClipMode

func (PcAnimClip) GetName added in v0.3.0

func (c PcAnimClip) GetName() string

GetName returns the animation clip name

func (PcAnimClip) GetOffset added in v0.3.0

func (c PcAnimClip) GetOffset(frame int) (x, y float64)

GetOffset returns the pixel offset (from the origin) of the current frame

func (PcAnimClip) GetRect added in v0.3.0

func (c PcAnimClip) GetRect(frame int) image.Rectangle

GetRect returns the drawable bounds

type PcFrame added in v0.3.0

type PcFrame struct {
	Image   *ebiten.Image
	Rect    image.Rectangle
	OffsetX float64
	OffsetY float64
}

type PrecomputedAnimation added in v0.3.0

type PrecomputedAnimation struct {
	Clips []PcAnimClip
}

PrecomputedAnimation is an animation of a one or more image sources It is the default data structure of an Atlas

func (*PrecomputedAnimation) Count added in v0.3.0

func (a *PrecomputedAnimation) Count() int

Count returns the total count of cnimation clips

func (*PrecomputedAnimation) Each added in v0.3.0

func (a *PrecomputedAnimation) Each(fn func(i int, clip AnimationClip) bool)

Each iterates through all animation clips

func (*PrecomputedAnimation) GetClip added in v0.3.0

func (a *PrecomputedAnimation) GetClip(index int) AnimationClip

GetClip returns an animation clip by index

func (*PrecomputedAnimation) GetClipEvents added in v0.3.0

func (a *PrecomputedAnimation) GetClipEvents(index int) []*AnimationEvent

GetClipEvents returns all animation clip events by the clip index

func (*PrecomputedAnimation) GetClipImage added in v0.3.0

func (a *PrecomputedAnimation) GetClipImage(clipi, frame int) *ebiten.Image

GetClipImage returns the clip image

func (*PrecomputedAnimation) GetClipOffset added in v0.3.0

func (a *PrecomputedAnimation) GetClipOffset(clipi, frame int) (x, y float64)

GetClipOffset returns the clip offset

func (*PrecomputedAnimation) GetClipRect added in v0.3.0

func (a *PrecomputedAnimation) GetClipRect(clipi, frame int) image.Rectangle

GetClipRect returns the clip Rectangle (bounds)

type Rotation

type Rotation struct {
	Speed float64
}

type RotationTransformComponentSystem

type RotationTransformComponentSystem struct {
	BaseComponentSystem
}

func (*RotationTransformComponentSystem) Components

func (cs *RotationTransformComponentSystem) Components(w *ecs.World) []*ecs.Component

func (*RotationTransformComponentSystem) SystemExec

func (*RotationTransformComponentSystem) SystemInit

func (*RotationTransformComponentSystem) SystemName

func (cs *RotationTransformComponentSystem) SystemName() string

func (*RotationTransformComponentSystem) SystemPriority

func (cs *RotationTransformComponentSystem) SystemPriority() int

type SLVal

type SLVal interface {
	Less(v interface{}) bool
}

type SetBase

type SetBase interface {
	Empty() bool
	Size() int
	Clear()
}

type SoloDrawableComponentSystem

type SoloDrawableComponentSystem struct {
	BaseComponentSystem
}

SoloDrawableComponentSystem handles drawable items (without a draw layer)

func (*SoloDrawableComponentSystem) Components

func (cs *SoloDrawableComponentSystem) Components(w *ecs.World) []*ecs.Component

Components returns the component signature(s)

func (*SoloDrawableComponentSystem) ExcludeComponents

func (cs *SoloDrawableComponentSystem) ExcludeComponents(w *ecs.World) []*ecs.Component

ExcludeComponents returns the components that must not be present in this system

func (*SoloDrawableComponentSystem) SystemExec

func (cs *SoloDrawableComponentSystem) SystemExec() SystemExecFn

SystemExec returns the system exec fn

func (*SoloDrawableComponentSystem) SystemInit

func (cs *SoloDrawableComponentSystem) SystemInit() SystemInitFn

SystemInit returns the system init

func (*SoloDrawableComponentSystem) SystemName

func (cs *SoloDrawableComponentSystem) SystemName() string

SystemName returns the system name

func (*SoloDrawableComponentSystem) SystemPriority

func (cs *SoloDrawableComponentSystem) SystemPriority() int

SystemPriority returns the system priority

func (*SoloDrawableComponentSystem) SystemTags

func (cs *SoloDrawableComponentSystem) SystemTags() []string

SystemTags -> draw

type Sprite

type Sprite struct {
	X            float64 // logical X position
	Y            float64 // logical Y position
	Angle        float64 // radians
	ScaleX       float64 // logical X scale (1 = 100%)
	ScaleY       float64 // logical Y scale (1 = 100%)
	OriginX      float64 // X origin (0 = left; 0.5 = center; 1 = right)
	OriginY      float64 // Y origin (0 = top; 0.5 = middle; 1 = bottom)
	OffsetX      float64 // offset origin X (in pixels)
	OffsetY      float64 // offset origin Y (in pixels)
	Image        *ebiten.Image
	DrawDisabled bool // if true, the SpriteSystem will not draw this
	// contains filtered or unexported fields
}

Sprite is the data of a sprite component.

func (*Sprite) ClearColorTransform added in v0.4.0

func (s *Sprite) ClearColorTransform()

func (*Sprite) ClearTransformMatrix

func (s *Sprite) ClearTransformMatrix()

func (*Sprite) Destroy

func (s *Sprite) Destroy()

func (*Sprite) Draw

func (s *Sprite) Draw(renderer DrawManager)

Draw is called by the Drawable systems

func (*Sprite) GetImage

func (s *Sprite) GetImage() *ebiten.Image

func (*Sprite) GetPrecomputedImage

func (s *Sprite) GetPrecomputedImage() *ebiten.Image

GetPrecomputedImage returns the last precomputed image

TODO: remove

func (*Sprite) GetPrecomputedImageDim

func (s *Sprite) GetPrecomputedImageDim() (width, height float64)

GetPrecomputedImageDim returns the last precomputed image dimmensions

func (*Sprite) IsDisabled

func (s *Sprite) IsDisabled() bool

func (*Sprite) SetColorHue added in v0.4.0

func (s *Sprite) SetColorHue(theta float64)

func (*Sprite) SetColorTint added in v0.4.0

func (s *Sprite) SetColorTint(c color.Color)

func (*Sprite) SetCompositeMode added in v0.4.0

func (s *Sprite) SetCompositeMode(mode ebiten.CompositeMode)

func (*Sprite) SetImage

func (s *Sprite) SetImage(img *ebiten.Image)

func (*Sprite) SetOffset added in v0.3.0

func (s *Sprite) SetOffset(x, y float64)

func (*Sprite) SetTransformMatrix

func (s *Sprite) SetTransformMatrix(m GeoMatrix)

SetTransformMatrix is used by TransformSystem to set a custom transform

func (*Sprite) Size

func (s *Sprite) Size() (w, h float64)

Size returns the real size of the Sprite

func (*Sprite) Update

func (s *Sprite) Update(ctx Context)

Update does some computation before drawing

type SpriteAnimation

type SpriteAnimation struct {
	Enabled     bool
	Playing     bool
	ActiveClip  int
	ActiveFrame int
	Anim        Animation
	T           float64

	// Default fps for clips with no fps specified
	Fps float64
	// contains filtered or unexported fields
}

SpriteAnimation holds the data of a sprite animation (and clips)

func (*SpriteAnimation) AnimEvent

func (a *SpriteAnimation) AnimEvent(name, value string)

func (*SpriteAnimation) PlayClip

func (a *SpriteAnimation) PlayClip(name string)

PlayClip sets the animation to play a clip by name

func (*SpriteAnimation) PlayClipIndex added in v0.3.0

func (a *SpriteAnimation) PlayClipIndex(i int)

PlayClipIndex plays a clip at index i

type SpriteAnimationComponentSystem

type SpriteAnimationComponentSystem struct {
	BaseComponentSystem
}

func (*SpriteAnimationComponentSystem) Components

func (cs *SpriteAnimationComponentSystem) Components(w *ecs.World) []*ecs.Component

func (*SpriteAnimationComponentSystem) ExcludeComponents

func (cs *SpriteAnimationComponentSystem) ExcludeComponents(w *ecs.World) []*ecs.Component

func (*SpriteAnimationComponentSystem) SystemExec

func (*SpriteAnimationComponentSystem) SystemName

func (cs *SpriteAnimationComponentSystem) SystemName() string

func (*SpriteAnimationComponentSystem) SystemPriority

func (cs *SpriteAnimationComponentSystem) SystemPriority() int

func (*SpriteAnimationComponentSystem) SystemTags

func (cs *SpriteAnimationComponentSystem) SystemTags() []string

type SpriteAnimationLinkComponentSystem

type SpriteAnimationLinkComponentSystem struct {
	BaseComponentSystem
}

func (*SpriteAnimationLinkComponentSystem) Components

func (*SpriteAnimationLinkComponentSystem) ExcludeComponents

func (cs *SpriteAnimationLinkComponentSystem) ExcludeComponents(w *ecs.World) []*ecs.Component

func (*SpriteAnimationLinkComponentSystem) SystemExec

func (*SpriteAnimationLinkComponentSystem) SystemName

func (cs *SpriteAnimationLinkComponentSystem) SystemName() string

func (*SpriteAnimationLinkComponentSystem) SystemPriority

func (cs *SpriteAnimationLinkComponentSystem) SystemPriority() int

func (*SpriteAnimationLinkComponentSystem) SystemTags

func (cs *SpriteAnimationLinkComponentSystem) SystemTags() []string

type SystemExecFn

type SystemExecFn func(ctx Context)

func SystemWrap

func SystemWrap(fn SystemExecFn, mid ...Middleware) SystemExecFn

SystemWrap wraps middlewares into a SystemExecFn

type SystemInitFn

type SystemInitFn func(w *ecs.World, sys *ecs.System)

type Tag

type Tag struct {
	// public and private struct fields
	Tags  []string
	Dirty bool
	// contains filtered or unexported fields
}

Tag is the data of a tag component.

func (*Tag) Add

func (t *Tag) Add(tag string)

func (*Tag) Remove

func (t *Tag) Remove(tag string)

type TagComponentSystem

type TagComponentSystem struct {
	BaseComponentSystem
}

func (*TagComponentSystem) Components

func (cs *TagComponentSystem) Components(w *ecs.World) []*ecs.Component

func (*TagComponentSystem) ExcludeComponents

func (cs *TagComponentSystem) ExcludeComponents(w *ecs.World) []*ecs.Component

func (*TagComponentSystem) SystemExec

func (cs *TagComponentSystem) SystemExec() SystemExecFn

func (*TagComponentSystem) SystemInit

func (cs *TagComponentSystem) SystemInit() SystemInitFn

func (*TagComponentSystem) SystemName

func (cs *TagComponentSystem) SystemName() string

type TileSet added in v0.4.0

type TileSet struct {
	X            float64 // logical X position
	Y            float64 // logical Y position
	Angle        float64 // radians
	ScaleX       float64 // logical X scale (1 = 100%)
	ScaleY       float64 // logical Y scale (1 = 100%)
	OriginX      float64 // X origin (0 = left; 0.5 = center; 1 = right)
	OriginY      float64 // Y origin (0 = top; 0.5 = middle; 1 = bottom)
	OffsetX      float64 // offset origin X (in pixels)
	OffsetY      float64 // offset origin Y (in pixels)
	DrawDisabled bool    // if true, the DrawableSystem will not draw this

	DB         []*ebiten.Image
	CellWidth  float64
	CellHeight float64
	CSize      image.Point
	Cells      []int
	// contains filtered or unexported fields
}

TileSet is a drawable that efficiently draws tiles in a 2d array

func (*TileSet) ClearTransformMatrix added in v0.4.0

func (t *TileSet) ClearTransformMatrix()

ClearTransformMatrix Drawable implementation

func (*TileSet) Destroy added in v0.4.0

func (t *TileSet) Destroy()

Destroy Drawable implementation

func (*TileSet) Draw added in v0.4.0

func (t *TileSet) Draw(renderer DrawManager)

Draw Drawable implementation

func (*TileSet) IsDisabled added in v0.4.0

func (t *TileSet) IsDisabled() bool

IsDisabled Drawable implementation

func (*TileSet) SetOffset added in v0.4.0

func (t *TileSet) SetOffset(x, y float64)

SetOffset Drawable implementation

func (*TileSet) SetTransformMatrix added in v0.4.0

func (t *TileSet) SetTransformMatrix(m GeoMatrix)

SetTransformMatrix Drawable implementation

func (*TileSet) Size added in v0.4.0

func (t *TileSet) Size() (w, h float64)

Size Drawable implementation

func (*TileSet) Update added in v0.4.0

func (t *TileSet) Update(ctx Context)

Update Drawable implementation

type TiledAnimation added in v0.3.0

type TiledAnimation struct {
	Clips []TiledAnimationClip
}

TiledAnimation is an animation of a single image source and many Rectangles that represent views (subimages)

func (*TiledAnimation) Count added in v0.3.0

func (a *TiledAnimation) Count() int

Count returns the total count of cnimation clips

func (*TiledAnimation) Each added in v0.3.0

func (a *TiledAnimation) Each(fn func(i int, clip AnimationClip) bool)

Each iterates through all animation clips

func (*TiledAnimation) GetClip added in v0.3.0

func (a *TiledAnimation) GetClip(index int) AnimationClip

GetClip returns an animation clip by index

func (*TiledAnimation) GetClipEvents added in v0.3.0

func (a *TiledAnimation) GetClipEvents(index int) []*AnimationEvent

GetClipEvents returns all animation clip events by the clip index

func (*TiledAnimation) GetClipImage added in v0.3.0

func (a *TiledAnimation) GetClipImage(clipi, frame int) *ebiten.Image

GetClipImage returns the clip image

func (*TiledAnimation) GetClipOffset added in v0.3.0

func (a *TiledAnimation) GetClipOffset(clipi, frame int) (x, y float64)

GetClipOffset returns the clip offset

func (*TiledAnimation) GetClipRect added in v0.3.0

func (a *TiledAnimation) GetClipRect(clipi, frame int) image.Rectangle

GetClipRect returns the clip Rectangle (bounds)

type TiledAnimationClip added in v0.3.0

type TiledAnimationClip struct {
	// The name of an animation is not allowed to be changed during runtime
	// but since this is part of a component (and components shouldn't have logic),
	// it is a public member.
	Name       string
	Image      *ebiten.Image
	Frames     []image.Rectangle
	Events     []*AnimationEvent //TODO: link
	Fps        float64
	ClipMode   AnimClipMode
	EndedEvent *AnimationEvent //TODO: link
}

TiledAnimationClip is an animation clip, like a character walk cycle.

func (TiledAnimationClip) GetEndedEvent added in v0.3.0

func (c TiledAnimationClip) GetEndedEvent() *AnimationEvent

func (TiledAnimationClip) GetEvents added in v0.3.0

func (c TiledAnimationClip) GetEvents() []*AnimationEvent

func (TiledAnimationClip) GetFPS added in v0.3.0

func (c TiledAnimationClip) GetFPS() float64

func (TiledAnimationClip) GetFrameCount added in v0.3.0

func (c TiledAnimationClip) GetFrameCount() int

func (TiledAnimationClip) GetImage added in v0.3.0

func (c TiledAnimationClip) GetImage(frame int) *ebiten.Image

func (TiledAnimationClip) GetMode added in v0.3.0

func (c TiledAnimationClip) GetMode() AnimClipMode

func (TiledAnimationClip) GetName added in v0.3.0

func (c TiledAnimationClip) GetName() string

GetName returns the animation clip name

func (TiledAnimationClip) GetOffset added in v0.3.0

func (c TiledAnimationClip) GetOffset(frame int) (x, y float64)

GetOffset is anoop for TiledAnimationClip

func (TiledAnimationClip) GetRect added in v0.3.0

func (c TiledAnimationClip) GetRect(frame int) image.Rectangle

GetRect returns the drawable bounds

type Transform

type Transform struct {
	Parent *Transform
	X      float64
	Y      float64
	Angle  float64
	ScaleX float64
	ScaleY float64
	// contains filtered or unexported fields
}

Transform is a hierarchy based matrix

func NewTransform

func NewTransform() *Transform

NewTransform returns a new transform with ScaleX = 1 and ScaleY = 1

type TransformComponentSystem

type TransformComponentSystem struct {
	BaseComponentSystem
}

func (*TransformComponentSystem) Components

func (cs *TransformComponentSystem) Components(w *ecs.World) []*ecs.Component

func (*TransformComponentSystem) ExcludeComponents

func (cs *TransformComponentSystem) ExcludeComponents(w *ecs.World) []*ecs.Component

func (*TransformComponentSystem) SystemExec

func (cs *TransformComponentSystem) SystemExec() SystemExecFn

func (*TransformComponentSystem) SystemInit

func (cs *TransformComponentSystem) SystemInit() SystemInitFn

func (*TransformComponentSystem) SystemName

func (cs *TransformComponentSystem) SystemName() string

func (*TransformComponentSystem) SystemPriority

func (cs *TransformComponentSystem) SystemPriority() int

type TransformDrawableComponentSystem

type TransformDrawableComponentSystem struct {
	BaseComponentSystem
}

func (*TransformDrawableComponentSystem) Components

func (cs *TransformDrawableComponentSystem) Components(w *ecs.World) []*ecs.Component

func (*TransformDrawableComponentSystem) ExcludeComponents

func (cs *TransformDrawableComponentSystem) ExcludeComponents(w *ecs.World) []*ecs.Component

func (*TransformDrawableComponentSystem) SystemExec

func (*TransformDrawableComponentSystem) SystemInit

SystemInit returns the system init

func (*TransformDrawableComponentSystem) SystemName

func (cs *TransformDrawableComponentSystem) SystemName() string

func (*TransformDrawableComponentSystem) SystemPriority

func (cs *TransformDrawableComponentSystem) SystemPriority() int

type UpdateFn

type UpdateFn func(ctx Context, e ecs.Entity)

Jump to

Keyboard shortcuts

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