{"modulePath":"github.com/nsgo-dev/game","version":"v0.2.2","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package plugin\n\nPackage plugin defines the runtime plugin contract and deterministic installer for Go plugins.\n\nBecause iOS and web targets link all native code at compile time, Go plugins are ordinary Go packages wired into a game project via go.mod. A plugin's runtime package exposes a constructor returning a [Plugin](#Plugin) value (conventionally func Plugin() plugin.Plugin), and the game installs every active plugin onto a [Host](#Host) with [Install](#Install).\n\n[Install](#Install) validates every plugin's [Plugin.API](#Plugin.API) against [APIVersion](#APIVersion), refuses duplicate plugin names, and verifies that every contributed component, system, pixel effect, data table row type, and console command name is free before registering anything. Contributions are applied in deterministic order: plugins in argument order, slice contributions in declaration order, and map contributions in sorted key order.\n\n[Host.Scheduler](#Host.Scheduler) receives four standard stage anchor pairs ([StageInput](#StageInput), [StageUpdate](#StageUpdate), [StagePhysics](#StagePhysics), [StageLate](#StageLate)) added once per scheduler so third-party systems can attach to a stage without knowing the game's own system names. [Host.OnWorld](#Host.OnWorld) applies every installed plugin's [Plugin.Codecs](#Plugin.Codecs) callback to each [entities.World](/github.com/nsgo-dev/game/pkg/entities#World) the game creates.\n\nProcess-global registries ([pixelfx](/github.com/nsgo-dev/game/pkg/pixelfx)) are written once per process per owning plugin so repeated [Install](#Install) calls in tests or after an editor reload neither panic nor overwrite another plugin's entry.\n\nDevelopment-time contributions that depend on heavier packages (MCP bridge prefabs and playtest bots) live in the separate [github.com/nsgo-dev/game/pkg/plugin/devtools](/github.com/nsgo-dev/game/pkg/plugin/devtools) package so shipped games that import pkg/plugin do not link pkg/mcp, pkg/playtest, or pkg/editor.\n\n## Constants\n\n```go\nconst APIVersion = 1\n```\nAPIVersion is the runtime plugin API contract version supported by this engine build. It is bumped only on breaking changes to the plugin contract. Every [Plugin](#Plugin) must set API to APIVersion.\n\n## Variables\n\n```go\nvar (\n\t// ErrNilHost reports a nil *Host passed to Install or a Host method.\n\tErrNilHost = errors.New(\"plugin: nil host\")\n\t// ErrNilWorld reports a nil *entities.World passed to Host.OnWorld.\n\tErrNilWorld = errors.New(\"plugin: nil world\")\n\t// ErrInvalidPlugin reports a Plugin with an invalid name, module path, or malformed contribution.\n\tErrInvalidPlugin = errors.New(\"plugin: invalid plugin\")\n\t// ErrAPIMismatch reports a Plugin whose API does not equal APIVersion.\n\tErrAPIMismatch = errors.New(\"plugin: unsupported API version\")\n\t// ErrDuplicatePlugin reports installing a plugin whose Name is already installed on the Host or repeated in the same Install call.\n\tErrDuplicatePlugin = errors.New(\"plugin: duplicate plugin\")\n\t// ErrConflict reports a contribution whose name, pattern, or effect ID collides with an existing entry or another plugin in the same Install call.\n\tErrConflict = errors.New(\"plugin: contribution conflict\")\n)\n```\n\n## Functions\n\n```go\nfunc EnsureStages(s *entities.Scheduler) error\n```\nEnsureStages registers the standard stage anchor systems ([StageInput](#StageInput), [StageUpdate](#StageUpdate), [StagePhysics](#StagePhysics), [StageLate](#StageLate)) on s if they are not already present. It is safe to call repeatedly on the same scheduler.\n\n```go\nfunc Install(h *Host, ps ...Plugin) error\n```\nInstall validates every plugin in ps against h and the process-global pixelfx registry before registering anything, then installs their contributions in deterministic order (plugins in argument order, slice fields in declaration order, maps by sorted key) and runs each plugin's Install escape hatch last.\n\n```go\nfunc ModuleVersion(modulePath string) string\n```\nModuleVersion returns the resolved Go module version of modulePath from runtime/debug.ReadBuildInfo, \"(devel)\" for a local build or replace directive without a version, or empty when modulePath is empty or not present in build info.\n\n## Types\n\n```go\ntype ConsoleCommand struct {\n\t// Name is the command token typed in the console (non-empty, without spaces or control characters).\n\tName string\n\t// Help is the one-line usage description shown by the console's help command.\n\tHelp string\n\t// Fn executes the command with its tokenized arguments and returns output text.\n\tFn func(args []string) (string, error)\n}\n```\nConsoleCommand describes one developer console command a [Plugin](#Plugin) registers on [Host.Console](#Host.Console).\n\n```go\ntype Host struct {\n\t// Components receives plugin scene component types (including ComponentType.Spawn) when non-nil.\n\tComponents *sceneformat.ComponentRegistry\n\t// Scheduler receives standard stage anchors and plugin systems when non-nil.\n\tScheduler *entities.Scheduler\n\t// DataTables receives plugin data-table row types when non-nil.\n\tDataTables *datatable.Registry\n\t// Console receives plugin console commands when non-nil.\n\tConsole *debug.Console\n\t// contains filtered or unexported fields\n}\n```\nHost holds the runtime registries that [Install](#Install) wires plugins into. Any nil registry field skips that kind of contribution.\n\n```go\nfunc (h *Host) Has(name string) bool\n```\nHas reports whether a plugin named name has been installed on h.\n\n```go\nfunc (h *Host) OnWorld(w *entities.World) error\n```\nOnWorld runs the [Plugin.Codecs](#Plugin.Codecs) callback of every installed plugin on w, in installation order.\n\n```go\nfunc (h *Host) Plugins() []Installed\n```\nPlugins returns the plugins installed on h in installation order.\n\n```go\ntype Installed struct {\n\t// Name is the plugin's unique short identifier.\n\tName string\n\t// Module is the plugin's Go module path, if declared.\n\tModule string\n\t// Version is the Go module version from runtime/debug.ReadBuildInfo, \"(devel)\" for a local build or replace directive without a version, or empty when Module is empty or absent from build info.\n\tVersion string\n}\n```\nInstalled describes a plugin that has been installed on a [Host](#Host).\n\n```go\ntype Plugin struct {\n\t// Name uniquely identifies the plugin using the same rule as plugin.yaml's name (1 to 64 lower-case ASCII letters, digits and '-', starting with a letter or digit).\n\tName string\n\t// Module is the plugin's Go module path, matching go.mod and plugin.yaml when set. Install reads its version from runtime/debug.ReadBuildInfo.\n\tModule string\n\t// API must equal [APIVersion].\n\tAPI int\n\t// Components declares scene component types (including optional Spawn factories) merged into Host.Components in slice order.\n\tComponents []sceneformat.ComponentType\n\t// Systems declares ECS scheduler systems added to Host.Scheduler in slice order.\n\tSystems []System\n\t// Codecs registers snapshot codecs on every entities.World passed to Host.OnWorld.\n\tCodecs func(*entities.World) error\n\t// PixelFX declares procedural pixel effects registered in the process-global pixelfx registry in sorted ID order, once per process per owning plugin.\n\tPixelFX map[string]*pixelfx.Effect\n\t// RowTypes maps data-table file patterns to typed Go row schemas registered on Host.DataTables in sorted pattern order.\n\tRowTypes map[string]*datatable.RowType\n\t// Console declares developer console commands registered on Host.Console in slice order.\n\tConsole []ConsoleCommand\n\t// Install is an optional escape hatch called last after all declarative contributions have been validated and registered.\n\tInstall func(*Host) error\n}\n```\nPlugin describes a runtime Go plugin's identity and declarative contributions.\n\nThere is deliberately no Version field: a plugin's version is its Go module version resolved by the game project's go.mod and read by [Install](#Install) from runtime/debug.ReadBuildInfo.\n\n```go\ntype Stage string\n```\nStage identifies one of the four standard scheduler stages that a plugin system can attach to without knowing the game's own system names.\n\n[Install](#Install) adds anchor systems for the four stages once per [entities.Scheduler](/github.com/nsgo-dev/game/pkg/entities#Scheduler) in the order [StageInput](#StageInput) -\u003e [StageUpdate](#StageUpdate) -\u003e [StagePhysics](#StagePhysics) -\u003e [StageLate](#StageLate). A [System](#System) with Stage set is constrained with entities.After(stage.Start()) and entities.Before(stage.End()).\n\n```go\nconst (\n\t// StageInput runs first on each fixed step, for reading input and translating player intent.\n\tStageInput Stage = \"input\"\n\t// StageUpdate runs after StageInput, for general gameplay systems.\n\tStageUpdate Stage = \"update\"\n\t// StagePhysics runs after StageUpdate, for physics, movement, and collision resolution.\n\tStagePhysics Stage = \"physics\"\n\t// StageLate runs last, after StagePhysics, for camera follow, transform synchronization, and cleanup.\n\tStageLate Stage = \"late\"\n)\n```\n\n```go\nfunc Stages() []Stage\n```\nStages returns the four standard scheduler stages in execution order.\n\n```go\nfunc (s Stage) End() string\n```\nEnd returns the scheduler anchor system name marking the end of s, or empty if s is not a valid stage.\n\n```go\nfunc (s Stage) Start() string\n```\nStart returns the scheduler anchor system name marking the start of s, or empty if s is not a valid stage.\n\n```go\nfunc (s Stage) String() string\n```\nString returns the stage's name.\n\n```go\nfunc (s Stage) Valid() bool\n```\nValid reports whether s is one of the four standard stages.\n\n```go\ntype System struct {\n\t// Name uniquely identifies the system within the scheduler.\n\tName string\n\t// Stage optionally places the system inside one of the four standard stages ([StageInput], [StageUpdate], [StagePhysics], [StageLate]). Leave empty to constrain only via Before and After.\n\tStage Stage\n\t// Before lists system names this system must run before.\n\tBefore []string\n\t// After lists system names this system must run after.\n\tAfter []string\n\t// Fn is the update function run on each Scheduler.Step.\n\tFn func(w *entities.World, dt time.Duration)\n}\n```\nSystem describes one ECS update system a [Plugin](#Plugin) registers on [Host.Scheduler](#Host.Scheduler).\n\n","path":"github.com/nsgo-dev/game/pkg/plugin","name":"plugin","synopsis":"Package plugin defines the runtime plugin contract and deterministic installer for Go plugins.","isRedistributable":true}
