assetkind

package
v0.0.0-...-94fff03 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 3 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func Register(name string, k Kind)

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 Lookup

func Lookup(name string) (Kind, bool)

Lookup returns the kind registered under name.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL