API 参考取自源码中的 Go 文档注释,以英文书写。
package manifest
import "github.com/nsgo-dev/game/pkg/tooling/manifest"概述
Package manifest walks an assets directory and generates a typed Go source file referencing every asset, so missing or removed assets fail the build at compile time.
索引
函数
func Generate(dir string, opts Options) ([]byte, error)Generate scans dir and returns a gofmt-formatted Go source file declaring typed references for every asset in dir.
func Verify(dir string, refs []string) errorVerify checks that every asset reference in refs exists as a regular file under dir. Each ref may be a relative path ("hero.png") or an "asset:" URI ("asset:hero.png").
func WriteFile(dir, outPath string, opts Options) errorWriteFile generates the manifest for dir and writes it to outPath, creating parent directories if needed.
类型
type Entry struct {
// Path is the asset's slash-separated path relative to the scanned directory.
Path string
// URI is the asset's URI with the configured prefix, such as "asset:hero.png".
URI string
// Ident is the exported Go identifier generated for this asset, such as "ImageHero".
Ident string
// Kind is the asset's classified type.
Kind Kind
}Entry is one asset file discovered in the assets directory.
func Scan(dir string, opts Options) ([]Entry, error)Scan walks dir deterministically, skipping dot-prefixed entries, Go source files and import settings sidecars (files named *.import.yaml, as package importsettings names them), and returns the discovered asset entries sorted by Path with unique Go identifiers.
type Kind intKind classifies a discovered asset file by its extension.
const (
// KindOther is any asset that is not an image, audio or map file.
KindOther Kind = iota
// KindImage is an image file exposed as a core.ImageSource.
KindImage
// KindAudio is an audio file exposed as an audio.Source.
KindAudio
// KindMap is a tilemap file (.tmj, .tmx, .tsj, .tsx).
KindMap
)type Options struct {
// Package is the generated Go file's package name ("assets" when empty).
Package string
// Prefix is prepended to each asset's relative path to form its URI ("asset:" when empty).
Prefix string
// Embed emits //go:embed directives so asset bytes are compiled into the binary instead of referencing URIs.
Embed bool
// EmbedDir is an optional slash-separated directory prefix prepended to each //go:embed pattern, for when the generated file lives in a parent of the assets directory.
EmbedDir string
// Header is the comment line at the top of the generated file (a standard generated-file notice when empty).
Header string
}Options configures asset scanning and Go source generation.
func DefaultOptions() OptionsDefaultOptions returns Options with the generator's defaults: package "assets", URI prefix "asset:" and URI mode.