resolver

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: 5 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 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.

Wiring:

res := resolver.New(srv)
res.SetScope(levelScope)        // loads of Deserialize are held by this scope
resolver.Install(world, res)    // god.SetAssetResolver

The 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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Install

func Install(w *ecs.World, r *Resolver)

Install makes r the world's asset resolver (god.SetAssetResolver).

Types

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver implements god.AssetResolver for an asset.Server. Like the server it is single-goroutine.

func New

func New(srv *asset.Server) *Resolver

New returns a Resolver that loads into srv's global scope until Resolver.SetScope is called. The loaders of the kinds in use (render.RegisterLoaders, anim.RegisterLoaders, sound.RegisterLoaders) must be registered on srv.

func (*Resolver) AssetKey

func (r *Resolver) AssetKey(kind string, h any) (key string, err error)

AssetKey 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.

func (*Resolver) ResolveAsset

func (r *Resolver) ResolveAsset(kind, path string) (h any, err error)

ResolveAsset 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.

func (*Resolver) Scope

func (r *Resolver) Scope() *asset.Scope

Scope returns the scope ResolveAsset loads into.

func (*Resolver) SetScope

func (r *Resolver) SetScope(sc *asset.Scope)

SetScope 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.

Jump to

Keyboard shortcuts

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