Documentation
¶
Overview ¶
Package templatemeta is experimental: its API and documented formats may change in a minor release; see https://nsgo.games/docs/stability/.
Package templatemeta 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.
Index ¶
Examples ¶
Constants ¶
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.
Variables ¶
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.
Functions ¶
func CoverSize ¶
func CoverSize(m Manifest) storecapture.Size
CoverSize returns the size m's gallery cover must have: 720x1280 for a portrait template, and 1280x720 for one laid out for landscape or any orientation.
func Encode ¶
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.
Types ¶
type Manifest ¶
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 `` /* 182-byte string literal not displayed */
// 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"`
// CompatiblePacks lists library pack names compatible with projects created from this template, such as cc0-adventurers.
CompatiblePacks []string `yaml:"compatiblePacks,omitempty,flow" json:"compatiblePacks,omitempty"`
// Cover is the path of the gallery cover, a PNG of CoverSize relative to the template's directory, in slash form.
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 ¶
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.
Example ¶
ExampleParse reads a template manifest, writes it back unchanged and reports where an invalid value is.
package main
import (
"bytes"
"fmt"
"strings"
"github.com/nsgo-dev/game/pkg/loaderr"
"github.com/nsgo-dev/game/pkg/tooling/templatemeta"
)
const manifestYAML = `# yaml-language-server: $schema=https://nsgo.games/schemas/template.v1.json
version: 1
id: puzzle2d
title:
en: Puzzle
zh: 解谜
summary:
en: Slide a spark to light every lamp
genre: puzzle
dimension: 2d
orientation: portrait
players:
min: 1
max: 1
inputs: [keyboard, touch]
tags: [puzzle, grid]
`
// ExampleParse reads a template manifest, writes it back unchanged and reports where an invalid value is.
func main() {
m, err := templatemeta.Parse([]byte(manifestYAML))
if err != nil {
fmt.Println(err)
return
}
fmt.Println(m.ID, m.Genre, m.Dimension, m.Orientation)
fmt.Println(m.TitleFor("zh"), m.TitleFor("ja"))
fmt.Println("players:", m.Players.Min, m.Players.Max, "inputs:", strings.Join(m.Inputs, ","))
out, err := templatemeta.Encode(m)
fmt.Println("round trip unchanged:", err == nil && bytes.Equal(out, []byte(manifestYAML)))
bad := strings.Replace(manifestYAML, "genre: puzzle", "genre: sports", 1)
_, err = templatemeta.Parse([]byte(bad))
if e, ok := loaderr.As(err); ok {
fmt.Printf("line %d %s: %s\n", e.Line, e.Field, e.Problem)
}
}
Output: puzzle2d puzzle 2d portrait 解谜 Puzzle players: 1 1 inputs: keyboard,touch round trip unchanged: true line 9 genre: templatemeta: unknown genre "sports"
func (Manifest) ControlsFor ¶
ControlsFor returns the controls text for locale lang (matching exact tag, lowercase tag, or primary language subtag), or the en controls text when the manifest has none for lang.
func (Manifest) SummaryFor ¶
SummaryFor returns the summary for locale lang (matching exact tag, lowercase tag, or primary language subtag), or the en summary when the manifest has none for lang.
type Players ¶
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.