storecapture

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: 25 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 storecapture is experimental: its API and documented formats may change in a minor release; see https://nsgo.games/docs/stability/.

Package storecapture reads a store capture plan, the YAML file (store/capture.yaml by default) that says which scene, input recording and frame make each store screenshot and cover and at which store sizes, renders each shot deterministically through gamedebug.StartMovie, and checks the resulting PNGs against their target sizes and aspect ratios.

Index

Examples

Constants

View Source
const DefaultMediaDir = "store/media"

DefaultMediaDir is the default media output directory relative to a project root.

View Source
const DefaultPlanPath = "store/capture.yaml"

DefaultPlanPath is the default store capture plan path relative to a project root.

View Source
const GalleryShot = "gallery"

GalleryShot is the name of the shot that captures a project template's gallery cover. It is held to the gallery rules: exactly one size, GalleryLandscape or GalleryPortrait, and a frame that is not blank.

View Source
const Version = 1

Version is the plan format version this package reads and writes.

Variables

View Source
var (
	GalleryLandscape = Size{Width: 1280, Height: 720}
	GalleryPortrait  = Size{Width: 720, Height: 1280}
)

GalleryLandscape and GalleryPortrait are the sizes a gallery cover may have: 1280x720 for a landscape template, or one laid out for any orientation, and 720x1280 for a portrait one.

View Source
var ErrRunEnded = errors.New("the run ended")

ErrRunEnded is what a StepFunc returns, or wraps, when the game's run ends before the shot's frame: Render then fails the shot with the step the run ended at and the frame it declared.

Functions

func Check

func Check(p Plan, project, media string) error

Check validates the plan and verifies its inputs and images: every shot's scene and recording exist under the project directory, every image exists under the media directory as a PNG of its target size, and the GalleryShot's image is not blank. It returns every problem found, joined, or nil.

func CheckGalleryPNG

func CheckGalleryPNG(data []byte, name string) error

CheckGalleryPNG reports whether data, named name in its errors, is a gallery cover: a PNG of GalleryLandscape or GalleryPortrait that is not blank.

func Presets

func Presets() map[string]Size

Presets returns a copy of the named store sizes a target may use.

func Render

func Render(ctx context.Context, plan Plan, out string, opts ...RenderOption) error

Render runs each shot of plan in deterministic fixed-step mode through gamedebug.StartMovie, validates every rendered image against its target size and aspect ratio, and writes the PNGs under out.

func ValidateCover

func ValidateCover(size Size) error

ValidateCover reports whether size meets the 16:9 store cover minimum: at least 960x540 pixels and within 5% of a 16:9 aspect ratio.

Types

type CaptureFunc

type CaptureFunc func(ctx context.Context, shot Shot, size Size, scene *sceneformat.BuiltScene, step int) ([]byte, error)

CaptureFunc renders the current scene state for shot at size and returns a PNG image.

type Image

type Image struct {
	// Shot is the shot's name.
	Shot string
	// Path is the file's path relative to the media directory, in slash form.
	Path string
	// Size is the size the file must have.
	Size Size
}

Image is one file a plan describes: a shot at one of its sizes.

type Plan

type Plan struct {
	// Version is the format version, always Version.
	Version int `yaml:"version"`
	// Shots are the plan's images in the order they are captured.
	Shots []Shot `yaml:"shots"`
}

Plan is a store capture plan.

func Decode

func Decode(data []byte) (*Plan, error)

Decode parses and validates a plan, refusing unknown fields and more than one YAML document. Its errors are *loaderr.Error values naming the line and field.

func LoadFile

func LoadFile(path string) (*Plan, error)

LoadFile reads and decodes the plan at path, naming the file in its errors.

func (*Plan) Encode

func (p *Plan) Encode() ([]byte, error)

Encode validates the plan and returns it as YAML with two-space indentation and fields in a fixed order, so a decoded plan encodes back to the same bytes.

func (Plan) FilterShot

func (p Plan) FilterShot(name string) (Plan, error)

FilterShot returns a copy of p containing only the shot named name, or all shots when name is empty. It returns an error when name is non-empty and does not match any shot in p.

func (*Plan) Images

func (p *Plan) Images() []Image

Images returns the files the plan describes, shot by shot in plan order and each shot's sizes in order. The plan must be valid.

Example

Decode reads a store capture plan; Images names every PNG the plan describes, with the size each store slot expects.

package main

import (
	"fmt"

	"github.com/nsgo-dev/game/pkg/tooling/storecapture"
)

func main() {
	plan, err := storecapture.Decode([]byte(`version: 1
shots:
  - name: title
    scene: scenes/title.scene.yaml
    frame: 30
    output: title
    sizes:
      - preset: itch_cover
`))
	if err != nil {
		fmt.Println(err)
		return
	}
	images := plan.Images()
	fmt.Println(len(images), images[0].Path, images[0].Size.Width, images[0].Size.Height)
}
Output:
1 title-630x500.png 630 500

