sheetfile

package
v0.0.0-...-94fff03 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 5 Imported by: 1 module, 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 sheetfile is the grid sheet format, *.sheet.json: fixed-size cells over one image (doc/guide/engine/asset-kinds.md#grid-sheet). The atlas loader in package render and the sheet tool of wpix-editor both use it, so the tool shows exactly the frames the loader makes. It imports the standard library only.

Index

Constants

View Source
const Suffix = ".sheet.json"

Suffix is the file name suffix of a grid sheet.

Variables

This section is empty.

Functions

func Encode

func Encode(f *File) ([]byte, error)

Encode returns the canonical text of f: two-space indent, zero margin and spacing left out, a trailing newline. It does not validate, so a tool can write a state that is still being edited; Decode does.

Types

type File

type File struct {
	// Image is the texture, relative to the sheet's folder.
	Image string `json:"image"`
	// FrameW and FrameH are the size of one cell in pixels, at least 1.
	FrameW int `json:"frameW"`
	FrameH int `json:"frameH"`
	// Margin is the border around the grid in pixels, Spacing the gap
	// between cells; neither is negative.
	Margin  int `json:"margin,omitempty"`
	Spacing int `json:"spacing,omitempty"`
	// Pivot is nil for the default pivot.
	Pivot *Pivot `json:"pivot,omitempty"`
}

File is a grid sheet. Frames are named "0", "1", ... left to right, top to bottom.

func Decode

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

Decode parses the text of a sheet and checks it with File.Validate. All problems of a well-formed file are reported together.

func Starter

func Starter(image string, size image.Point) *File

Starter returns the sheet a new sheet tool starts from: 16 pixel cells, or the whole image when it is smaller, no margin and no spacing.

func (*File) Equal

func (f *File) Equal(o *File) bool

Equal reports whether a and b encode to the same text.

func (*File) Layout

func (f *File) Layout(size image.Point) Grid

Layout cuts an image of the given size by f: as many whole cells as fit inside the margin on both sides. The file must be valid.

func (*File) Validate

func (f *File) Validate() error

Validate collects every problem of the fields, independent of any image.

type Grid

type Grid struct {
	File *File
	// Cols and Rows are the cells that fit; both are 0 when not even one
	// does.
	Cols, Rows int
	// Size is the image size.
	Size image.Point
}

Grid is the layout of a valid sheet over an image of a given size.

func (Grid) At

func (g Grid) At(p image.Point) (int, bool)

At returns the frame under the image pixel p. It reports false for a pixel in the margin, in the spacing between cells or outside the grid.

func (Grid) Count

func (g Grid) Count() int

Count is the number of frames.

func (Grid) Rect

func (g Grid) Rect(i int) image.Rectangle

Rect is the rectangle of frame i in image pixels; i must be in [0, Count).

func (Grid) Used

func (g Grid) Used() image.Rectangle

Used is the part of the image the grid covers, from the margin to the last cell. Pixels beyond it are leftovers.

type Pivot

type Pivot struct {
	X float32 `json:"x"`
	Y float32 `json:"y"`
}

Pivot is the optional pivot of every frame, as a fraction of the frame.

Jump to

Keyboard shortcuts

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