API 参考取自源码中的 Go 文档注释,以英文书写。
package credits
import "github.com/nsgo-dev/game/pkg/tooling/credits"概述
Package credits lists who made each of a game's assets and under what license, from the credit section of the import settings sidecar beside each one (package importsettings), and writes the list as the credits file a release ships with.
Assets returns the assets game.yaml's assets section (package project) reaches: the images each atlas packs, the image of each texture target, the sound of each audio target, and every file in the manifest's folder that the manifest lists, except the files the targets write, which are made from those inputs. Collect reads each one's sidecar and returns its credit, with a *MissingError naming every asset that has no sidecar or a sidecar without a credit. Markdown writes the entries as FileName, CREDITS.md: a table of each asset's author, license and source, a count of the assets under each license, and each notice a license requires to be shipped, word for word.
game release writes the file beside the packages it builds, and refuses to build when an asset has no credit; game credits writes or prints it on its own.
索引
常量
const FileName = "CREDITS.md"FileName is the name of the credits file game release writes beside a release's packages.
函数
func Assets(root string, a *project.Assets) ([]string, error)Assets returns the slash-separated paths, relative to root, of the assets a reaches, sorted: the PNG images each atlas packs, the input of each texture, audio, font and model target, the buffers and images each model names by relative path (assetbuild.ModelFiles), which its GLB embeds, and every file the manifest lists in its folder, leaving out what a target writes (Assets.IsOutput), since that is made from the targets' inputs. A file a target wrote before its output changed counts as an asset until game assets removes it. A nil a reaches none. It fails when an input a target names is missing; a manifest folder that is not there yet holds no asset.
func Markdown(entries []Entry) []byteMarkdown writes entries as the credits file, sorted by asset: a table of each asset's author, license and source, a table of how many assets each license covers, linking each single SPDX identifier to its page in the SPDX license list, and each asset's notice word for word in a fenced block. The output depends only on entries, so the same credits always give the same bytes.
func Write(dir string, entries []Entry) (string, error)Write writes the credits file of entries, as Markdown makes it, to FileName in dir, creating dir when it is missing, and returns the file's path.
类型
type Entry struct {
// Asset is the asset's slash-separated path relative to the project root.
Asset string
// Credit is the credit section of the asset's import settings sidecar.
Credit importsettings.Credit
}Entry is one asset and its credit.
func Collect(root string, a *project.Assets) ([]Entry, error)Collect returns the credit of every asset Assets returns, in its order, read from the credit section of the import settings sidecar beside each one (or a generated asset's *.source.yaml sidecar when its license is known). It also checks every *.source.yaml sidecar under root and fails with *UnknownLicenseError if any generated asset has an unknown or empty license. A sidecar counts only under exactly its asset's name and the suffix, so a case-insensitive file system, which would open Hero.PNG.import.yaml for hero.png, credits the same assets as a case-sensitive one. When some assets have none, it returns the entries of the others with a *MissingError naming them; a sidecar that fails to parse is an error of its own.
type GeneratedAssetLicense struct {
// Asset is the generated asset's slash-separated path relative to the project root.
Asset string
// SourcePath is the slash-separated path of the asset's *.source.yaml sidecar relative to the project root.
SourcePath string
// Generator is the MCP generator server name recorded in the sidecar.
Generator string
// Model is the model identifier recorded in the sidecar, if any.
Model string
// License is the license string recorded in the sidecar (possibly empty or "unknown").
License string
// CommercialUse reports whether the sidecar allows commercial use.
CommercialUse bool
// ApprovedBy names the person who approved the pick, if recorded.
ApprovedBy string
// UnknownLicense reports whether License is empty or unknown and therefore blocks release builds.
UnknownLicense bool
}GeneratedAssetLicense summarizes the provenance and license recorded in one generated asset's *.source.yaml sidecar.
func CheckGeneratedLicenses(root string) ([]GeneratedAssetLicense, error)CheckGeneratedLicenses scans every *.source.yaml sidecar under root and fails with *UnknownLicenseError when any generated asset has an empty or unknown license, naming every blocked asset path.
func ScanGeneratedLicenses(root string) ([]GeneratedAssetLicense, error)ScanGeneratedLicenses walks root and reads every generated asset's *.source.yaml sidecar in deterministic path order, skipping dot-prefixed directories, node_modules, and vendor. A malformed *.source.yaml returns an error naming its relative path.
type MissingError struct {
// Assets are the uncredited assets' slash-separated paths, sorted.
Assets []string
}MissingError is returned by Collect when some assets have no credit: no import settings sidecar, or one without a credit section.
func (e *MissingError) Error() stringError names every uncredited asset and the sidecar that would credit it.
type UnknownLicenseError struct {
// Assets are the slash-separated paths of generated assets whose license is unknown, sorted.
Assets []string
}UnknownLicenseError is returned by CheckGeneratedLicenses and Collect when one or more generated assets (*.source.yaml) have an empty or unknown license.
func (e *UnknownLicenseError) Error() stringError names every generated asset whose unknown license blocks a release build.