Documentation
¶
Overview ¶
Package assetkind is the registry of asset kinds: the names a component field carries in its +game:asset:kind=... marker ("sprite", "clip", "voice"), each with how to load a key of that kind and how to find the key of a handle again.
The package that owns an asset type registers its kinds from an init function, so a kind exists in every program that links its owner:
func init() {
assetkind.Register(AssetKindSprite, assetkind.Of(LoadSprite,
func(srv *asset.Server, h gfx.SpriteHandle) asset.Key { return SpriteStoreOf(srv).Key(h) }))
}
Package resolver looks kinds up here when it turns the asset keys of a level or prefab into handles and back. The package imports only the standard library and the asset module, so every owner can import it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Names ¶
func Names() []string
Names returns the registered kind names, sorted. It allocates; use it for tools, tests and error texts.
func Register ¶
Register adds an asset kind under name. Call it from an init function of the package that owns the asset type. It is safe for concurrent use.
Panics with "assetkind: kind ... needs Load and Key" when either function is nil, and with "assetkind: kind ... is already registered" when name is taken: a kind has one owner.
Types ¶
type Kind ¶
type Kind struct {
// Load loads key into sc and returns the handle components hold. It
// may panic like asset.Load; the resolver turns that into an error.
Load func(sc *asset.Scope, key string) any
// Key returns the key h was loaded from on srv, and false when h is not
// a handle of the kind. A stale handle returns the zero Key.
Key func(srv *asset.Server, h any) (asset.Key, bool)
}
Kind is how one asset kind is loaded and written back.
func Of ¶
func Of[H any](load func(sc *asset.Scope, key string) H, key func(srv *asset.Server, h H) asset.Key) Kind
Of builds a Kind from the two typed functions an owner already has: its Load helper and the Key method of its store. H is the handle type components hold (gfx.SpriteHandle); the Kind's Key reports false for any other type.