GitHubНачать

Справочник API собран из Go doc-комментариев в исходном коде и написан на английском языке.

package assetbuild

import "github.com/nsgo-dev/game/pkg/tooling/assetbuild"

Обзор

Package assetbuild builds a game's assets from the assets section of its game.yaml, which package project defines: it packs sprite atlases, encodes KTX2 textures, converts audio, bakes TrueType and OpenType fonts into AngelCode BMFonts, packs glTF models into single GLB files and generates the Go asset manifest, applying the import settings sidecar beside each image, sound, font or model that package importsettings reads, and keeps a text cache of what each output was built from so a later run rebuilds only the targets whose inputs, sidecars or settings changed.

Указатель

Функции

func ModelFiles(model string, data []byte) ([]string, error)

ModelFiles returns the slash-separated paths, relative to the project root, of the files the glTF or GLB model at model (slash-separated, relative to the project root) names by relative path in its buffers and images, given the model file's bytes, in the order the model lists them and without repeats: the files a model target embeds and counts as inputs. Data URIs name no file. A URI with a scheme, an absolute path, or one that leaves the project is an error, as is a model whose JSON does not decode.

Типы

type Builder struct {
	// Root is the directory game.yaml's paths are relative to, normally the one holding game.yaml.
	Root string
	// Audio converts audio targets (a zero Encoder when nil).
	Audio *audioconv.Encoder
	// Version names the tools that build the targets, such as the game layer's module version; a target built by a different Version is rebuilt.
	Version string
	// Force rebuilds every target even when the cache says it is up to date.
	Force bool
	// Check reports which targets are out of date without writing anything under Root: their status is Stale instead of Built. A target whose cache entry does not match is built in a temporary folder and counts as up to date when Root already holds exactly the files it writes, so a check passes on a fresh checkout whose committed outputs are current even without the cache. AAC and MP3 targets are the exception: an external encoder writes them, and another encoder or encoder version writes different bytes for the same input, so with no cache entry for one, as in a fresh checkout, it counts as up to date when its output exists. An atlas also counts as stale when its output folder holds a page file of its name that it no longer writes.
	Check bool
	// contains filtered or unexported fields
}

Builder builds a project's asset targets against the files in its directory.

func (b *Builder) Build(ctx context.Context, a *project.Assets) (*Report, error)

Build builds the targets of a, game.yaml's assets section, in order, skipping each whose key (a hash of its settings, its inputs' paths and contents, those of the import settings sidecars beside them, and Version) and outputs match the cache, then saves the cache when it changed. A nil a declares no targets: Build then reads and writes nothing. A setting in a sidecar overrides the target's: a texture target takes an image sidecar's filter, format, mipmaps and sRGB, an atlas cuts each image whose sidecar has a slice into frames, an audio target takes every setting of a sound's sidecar, loop points included, a font target a font sidecar's size, characters and padding, and a model target a model sidecar's scale and whether to keep animations. A model's key also covers the buffers and images it names by relative path. An image that both an atlas and a texture target read may hold both kinds of settings in its sidecar, each target taking its own; otherwise a setting no target of the image reads is refused. Before building, Build refuses a sidecar in a folder a target reads from whose asset no target reads, such as one with a mistyped name, and one whose name differs from its asset's in case, unless it holds only a credit section and its asset is there. A sidecar's credit section changes no output and is left out of the key of the targets that read its asset, so editing a credit rebuilds nothing; the key takes the rest of the sidecar's settings, not its bytes, so a comment or layout change rebuilds nothing either. A second Build with nothing changed writes no file. When a target fails, Build saves what it built so far and returns the report up to that target with the error.

type Kind string

Kind is the sort of work a target does.

const (
	// KindAtlas packs a folder of PNG images into atlas pages.
	KindAtlas Kind = "atlas"
	// KindTexture encodes an image into a KTX2 container.
	KindTexture Kind = "texture"
	// KindAudio converts a WAV file.
	KindAudio Kind = "audio"
	// KindFont bakes a TrueType or OpenType font into a bitmap font.
	KindFont Kind = "font"
	// KindModel packs a glTF model into one GLB file.
	KindModel Kind = "model"
	// KindManifest generates the Go asset manifest.
	KindManifest Kind = "manifest"
)
type Report struct {
	Targets []Target
}

Report lists every target of a build in the order it ran: atlases, textures, audio, fonts and models in their game.yaml order, the manifest last.

func (r *Report) Count(s Status) int

Count returns how many targets in r have status s.

type Status string

Status is what a build did with a target.

const (
	// Built means the target's outputs were written.
	Built Status = "built"
	// UpToDate means the target's inputs, settings and outputs matched the cache, so nothing was written.
	UpToDate Status = "up to date"
	// Stale means a check found the target out of date; nothing was written.
	Stale Status = "stale"
)
type Target struct {
	// ID names the target: its kind and its output, such as "atlas assets/atlases/ui" or "texture assets/albedo.ktx2".
	ID string
	// Kind is the sort of work the target does.
	Kind Kind
	// Status is what the build did with it.
	Status Status
	// Outputs are the slash-separated paths, relative to the project directory, of the files the target wrote or would write, sorted; when Status is Stale they are the outputs of the previous build, if any.
	Outputs []string
}

Target is one target's outcome in a Report.