Documentation
¶
Overview ¶
Package wecqs is an ECS framework for Go game development.
Index ¶
- Constants
- Variables
- func LogDebug(layout string, v ...any)
- func LogError(layout string, v ...any)
- func LogInfo(layout string, v ...any)
- func LogTrace(layout string, v ...any)
- func LogWarn(layout string, v ...any)
- func SetLogger(logger Logger)
- type AssetReader
- type DrawSystem
- type Entity
- func (entity *Entity) AddComponents(components ...any) *Entity
- func (entity *Entity) AddTags(tags ...string) *Entity
- func (entity *Entity) Component(dst any) bool
- func (entity *Entity) Components() []any
- func (entity *Entity) HasTag(tag string) bool
- func (entity *Entity) ID() ID
- func (entity *Entity) String() string
- func (entity *Entity) Tags() []string
- type ErrInputsConflict
- type Game
- func (game *Game) AddIcons(icons ...image.Image) *Game
- func (game *Game) AddWorlds(worlds ...*World) *Game
- func (game *Game) AllowFullscreen(enable bool) *Game
- func (game *Game) AllowHighDPI(enable bool) *Game
- func (game *Game) AllowResize(enable bool) *Game
- func (game *Game) Run(worldName, sceneName string) error
- func (game *Game) SetFullscreen(enable bool) *Game
- func (game *Game) SetResolution(width, height int) *Game
- func (game *Game) SetResolutionLimits(minWidth, minHeight, maxWidth, maxHeight int) *Game
- func (game *Game) SetScale(scale int) *Game
- func (game *Game) SetTPS(tps int) *Game
- func (game *Game) SetVsync(enable bool) *Game
- type ID
- type Input
- func (input *Input) AddGamepadAxis(gamepadAxis ebitengine.StandardGamepadAxis) *Input
- func (input *Input) AddGamepadButton(gamepadButton ebitengine.StandardGamepadButton) *Input
- func (input *Input) AddGamepadID(gamepadID ebitengine.GamepadID) *Input
- func (input *Input) AddKeys(keys ...ebitengine.Key) *Input
- func (input *Input) AddMode(mode inputMode) *Input
- func (input *Input) AddMouseButton(mouseButton ebitengine.MouseButton) *Input
- func (input *Input) DisableRebind() *Input
- func (input *Input) IsJustPressed() bool
- func (input *Input) IsJustReleased() bool
- func (input *Input) IsPressed() bool
- func (input *Input) ModeAvailable() bool
- func (input *Input) PressDuration() int
- func (input *Input) Value() float64
- type LayoutSystem
- type LoadSystem
- type Logger
- type Query
- type Scene
- type SilentLogger
- type SimpleLogger
- type State
- func (state *State) AddAssetReader(ext string, assetReader AssetReader) *State
- func (state *State) AddWorlds(worlds ...*World)
- func (state *State) CanvasScale() int
- func (state *State) CanvasSize() (int, int)
- func (state *State) CurrentScene() *Scene
- func (state *State) CurrentWorld() *World
- func (state *State) GetAsset(name string) (raw []byte, err error)
- func (state *State) GetAudio(name string) (s io.ReadSeeker, err error)
- func (state *State) GetFont(name string, size float64) (font.Face, error)
- func (state *State) GetImage(name string) (img *ebitengine.Image, i image.Image, err error)
- func (state *State) GetJSON(name string, dst any) (err error)
- func (state *State) InputJustPressed(name string) bool
- func (state *State) InputJustReleased(name string) bool
- func (state *State) InputPressDuration(name string) int
- func (state *State) InputPressed(name string) bool
- func (state *State) InputValue(name string) float64
- func (state *State) NewAudioPlayer(name string) (*audio.Player, error)
- func (state *State) NewLoopAudioPlayer(name string, length int64) (*audio.Player, error)
- func (state *State) NewLoopWithIntroAudioPlayer(name string, introLength, loopLength int64) (*audio.Player, error)
- func (state *State) Query(query Query, fn func(*Entity) bool)
- func (state *State) RebindInput(name string, newInput *Input, force bool) error
- func (state *State) RegisterInput(name string, newInput *Input)
- func (state *State) SetFullscreen(enable bool)
- func (state *State) SetResolution(width, height int)
- func (state *State) SetVsync(enable bool)
- func (state *State) Switch(worldName, sceneName string) error
- func (state *State) World(name string) *World
- type UnloadSystem
- type UpdateSystem
- type World
Constants ¶
const ( InputKeyboard inputMode = iota InputMouseButton InputGamepadButton InputGamepadAxis )
Variables ¶
var ( // ErrShutdown is an error which can be returned by an UpdateSystem to gracefully stop the game. ErrShutdown = errors.New("game shutdown") ErrWorldNoneActive = errors.New("no world is currently active") ErrSceneNoneActive = errors.New("no scene is currently active") ErrInputsRebindDisabled = errors.New("input mapping has rebinding disabled") ErrExpectedFolder = errors.New("expected path to folder") ErrUnhandledType = errors.New("unhandled type") )
Functions ¶
Types ¶
type DrawSystem ¶
type DrawSystem interface {
Draw(state *State, canvas *ebitengine.Image)
}
type Entity ¶
type Entity struct {
// contains filtered or unexported fields
}
Entity is a general-purpose collection of components and tags which queries can be run on.
func (*Entity) AddComponents ¶
AddComponents adds the given components to this entity and returns it.
func (*Entity) Component ¶
Component gets a component from this entity and stores it in the given destination. Generally this method wouldn't be used, as in regular usage a component would be extracted using a Has query instead. But for completeness’ sake, it's here anyway.
func (*Entity) Components ¶ added in v0.4.0
Components returns a slice of all the components in this entity.
type ErrInputsConflict ¶
func (ErrInputsConflict) Error ¶
func (e ErrInputsConflict) Error() string
type Game ¶ added in v0.5.0
type Game struct {
// contains filtered or unexported fields
}
func (*Game) AddIcons ¶ added in v0.5.0
AddIcons adds window icons to the game. Adding multiple icons allows for the one of the closest desired size to be chosen automatically (see ebiten.SetWindowIcon).
It returns the game, which makes it useful for initialising by chaining method calls together. This has no effect when running on non-desktops.
func (*Game) AddWorlds ¶ added in v0.5.0
AddWorlds adds all the given worlds to the game state.
It returns the game, which makes it useful for initialising by chaining method calls together.
func (*Game) AllowFullscreen ¶ added in v0.5.0
AllowFullscreen sets if native desktop fullscreen is allowed or not. This currently only has an effect on macOS (see ebiten.WindowResizingModeOnlyFullscreenEnabled).
It returns the game, which makes it useful for initialising by chaining method calls together.
func (*Game) AllowHighDPI ¶ added in v0.5.2
AllowHighDPI sets if the game should acknowledge the high-DPI settings of the host system.
It returns the game, which makes it useful for initialising by chaining method calls together.
func (*Game) AllowResize ¶ added in v0.5.0
AllowResize sets if window resizing is enabled or disabled.
It returns the game, which makes it useful for initialising by chaining method calls together. This has no effect when running on non-desktops.
func (*Game) Run ¶ added in v0.5.0
Run initialises the game with a starting world and scene and runs it.
func (*Game) SetFullscreen ¶ added in v0.5.0
SetFullscreen sets if the game should be fullscreen. This does not have an effect on macOS if fullscreen has been enabled natively by the desktop.
It returns the game, which makes it useful for initialising by chaining method calls together. This has no effect when running on non-desktops.
func (*Game) SetResolution ¶ added in v0.5.0
SetResolution sets the canvas resolution of the game.
It returns the game, which makes it useful for initialising by chaining method calls together. This has no effect when running on non-desktops.
func (*Game) SetResolutionLimits ¶ added in v0.5.0
SetResolutionLimits sets the resolution limits of the game window. A negative value means the size is unlimited.
It returns the game, which makes it useful for initialising by chaining method calls together. This has no effect when running on non-desktops.
func (*Game) SetScale ¶ added in v0.5.3
SetScale sets the canvas scale of the game.
It returns the game, which makes it useful for initialising by chaining method calls together.
func (*Game) SetTPS ¶ added in v0.5.0
SetTPS sets the maximum TPS (ticks per second). By default, this is set to 60. Setting the TPS to a negative number results in ticks being synced to the framerate (see ebiten.SetTPS).
It returns the game, which makes it useful for initialising by chaining method calls together.
type Input ¶
type Input struct { Mode inputMode KeyPrimary ebitengine.Key KeySecondary ebitengine.Key MouseButton ebitengine.MouseButton GamepadID ebitengine.GamepadID GamepadButton ebitengine.StandardGamepadButton GamepadAxis ebitengine.StandardGamepadAxis // contains filtered or unexported fields }
func NewInput ¶
func NewInput() *Input
NewInput returns a new Input with all the input values set to -1 by default, meaning it will not react to any inputs.
func (*Input) AddGamepadAxis ¶
func (input *Input) AddGamepadAxis(gamepadAxis ebitengine.StandardGamepadAxis) *Input
func (*Input) AddGamepadButton ¶
func (input *Input) AddGamepadButton(gamepadButton ebitengine.StandardGamepadButton) *Input
func (*Input) AddGamepadID ¶
func (input *Input) AddGamepadID(gamepadID ebitengine.GamepadID) *Input
func (*Input) AddKeys ¶
func (input *Input) AddKeys(keys ...ebitengine.Key) *Input
AddKeys sets the input keys and returns the input. If more than 2 keys are given, the rest are ignored.
func (*Input) AddMouseButton ¶
func (input *Input) AddMouseButton(mouseButton ebitengine.MouseButton) *Input
func (*Input) DisableRebind ¶
func (*Input) IsJustPressed ¶
func (*Input) IsJustReleased ¶
func (*Input) ModeAvailable ¶
func (*Input) PressDuration ¶
type LayoutSystem ¶
type LayoutSystem interface {
Layout(state *State, canvas *ebitengine.Image)
}
type LoadSystem ¶
type Query ¶
type Query interface { // Match returns true if the Entity does not match the query, else returns false. Match(*Entity) bool }
type Scene ¶
type Scene struct {
// contains filtered or unexported fields
}
func (*Scene) AddEntities ¶
AddEntities adds all the given entities.
It returns the scene, which makes it useful for initialising scenes by chaining method calls together.
func (*Scene) Query ¶
Query runs a given function on all matching entities that match a given query. If false is returned from the given function, iteration will stop.
func (*Scene) RemoveEntities ¶
RemoveEntities removes all entities with the given IDs. This uses a fast method for removing elements from a slice which does not preserve order.
It returns the scene, which makes it useful for initialising scenes by chaining method calls together.
type SilentLogger ¶ added in v0.3.0
type SilentLogger struct{}
SilentLogger is a levelled logger implementation which does nothing.
func (SilentLogger) Debug ¶ added in v0.3.0
func (s SilentLogger) Debug(string, ...any)
func (SilentLogger) Error ¶ added in v0.3.0
func (s SilentLogger) Error(string, ...any)
func (SilentLogger) Info ¶ added in v0.3.0
func (s SilentLogger) Info(string, ...any)
func (SilentLogger) Trace ¶ added in v0.3.0
func (s SilentLogger) Trace(string, ...any)
func (SilentLogger) Warn ¶ added in v0.3.0
func (s SilentLogger) Warn(string, ...any)
type SimpleLogger ¶ added in v0.3.0
type SimpleLogger struct { // Level specifies what sort of logs should be outputted. // -1: none // 0: errors // 1: warnings // 2: informational logs // 3: debug logging (verbose) // 4: trace logging (extremely verbose) Level int // contains filtered or unexported fields }
SimpleLogger is a simple levelled logger implementation, which prints all logs to the console (stderr).
func (*SimpleLogger) Debug ¶ added in v0.3.0
func (l *SimpleLogger) Debug(layout string, v ...any)
func (*SimpleLogger) Error ¶ added in v0.3.0
func (l *SimpleLogger) Error(layout string, v ...any)
func (*SimpleLogger) Info ¶ added in v0.3.0
func (l *SimpleLogger) Info(layout string, v ...any)
func (*SimpleLogger) Trace ¶ added in v0.3.0
func (l *SimpleLogger) Trace(layout string, v ...any)
func (*SimpleLogger) Warn ¶ added in v0.3.0
func (l *SimpleLogger) Warn(layout string, v ...any)
type State ¶ added in v0.2.0
type State struct {
// contains filtered or unexported fields
}
State stores the current game state.
func (*State) AddAssetReader ¶ added in v0.4.0
func (state *State) AddAssetReader(ext string, assetReader AssetReader) *State
AddAssetReader adds an asset handler function to the state, allowing it to read assets from a new file type. The function takes a path to the asset file as the only argument and returns an fs.FS and an error.
It returns the state, which makes it useful for initialising the state by chaining method calls together.
func (*State) CanvasScale ¶ added in v0.5.3
CanvasScale returns the current canvas scale.
func (*State) CanvasSize ¶ added in v0.3.2
CanvasSize returns the current canvas size.
func (*State) CurrentScene ¶ added in v0.2.0
CurrentScene returns the current scene.
func (*State) CurrentWorld ¶ added in v0.2.0
CurrentWorld returns the current world.
func (*State) GetAsset ¶ added in v0.2.0
GetAsset reads a given asset for this world and returns its raw bytes.
func (*State) GetAudio ¶ added in v0.2.0
func (state *State) GetAudio(name string) (s io.ReadSeeker, err error)
GetAudio returns an MP3, WAV, or Vorbis audio file as an io.ReadSeeker. Usually, NewAudioPlayer, NewLoopAudioPlayer, or NewLoopWithIntroAudioPlayer would be preferred.
func (*State) InputJustPressed ¶ added in v0.2.0
InputJustPressed returns true if the input with the given name was just pressed.
func (*State) InputJustReleased ¶ added in v0.2.0
InputJustReleased returns true if the input with the given name was just released.
func (*State) InputPressDuration ¶ added in v0.2.0
InputPressDuration returns the number of update cycles the input with the given name has been pressed for.
func (*State) InputPressed ¶ added in v0.2.0
InputPressed returns true if the input with the given name is currently pressed.
func (*State) InputValue ¶ added in v0.2.0
InputValue returns the value of the input with the given name, between 0.0 and 1.0.
func (*State) NewAudioPlayer ¶ added in v0.2.0
func (*State) NewLoopAudioPlayer ¶ added in v0.2.0
func (*State) NewLoopWithIntroAudioPlayer ¶ added in v0.2.0
func (*State) Query ¶ added in v0.2.0
Query iterates over all entities in the current scene, running a given function.
func (*State) RebindInput ¶ added in v0.2.0
RebindInput changes an existing input mapping with conflict detection. When force is true, conflict detection is skipped, and mappings are created regardless of if they existed already. Error will still be returned if input mapping has rebinding disabled, regardless of the value of force.
func (*State) RegisterInput ¶ added in v0.2.0
RegisterInput adds a new input mapping with the given name if it has not already been added. If an input mapping with this name already exists, nothing is done. This makes it good for initialising input mappings per-system.
func (*State) SetFullscreen ¶ added in v0.3.0
SetFullscreen sets if the game should be fullscreen. This does not have an effect on macOS if fullscreen has been enabled natively by the desktop.
This has no effect when running on non-desktops.
func (*State) SetResolution ¶ added in v0.3.0
SetResolution sets the resolution of the game.
This has no effect when running on non-desktops.
type UnloadSystem ¶
type UpdateSystem ¶
type World ¶
type World struct {
// contains filtered or unexported fields
}
World is a collection of scenes and systems.
func (*World) AddScenes ¶
AddScenes all the given scenes to the world.
It returns the world, which makes it useful for initialising world by chaining method calls together.
func (*World) AddSystems ¶
AddSystems all the given systems to the world.
It returns the world, which makes it useful for initialising world by chaining method calls together.
func (*World) SetAssets ¶ added in v0.4.0
SetAssets sets the assets for this world. The given value can be a string, an fs.FS, or an embed.FS. If a string is provided, it must be a path to either a folder of assets, or an archive file containing the assets. By default, only .zip files are supported. Use (*State).AddAssetReader to add handlers for other archive types.
It returns the world, which makes it useful for initialising world by chaining method calls together.