Documentation
¶
Overview ¶
routine is a package for creating sequences of events, primarily for game development in Golang.
Index ¶
- type Action
- type ActionCollectionable
- type ActionIdentifiable
- type Block
- type Flow
- type Properties
- type Routine
- func (r *Routine) BlockByID(id any) *Block
- func (r *Routine) Define(id any, Actions ...Action) *Block
- func (r *Routine) Pause(blockIDs ...any)
- func (r *Routine) Properties() *Properties
- func (r *Routine) Restart(blockIDs ...any)
- func (r *Routine) Run(blockIDs ...any)
- func (r *Routine) Running(ids ...any) bool
- func (r *Routine) Stop(blockIDs ...any)
- func (r *Routine) Update()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action interface { Init(block *Block) // The Init function is called when a Action is switched to. Poll(block *Block) Flow // The Poll function is called every frame and can return a Flow, indicating what the Routine should do next. }
Action is an interface that represents an object that can Action and direct the flow of a Routine.
type ActionCollectionable ¶
type ActionCollectionable interface {
Actions() []Action
}
ActionCollectionable identifies an interface for an Action that allows it to return a slice of Actions to be added to Blocks, Gates, or Collections in definition.
type ActionIdentifiable ¶
type ActionIdentifiable interface {
ID() any
}
ActionIdentifiable identifies an interface for an action that allows that Action to be used for jumping (as though it were a label).
type Block ¶
Block represents a block of Actions. Blocks execute Actions in sequence, and have an ID that allows them to be activated or deactivated at will by their owning Routine.
func (*Block) CurrentFrame ¶
CurrentFrame returns the current frame of the Block's execution of the currently executed Action. This increases by 1 every Routine.Update() call until the Block executes another Action.
func (*Block) JumpTo ¶
JumpTo sets the Block's execution index to the index of a ActionLabel, using the label provided. If it finds the Label, then it will jump to and return that index. Otherwise, it will return -1.
func (*Block) Pause ¶
func (b *Block) Pause()
Pause pauses the specified block, so that it isn't active when the Routine is run. When it is run again, it resumes execution at its current action.
type Flow ¶
type Flow uint8
Flow is simply a uint8, and represents what a Routine should do following a Action's action.
const ( // FlowIdle means that the Routine should cycle and do the same Action again the following Update() cycle. FlowIdle Flow = iota // FlowNext means that the Routine should move on to the next Action in the Block. // If this is returned from the last Action in a Block, the Block will loop. FlowNext // FlowFinish indicates the Block should finish its execution, deactivating afterwards. FlowFinish )
type Properties ¶
Properties represents a kind of "local memory" for an Execution object.
func (*Properties) Delete ¶
func (p *Properties) Delete(keyName string)
Delete deletes a key out of the properties map.
func (Properties) Get ¶
func (p Properties) Get(propName any) any
Get returns the value associated with the given property identifier.
func (Properties) Has ¶
func (p Properties) Has(propName any) bool
Has returns if the Properties object has a property associated with the given identifier.
func (*Properties) Init ¶
func (p *Properties) Init(propName any, toValue any)
Init will initialize a property by the given name with the given value if it doesn't already exist.
func (*Properties) Set ¶
func (p *Properties) Set(propName any, value any)
Set sets the Properties object with the given property name to the value passed.
type Routine ¶
type Routine struct { Blocks []*Block // contains filtered or unexported fields }
Routine represents a container to run Blocks of code.
func (*Routine) BlockByID ¶
BlockByID returns any Block found with the given ID. If no Block with the given id is found, nil is returned.
func (*Routine) Define ¶
Define defines a Block using the ID given and the list of Actions provided and adds it to the Routine. The ID can be of any comparable type. Define returns the new Block as well. If a block with the given blockID already exists, Define will remove the previous one.
func (*Routine) Pause ¶
Pause pauses Blocks with the given IDs. If no block IDs are given, then all blocks contained in the Routine are paused.
func (*Routine) Properties ¶
func (r *Routine) Properties() *Properties
Properties returns the Properties object for the Routine.
func (*Routine) Restart ¶
Restart restarts Blocks with the given IDs. If no block IDs are given, then all blocks contained in the Routine are restarted.
func (*Routine) Run ¶
Run runs Blocks with the given IDs. If no block IDs are given, then all blocks contained in the Routine are run.
func (*Routine) Running ¶
Running returns true if at least one Block is running with at least one of the given IDs in the Routine. If no IDs are given, then any running Blocks will return.