GitHubはじめる

API リファレンスはソースコード内の Go ドキュメントコメントから生成されており、英語で記述されています。

package templatemeta

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

概要

Package templatemeta is experimental: its API and documented formats may change in a minor release. See the API stability policy. reads and writes template.yaml, the versioned manifest every project template ships beside its files. game new, the editor Start Screen and the editor's templates_list MCP tool read a template's title, summary, genre, dimension, orientation, players and inputs from it instead of keeping their own copies.

目次

定数

const File = "template.yaml"

File is the manifest's file name in a template's directory.

const SchemaComment = "# yaml-language-server: $schema=" + SchemaURL

SchemaComment is the first line Encode writes, which points YAML editors at SchemaURL.

const SchemaURL = "https://nsgo.games/schemas/template.v1.json"

SchemaURL is where the JSON Schema of version 1 is published.

const Version = 1

Version is the only manifest version Parse accepts and Encode writes.

変数

var Dimensions = []string{"2d", "3d"}

Dimensions are the values a manifest's dimension takes.

var Genres = []string{"action", "arcade", "card", "co-op", "fighting", "fps", "idle", "platformer", "puzzle", "racing", "rhythm", "roguelike", "rpg", "rts", "shmup", "starter", "tower-defense", "visual-novel"}

Genres are the values a manifest's genre takes.

var Inputs = []string{"keyboard", "gamepad", "touch", "mouse"}

Inputs are the values a manifest's inputs list holds.

var Orientations = []string{"landscape", "portrait", "any"}

Orientations are the values a manifest's orientation takes.

関数

func Encode(m Manifest) ([]byte, error)

Encode validates m and writes it as canonical YAML: SchemaComment, then the fields in the order of Manifest with map keys sorted, so that Parse followed by Encode gives back the bytes of a canonical file.

func Validate(m Manifest) error

Validate reports the first field of m that a version 1 manifest does not allow, as a *loaderr.Error naming the field.

型

type Manifest struct {
	// Version is the manifest format version, 1.
	Version int `yaml:"version" json:"version" schema:"required"`
	// ID is the template's name, the value game new -template takes.
	ID string `yaml:"id" json:"id" schema:"required"`
	// Title is the template's display title per locale code; en is required.
	Title map[string]string `yaml:"title" json:"title" schema:"required"`
	// Summary is the one-line description per locale code that game new -list prints and the Start Screen shows; en is required.
	Summary map[string]string `yaml:"summary" json:"summary" schema:"required"`
	// Genre is one of Genres.
	Genre string `yaml:"genre" json:"genre" schema:"required,enum=action|arcade|card|co-op|fighting|fps|idle|platformer|puzzle|racing|rhythm|roguelike|rpg|rts|shmup|starter|tower-defense|visual-novel"`
	// Dimension is 2d or 3d.
	Dimension string `yaml:"dimension" json:"dimension" schema:"required,enum=2d|3d"`
	// Orientation is the screen orientation the game is laid out for: landscape, portrait or any.
	Orientation string `yaml:"orientation" json:"orientation" schema:"required,enum=landscape|portrait|any"`
	// Players says how many people play and whether locally or online.
	Players Players `yaml:"players" json:"players" schema:"required"`
	// Inputs are the input devices the game supports, each one of keyboard, gamepad, touch and mouse.
	Inputs []string `yaml:"inputs,omitempty,flow" json:"inputs,omitempty"`
	// Platforms are the platforms the template targets, such as desktop, web and mobile.
	Platforms []string `yaml:"platforms,omitempty,flow" json:"platforms,omitempty"`
	// Controls describes the controls per locale code.
	Controls map[string]string `yaml:"controls,omitempty" json:"controls,omitempty"`
	// Tags are free-form search terms.
	Tags []string `yaml:"tags,omitempty,flow" json:"tags,omitempty"`
	// Cover is the path of the gallery cover image, relative to the template's directory.
	Cover string `yaml:"cover,omitempty" json:"cover,omitempty"`
	// Playtest names the playtest bot profile that plays the template.
	Playtest string `yaml:"playtest,omitempty" json:"playtest,omitempty"`
}

Manifest is a template's template.yaml.

func Parse(data []byte) (Manifest, error)

Parse decodes a version 1 manifest and validates it. Unknown fields, a second YAML document, and values outside the closed vocabularies are refused with a *loaderr.Error that names the field and its line.

func (m Manifest) SummaryFor(lang string) string

SummaryFor returns the summary for locale lang, or the en summary when the manifest has none for lang.

func (m Manifest) TitleFor(lang string) string

TitleFor returns the title for locale lang, or the en title when the manifest has none for lang.

type Players struct {
	// Min is the fewest players the game runs with, at least 1.
	Min int `yaml:"min" json:"min" schema:"required,minimum=1"`
	// Max is the most players the game runs with, at least Min.
	Max int `yaml:"max" json:"max" schema:"required,minimum=1"`
	// Local reports whether several players share one device.
	Local bool `yaml:"local,omitempty" json:"local,omitempty"`
	// Online reports whether players join over the network.
	Online bool `yaml:"online,omitempty" json:"online,omitempty"`
}

Players says how many people play a template's game and how.