func (*Plan) Validate

func (p *Plan) Validate() error

Validate reports the first problem with the plan as a *loaderr.Error naming its field: an unsupported version, no shots, or a shot with a missing or duplicate name, a scene, recording or output outside the project, both a frame and a time, a negative capture point, no sizes or an invalid size, two images with the same file, or a GalleryShot with other than one size of GalleryLandscape or GalleryPortrait.

type RenderOption

type RenderOption func(*renderConfig)

RenderOption configures Render.

func WithAssets

func WithAssets(assets sceneformat.AssetResolver) RenderOption

WithAssets sets the AssetResolver passed to sceneformat.Build when loading each shot's scene. When nil, Render reads project files and in-memory PNG/JPEG images from ProjectDir.

func WithCapture

func WithCapture(fn CaptureFunc) RenderOption

WithCapture overrides the frame rasterizer used on the capture frame of each shot. The returned bytes are still checked to be a valid PNG matching the target's exact size and aspect ratio.

func WithProjectDir

func WithProjectDir(dir string) RenderOption

WithProjectDir sets the project directory used to resolve shot scene and recording paths. When omitted, Render resolves paths relative to the current directory (".").

func WithStepFunc

func WithStepFunc(fn StepFunc) RenderOption

WithStepFunc attaches a callback invoked on each fixed simulation step after the optional replay.Player and BuiltScene have advanced.

func WithStepRate

func WithStepRate(hz int) RenderOption

WithStepRate sets the fixed-step simulation rate in Hz for shots without an input recording. Shots with a .replay.yaml recording always use the recording's own rate (default 60 Hz).

type RunOptions

type RunOptions struct {
	// ProjectDir is the project root directory (defaults to ".").
	ProjectDir string
	// PlanPath is the capture plan YAML path, relative to ProjectDir unless absolute (defaults to DefaultPlanPath).
	PlanPath string
	// OutDir is the output media directory, relative to ProjectDir unless absolute (defaults to DefaultMediaDir).
	OutDir string
	// ShotName, when non-empty, restricts the run to the single shot of that name.
	ShotName string
	// CheckOnly verifies existing images against the plan with Check without rendering them.
	CheckOnly bool
	// RenderOptions are passed to Render when CheckOnly is false.
	RenderOptions []RenderOption
}

RunOptions configures Run, the shared entry point behind `go tool game capture` and the editor's Build and Release screen "Capture store media" action.

type RunResult

type RunResult struct {
	PlanPath string
	OutDir   string
	Images   []Image
	Rendered bool
}

RunResult summarizes a completed Run call.

func Run

func Run(ctx context.Context, opts RunOptions) (RunResult, error)

Run loads a project's capture plan, optionally filters it to opts.ShotName, renders every shot in deterministic fixed-step mode (unless opts.CheckOnly is set), and checks the resulting images against the plan. Both `go tool game capture` and the editor's "Capture store media" action call Run.

type Shot

type Shot struct {
	// Name identifies the shot, unique within the plan.
	Name string `yaml:"name"`
	// Scene is the scene file to capture, relative to the project, in slash form.
	Scene string `yaml:"scene"`
	// Recording is an optional .replay.yaml input recording played before the capture, relative to the project, in slash form.
	Recording string `yaml:"recording,omitempty"`
	// Frame is the fixed-step frame to capture; at most one of Frame and Time is set, and neither means the first frame.
	Frame *int `yaml:"frame,omitempty"`
	// Time is the fixed-step time in seconds to capture.
	Time *float64 `yaml:"time,omitempty"`
	// Output is the image name relative to the media directory, in slash form and without the size suffix: each target is written to <output>-<width>x<height>.png.
	Output string `yaml:"output"`
	// Sizes are the sizes the shot is delivered at.
	Sizes []Target `yaml:"sizes"`
}

Shot is one store image: what to capture and the sizes to deliver it at.

type Size

type Size struct {
	Width  int
	Height int
}

Size is an image's pixel dimensions.

type StepFunc

type StepFunc func(shot Shot, step int, dt time.Duration, scene *sceneformat.BuiltScene, input replay.ActionSource) error

StepFunc runs once per fixed simulation step inside Render, after the optional replay.Player and sceneformat.BuiltScene have stepped. It returns an error wrapping ErrRunEnded when the game's run is over, such as on a game over screen, so a shot whose frame comes later fails instead of capturing it.

type Target

type Target struct {
	// Preset names one of Presets.
	Preset string `yaml:"preset,omitempty"`
	// Width and Height are an explicit size in pixels.
	Width  int `yaml:"width,omitempty"`
	Height int `yaml:"height,omitempty"`
}

Target is one size a shot is wanted at: a named preset, or an explicit width and height, never both.

func (Target) Resolve

func (t Target) Resolve() (Size, error)

Resolve returns the target's size.

Jump to

Keyboard shortcuts

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