Entity Component System framework for Ebiten
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.6 KiB

package gohan
import (
"errors"
"github.com/hajimehoshi/ebiten/v2"
)
// System represents a system that runs continuously. While the system must
// implement the Update and Draw methods, a special error value may be returned
// indicating that the system does not utilize one of the methods. System
// methods which return one of these special error values will not be called again.
//
// See the special error values ErrSystemWithoutUpdate and ErrSystemWithoutDraw.
type System interface {
// Needs returns a list of Components (specified by ID) which are required
// for an Entity to be handled by the System. When the game is running,
// matching entities will be passed to the Update and Draw methods.
Needs() []ComponentID
// Uses returns a list of Components (specified by ID) which are used by
// the System, in addition to any required Components. Because required
// Components are automatically included in this list, Uses should only
// return Components which are not also returned by Needs.
Uses() []ComponentID
// Update is called once for each matching Entity each time the game state is updated.
Update(ctx *Context) error
// Draw is called once for each matching Entity each time the game is drawn to the screen.
Draw(ctx *Context, screen *ebiten.Image) error
}
// Special error values.
var (
// ErrSystemWithoutUpdate is the error returned when a System does not implement Update.
ErrSystemWithoutUpdate = errors.New("system does not implement update")
// ErrSystemWithoutDraw is the error returned when a System does not implement Draw.
ErrSystemWithoutDraw = errors.New("system does not implement draw")
)