{"modulePath":"github.com/weakpixel/engine","version":"v0.0.0-20261205071607-94fff0387040","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package resolver\n\nPackage resolver connects Game Object data to the asset system. Its Resolver implements god.AssetResolver on top of an asset.Server, so god.Deserialize can turn the asset keys of a prefab or level (\"chars/hero.aseprite.json#run\") into the handles components hold, and god.SerializeComponents can turn them back.\n\nWiring:\n\n\tres := resolver.New(srv)\n\tres.SetScope(levelScope)        // loads of Deserialize are held by this scope\n\tresolver.Install(world, res)    // god.SetAssetResolver\n\nThe resolver knows no asset kind itself. Every kind (\"sprite\", \"clip\", \"sound\", \"voice\", ...) is registered in package assetkind by the package that owns the asset type (render, anim, sound, prefab, particles, speech), so a kind exists in every program that links its owner; a game built on package game links all of them except the opt-in speech. The kinds and the fields that use them are listed in doc/guide/engine/kinds.md.\n\n## Functions\n\n```go\nfunc Install(w *ecs.World, r *Resolver)\n```\nInstall makes r the world's asset resolver (god.SetAssetResolver).\n\n## Types\n\n```go\ntype Resolver struct {\n\t// contains filtered or unexported fields\n}\n```\nResolver implements [god.AssetResolver](/github.com/weakpixel/engine/god#AssetResolver) for an asset.Server. Like the server it is single-goroutine.\n\n```go\nfunc New(srv *asset.Server) *Resolver\n```\nNew returns a Resolver that loads into srv's global scope until [Resolver.SetScope](#Resolver.SetScope) is called. The loaders of the kinds in use (render.RegisterLoaders, anim.RegisterLoaders, sound.RegisterLoaders) must be registered on srv.\n\n```go\nfunc (r *Resolver) AssetKey(kind string, h any) (key string, err error)\n```\nAssetKey returns the key h was loaded from (\"path\" or \"path#sub\"). A stale handle (its asset was unloaded) is an error, so serialization never writes a key that no longer means anything.\n\n```go\nfunc (r *Resolver) ResolveAsset(kind, path string) (h any, err error)\n```\nResolveAsset loads path as an asset of the given kind into the current scope and returns its handle (gfx.SpriteHandle for \"sprite\", gfx.ClipHandle for \"clip\", and so on: what the kind's Load returns). It does not block: the asset may still be loading, and draws its placeholder until it is ready. A malformed path, a kind that is not registered in package assetkind or a kind whose loader is not registered on the server is an error, not a panic.\n\n```go\nfunc (r *Resolver) Scope() *asset.Scope\n```\nScope returns the scope ResolveAsset loads into.\n\n```go\nfunc (r *Resolver) SetScope(sc *asset.Scope)\n```\nSetScope sets the scope that ResolveAsset loads into. Every resolved asset is held by that scope, so releasing a level's scope frees the art its prefabs loaded. Deleting an entity releases nothing. Set the scope before Deserialize; a nil scope means the global one.\n\n","path":"github.com/weakpixel/engine/resolver","name":"resolver","synopsis":"Package resolver connects Game Object data to the asset system.","isRedistributable":true}
