{"modulePath":"github.com/weakpixel/engine","version":"v0.0.0-20261205071607-94fff0387040","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package inputsys\n\nPackage inputsys connects an input.Router to an ecs World: [InputSystem](#InputSystem) updates the router once per tick and publishes it as a resource, and [TouchControlsExtract](#TouchControlsExtract) draws the virtual touch controls. game.Engine adds both; wire them by hand when using the low-level packages.\n\n## Constants\n\n```go\nconst TouchLayer int16 = 32766\n```\nTouchLayer is the layer the virtual touch controls are drawn on: above the game, below debug shapes.\n\n## Functions\n\n```go\nfunc RegisterLoaders(srv *asset.Server, acts *input.Actions)\n```\nRegisterLoaders makes bindings files (\"input/bindings.json\") loadable on srv, validated against acts. The placeholder is empty bindings, so a handle that is loading or failed binds nothing. It panics with \"input: RegisterLoaders: nil Actions\" or \"input: RegisterLoaders: Actions not frozen\", and like [asset.Register](/github.com/weakpixel/asset#Register) if it runs twice on srv.\n\n## Types\n\n```go\ntype BindingsHandle struct{ asset.Ref }\n```\nBindingsHandle refers to compiled [input.Bindings](/github.com/weakpixel/engine/input#Bindings) loaded through the asset system. It is 8 bytes, comparable and pointer-free; the zero value means \"none\". No component holds one, so it lives here rather than in gfx.\n\n```go\nfunc LoadBindings(sc *asset.Scope, key string) BindingsHandle\n```\nLoadBindings returns the handle for a bindings file and adds a hold for sc. It never blocks and panics like [asset.Load](/github.com/weakpixel/asset#Load).\n\n```go\nfunc LoadBindingsSync(sc *asset.Scope, key string) (BindingsHandle, error)\n```\nLoadBindingsSync is LoadBindings followed by loading until the file is ready or failed, like [asset.LoadSync](/github.com/weakpixel/asset#LoadSync). It blocks.\n\n```go\ntype BindingsStore struct {\n\t// contains filtered or unexported fields\n}\n```\nBindingsStore resolves [BindingsHandle](#BindingsHandle) values. It is a small value; copy it freely.\n\n```go\nfunc BindingsStoreOf(srv *asset.Server) BindingsStore\n```\nBindingsStoreOf returns the bindings store of srv. It panics like [asset.StoreOf](/github.com/weakpixel/asset#StoreOf) if [RegisterLoaders](#RegisterLoaders) has not run on srv.\n\n```go\nfunc (s BindingsStore) Err(h BindingsHandle) error\n```\nErr returns why the file failed to load, or nil.\n\n```go\nfunc (s BindingsStore) Get(h BindingsHandle) *input.Bindings\n```\nGet returns the bindings, or the empty placeholder; see [asset.Store.Get](/github.com/weakpixel/asset#Store.Get) for the pointer validity rule.\n\n```go\nfunc (s BindingsStore) Lookup(h BindingsHandle) (*input.Bindings, asset.State)\n```\nLookup is Get plus the load state.\n\n```go\nfunc (s BindingsStore) Ready(h BindingsHandle) bool\n```\nReady reports whether h refers to loaded bindings.\n\n```go\nfunc (s BindingsStore) Version(h BindingsHandle) uint32\n```\nVersion changes whenever the asset is committed again (first load, and hot reload once the asset system has it).\n\n```go\ntype InputSystem struct {\n\t// OnError receives the load error of the watched bindings. nil logs it.\n\tOnError func(error)\n\t// contains filtered or unexported fields\n}\n```\nInputSystem runs [input.Router.Update](/github.com/weakpixel/engine/input#Router.Update) once per tick. Add it first in the input stage, so every later system in the tick reads the same action state.\n\nInit publishes the World resources \\*input.Router and \\*input.Events (the Router's events, reused every tick).\n\nWith [InputSystem.Watch](#InputSystem.Watch) it also follows a bindings asset: whenever the asset is committed (first load, and reloads), the router gets the new default bindings before the tick's Update. A file that fails to load is reported once through OnError and the router keeps its bindings.\n\n```go\nfunc New(r *input.Router) *InputSystem\n```\nNew returns the system for r. Panics with \"input: \" if r is nil.\n\n```go\nfunc (s *InputSystem) Init(ctx *system.Context)\n```\nInit implements system.Initializer.\n\n```go\nfunc (s *InputSystem) Router() *input.Router\n```\nRouter returns the router the system updates.\n\n```go\nfunc (s *InputSystem) Run(*system.Context)\n```\nRun implements system.Runner.\n\n```go\nfunc (s *InputSystem) Watch(srv *asset.Server, h BindingsHandle)\n```\nWatch makes the system apply the bindings asset h whenever it becomes ready or is committed again. srv must have the input loaders ([RegisterLoaders](#RegisterLoaders)); Watch panics like [BindingsStoreOf](#BindingsStoreOf) otherwise. A second call replaces the watched handle.\n\n```go\ntype TouchControlsExtract struct {\n\t// Color and PressedColor are the outline colors. Zero means a\n\t// translucent white and opaque white.\n\tColor, PressedColor gfx.Color\n\t// AlwaysShow draws the controls whatever the active device.\n\tAlwaysShow bool\n\t// contains filtered or unexported fields\n}\n```\nTouchControlsExtract draws the touch regions of the player that owns the touch screen as screen-space outlines: rectangles and circles, a stick as its base plus a knob. It draws nothing while that player's active device is not the touch screen, so the controls appear on the first touch and disappear when a keyboard or pad is used, unless AlwaysShow is set.\n\nAdd it to the render stage after extract.ResetQueue. It needs the \\*render.Queue resource and the \\*input.Router resource that [InputSystem.Init](#InputSystem.Init) publishes, so it must be initialized after it.\n\n```go\nfunc NewTouchControlsExtract() *TouchControlsExtract\n```\nNewTouchControlsExtract returns the system.\n\n```go\nfunc (s *TouchControlsExtract) Init(ctx *system.Context)\n```\nInit implements system.Initializer.\n\n```go\nfunc (s *TouchControlsExtract) Run(*system.Context)\n```\nRun implements system.Runner.\n\n","path":"github.com/weakpixel/engine/input/inputsys","name":"inputsys","synopsis":"Package inputsys connects an input.Router to an ecs World: InputSystem updates the router once per tick and publishes it as a resource, and TouchControlsExtract draws the virtual touch controls.","isRedistributable":true}
