templatemeta

package
v0.4.0-rc.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const File = "template.yaml"

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

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

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

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

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

View Source
const Version = 1

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

Variables

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

Dimensions are the values a manifest's dimension takes.

View Source
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.

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

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

View Source
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

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 ReadCover

func ReadCover(m Manifest, files fs.FS) ([]byte, error)

ReadCover returns the gallery cover m declares, read from files, the template's directory, after checking that it is a PNG of CoverSize(m) that is not blank. It returns nil and no error when m declares no cover.

func Validate

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.

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

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.

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

func (m Manifest) ControlsFor(lang string) string

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

func (m Manifest) SummaryFor(lang string) string

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.

func (Manifest) TitleFor

func (m Manifest) TitleFor(lang string) string

TitleFor returns the title for locale lang (matching exact tag, lowercase tag, or primary language subtag), or the en title 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL