API 參考取自原始碼中的 Go 文件註解,以英文撰寫。
package assetcheck
import "github.com/nsgo-dev/game/pkg/tooling/assetcheck"概覽
Package assetcheck checks a game's scene files, Tiled and LDtk maps and sprite atlases, and the references between them, and reports each problem with the file and line that holds it. The game check command runs it, so a broken reference fails in CI instead of when a player reaches the level.
Check walks a directory and reads:
- scenes, files named *.scene.yaml or *.scene.yml, parsed and validated by sceneformat, whose tilemap sources (Tiled .tmj and .tmx maps and LDtk .ldtk projects, with the level they name), YAML tilesets, sprite and tileset atlases and materials must exist and load, whose glTF models (.gltf or .glb) must exist and load with gltf.LoadFS and hold the node or mesh an object names, whose sprite frames and tile IDs must be in their atlases and tilesets, which must resolve with sceneformat.Resolve when they instance or inherit other scenes, and whose connections must name objects of the scene, counting the objects the scenes it instances and inherits bring, and, given the game's component types (Options.Components), events and handlers those objects' components declare;
- YAML tilesets, files named *.tileset.yaml or *.tileset.yml, parsed and validated by tilemap.ParseTileset, whose grid image must exist and be large enough for their columns and tile count, or whose atlas must exist and hold their frames;
- cutscenes, files named *.cutscene.yaml or *.cutscene.yml, parsed and validated by cutscene, whose video or timeline audio sources and scene file must exist, whose actor and camera target object IDs must exist in the referenced scene, and whose dialogue line IDs must exist in the project's localization YAML string tables;
- 3D world files named *.gridmap.yaml/.yml, *.terrain.yaml/.yml and *.foliage.yaml/.yml, parsed and validated by world3d, whose referenced mesh libraries (and their tile names for .gltf libraries), heightmaps, splat maps, layer textures, terrain definitions, foliage meshes, materials and density maps must exist and decode;
- Tiled maps (.tmj) and tilesets (.tsj), whose external tilesets must be JSON tilesets (.tsj or .json) that exist, whose tileset and image-layer images must exist, and which must load with tilemap.LoadTiled;
- LDtk projects (.ldtk), whose tileset images and level backgrounds must exist, whose levels must not be saved in separate files, which tilemap.LoadLDtkAll does not read, and which must load with tilemap.LoadLDtkAll;
- sprite atlases, JSON files with top-level frames and meta objects as TexturePacker and Aseprite write them, whose meta.image must exist, whose frames must lie inside it, and which must load with sprite.LoadAtlas;
- every other reference refs.Scan finds, which must name a file that exists, or a folder for game.yaml's asset inputs that are folders: the scene a scene inherits or an object instances, references in scenes not named *.scene.yaml that a reference names as a scene, a material's texture, the paths game.yaml autoloads and builds assets from, and the rest; what a tool writes, such as an asset target's out, need not exist yet. game.yaml must parse, and so must the project indexes refs reads, with no uid shared by two files of one project.
A reference to a file that is gone says where the file went when the project index (refs.IndexFileName) finds it again (refs.Project.Moved), and that game index updates the reference.
A file a map or tileset names is resolved from that file's directory, as Tiled and LDtk write them. A scene's tilemap source, tileset file and material paths, and a YAML tileset's image, are resolved from its project root, the nearest directory above the scene that holds game.yaml, nsgo.yaml or go.mod, or the checked directory when none does. A scene names an atlas by name, as a sceneformat.AssetResolver resolves it: the name is the path of an atlas JSON file without its .json extension, either from the project root or as the file's base name, and when several atlases in the project match, the one nearest the scene, counting the directories up from the scene and down to the atlas, wins. A JSON file of that name that does not parse, or is not an atlas, is reported when a scene names it. PNG, JPEG and GIF images must also decode; other images only have to exist.
Directories whose names start with "." or "_", and those named testdata, are skipped, as the go command skips them.
索引
型別
type Options struct {
// Components, when non-nil, are the game's component types, whose events and handlers a scene's connections name: every object's components are checked against them, as sceneformat.ParseWith checks them, and so is every connection, so a connection naming an event or handler its object does not declare, or a handler argument it does not take, is a Problem at the line that names it. In a scene that instances or inherits other scenes, the components its overrides write and every connection of the resolved scene are checked too, and an override that breaks a connection the other scenes bring is a Problem at the override; a fault a scene brings unchanged from another file is reported on that file only. Nil checks a connection's objects only, since the command line cannot know the types a game registers in Go.
Components *sceneformat.ComponentRegistry
}Options configures CheckWith.
type Problem struct {
// File is the slash-separated path of the file at fault, relative to the checked directory.
File string
// Line is the 1-based line of the file that holds the problem, or 0 when the problem is about the whole file, such as a loader error that names no place in it.
Line int
// Column is the 1-based column on Line where the scene or YAML format knows it, or 0 when unknown.
Column int
// Object is the ID of the scene object the problem names or belongs to when known, or "" for file-wide or non-scene problems.
Object string
// Message says what is wrong.
Message string
}Problem is one thing wrong with a file Check read.
func (p Problem) Location() stringLocation formats p's source position as "file:line:column" when both Line and Column are known, "file:line" when only Line is known, or "file" otherwise.
func (p Problem) String() stringString formats p as "file:line: message", or "file: message" when it has no line, as compilers and go vet print theirs.
type Report struct {
// Scenes, Maps, Tilesets and Atlases count the files of each kind that were checked: scene files, Tiled and LDtk maps, Tiled and YAML tilesets, and sprite atlases.
Scenes, Maps, Tilesets, Atlases int
// GridMaps, Terrains and Foliage count the 3D world YAML files that were checked: *.gridmap.yaml, *.terrain.yaml and *.foliage.yaml.
GridMaps, Terrains, Foliage int
// Cutscenes counts the *.cutscene.yaml / *.cutscene.yml files that were checked.
Cutscenes int
// Screens counts the gameui *.screen.yaml / *.screen.yml files that were checked.
Screens int
// States counts the sprite animation state machine YAML files (*.states.yaml) that were checked.
States int
// Problems are the problems found, sorted by file, then line, then message.
Problems []Problem
}Report is what Check found.
func Check(fsys fs.FS) (*Report, error)Check is CheckWith without Options: it checks that every connection names objects that exist, but not their events and handlers.
func CheckWith(fsys fs.FS, opts Options) (*Report, error)CheckWith walks fsys, such as os.DirFS of a game's directory, checks every scene, map, tileset and atlas in it as the package comment describes, and returns what it found. It returns an error only when fsys's root cannot be read; a file it cannot read or parse is a Problem.
func (r *Report) Summary() stringSummary returns a line counting the files checked and the problems found, such as "1 scene, 2 maps, 0 tilesets, 1 atlas: 3 problems".