Documentation
¶
Overview ¶
Package pet reads and draws petdex pets: small animated companions kept as a folder holding a pet.json and a sheet of frames, one row of cells for each state a pet is shown in, as petdex.dev publishes them and as /hatch makes them
Index ¶
- Constants
- Variables
- func Blank(img *image.NRGBA) bool
- func Cells(frame *image.NRGBA, cols int) [][]Cell
- func Clamp(scale float64) float64
- func Cols(scale float64, set int) int
- func Direction(dx, dy float64) int
- func Fit(frames []*image.NRGBA, box image.Rectangle, w, h int) []*image.NRGBA
- func Fond(text string) bool
- func Hosted(address, index string) bool
- func Layout(rows int) []string
- func NRGBA(src image.Image) *image.NRGBA
- func Opaque(img *image.NRGBA) image.Rectangle
- func Row(state State, rows int) int
- func Scaled(box image.Rectangle, scale float64) (w, h int)
- func SheetExt(address string) string
- func Slug(title string) string
- func TitleOf(words string) string
- func Turn(from, to int) int
- func Unique(name string, taken func(name string) bool) string
- func Valid(name string) bool
- func Zipped(data []byte) bool
- type Broken
- type Cell
- type Entry
- type Folder
- func (f Folder) Add(name string, manifest Manifest, sheet []byte, ext string) (Pet, error)
- func (f Folder) Export(name string) ([]byte, error)
- func (f Folder) List() ([]Pet, []Broken, error)
- func (f Folder) Load(name string) (Pet, error)
- func (f Folder) Move(name string, into Folder, to string) error
- func (f Folder) Remove(name string) (bool, error)
- func (f Folder) Retitle(name, title string) error
- type Manifest
- func (m Manifest) CreatedBy() string
- func (m Manifest) Description() string
- func (m Manifest) DisplayName() string
- func (m Manifest) ID() string
- func (m Manifest) JSON() ([]byte, error)
- func (m Manifest) Named(name, title, sheet, maker string) Manifest
- func (m Manifest) Sheet() string
- func (m Manifest) With(key string, value any) Manifest
- type Pet
- type Sheet
- func (s *Sheet) Bounds() image.Rectangle
- func (s *Sheet) CanLook() bool
- func (s *Sheet) Check() error
- func (s *Sheet) Counts() map[string]int
- func (s *Sheet) Frames(state State) []*image.NRGBA
- func (s *Sheet) Layout() []string
- func (s *Sheet) Looks() []*image.NRGBA
- func (s *Sheet) Size() (cols, rows int)
- type Signals
- type State
Constants ¶
const ( FrameW = 192 FrameH = 208 )
Pixels of one cell of a sheet
const ( MinScale = 0.1 MaxScale = 3.0 DefaultScale = 0.33 )
How big a pet is drawn, as a share of the pixels of its sheet: the least, the most and the size it has unless a person sets another
const ( Directions = 16 Rest = 8 Front = Directions )
Ways a pet of the second layout looks: 0 up, then on clockwise in steps of 22.5 degrees (4 right, 8 down, 12 left), the frames of rows 9 and 10 of its sheet in that order; the way its head turns back to, down toward the person, before it faces front; and the frame of Look that faces front, the neutral frame in row 0, column 6 of the sheet, which a sheet may leave blank
const Beat = 1600 * time.Millisecond
How long a pet shows how something that just happened went, such as a reply that ended, before it goes back to what it does
const Frame = 160 * time.Millisecond
Time one frame of an animation is shown before the next
const Generator = "generator"
What createdBy says of a pet that /hatch made
const Index = "https://petdex.dev/api/manifest"
Address of the index of the pets petdex.dev publishes, read whole with one request
const ManifestName = "pet.json"
File of a pet's folder that says what the pet is
const (
MinCols = 16
)
Columns a pet drawn in text blocks takes at least, and those its full size takes: one for every eight pixels of a cell
const VersionField = "spriteVersionNumber"
Field of pet.json that says which layout of petdex the sheet is of, 2 for the second, whose pet looks around
Variables ¶
var ( Rows = []string{"idle", "running-right", "running-left", "waving", "jumping", "failed", "waiting", "running", "review"} LookRows = []string{"look-1-8", "look-9-16"} EightRows = []string{"idle", "wave", "run", "failed", "review", "jump", "extra1", "extra2"} )
Rows of a sheet of nine rows, the first layout of petdex; the two rows a sheet of eleven adds, its second layout (spriteVersionNumber 2), which hold the sixteen ways the pet looks, Directions in their order, with the neutral frame facing front in row 0, column 6; and the rows of a sheet of eight, the layout of older pets
var ErrNoPet = errors.New("no such pet")
No pet of the name is in the folder
Every state a pet is shown in, in the order a preview goes through them
Functions ¶
func Cells ¶
Rows of a frame drawn in text blocks cols cells wide, as many rows as keep its shape with each cell two pixels high
func Cols ¶
Columns a pet drawn in text blocks takes: those set when any are, else those the size gives, never fewer than the least
func Direction ¶
Direction of a vector of the screen in pixels, x to the right and y down, among the ways a pet looks
func Hosted ¶
Whether the address is of the host the index is on or one below it, the only hosts a pet of the index is fetched from
func Layout ¶
Layout of a sheet of so many rows: the eleven of the second layout of petdex for eleven or more, its nine for nine or ten, the older eight otherwise
func Opaque ¶
Smallest box holding every pixel of the picture that is not empty, empty for a blank one
func Row ¶
Row of a sheet of so many rows that holds the state, the idle row when the sheet has none for it
func Scaled ¶
Pixels across and down a pet whose frames fill the box is drawn at, at the size given: at least one each way
func SheetExt ¶
Extension the sheet at the address is kept under: .png for an address whose path ends so, .gif for one that ends so, else .webp
func Slug ¶
Name of a folder for a pet of the title: lower case letters and digits, every run of anything else a dash; pet for a title with none
func TitleOf ¶
Short title of a pet a person described: the first three words of the words, each capitalized, 28 characters at most; empty for none
Types ¶
type Broken ¶
type Broken struct {
Name, Dir, Why string
}
A pet folder of a folder that holds no usable pet, and why
type Cell ¶
One cell of a pet drawn in text blocks: the pixel of its upper half and the one of its lower half
type Entry ¶
type Entry struct {
// Name of the pet's folder once installed, and what a person calls it
Name, Title string
// Kind of thing it is, pet for most, and who sent it in
Kind, By string
// Addresses of its sheet, of its pet.json and of a zip of its whole folder; the sheet's is always there
Sheet, Manifest, Zip string
}
One pet of the index
func ParseIndex ¶
Pets of an index: {"pets": [{"slug", "displayName", "kind", "submittedBy", "spritesheetUrl", "petJsonUrl", "zipUrl"}]}, other fields read past, those with no slug or no sheet left out, and stand-ins that show the sheet of another pet; an error for text that holds no list of pets
type Folder ¶
type Folder string
A folder holding pets, each in a folder of its own named by the pet
func (Folder) Add ¶
Puts a pet into the folder under the name, in place of one of that name: its sheet as a file of the extension given and its pet.json naming that file. Written beside the folder first and moved in at once, so a pet is never seen half written
func (Folder) Export ¶
The pet of the name as a zip holding its folder, as petdex hands pets out: every file of the folder but those whose name starts with a dot, under a folder of the pet's name
func (Folder) List ¶
The pets of the folder by name, and the pet folders in it that hold none that can be used; no pets for a folder that is not there
func (Folder) Load ¶
The pet of the name, ErrNoPet when the folder holds no pet folder of that name; a pet whose pet.json does not read or whose sheet is missing is an error that says so
func (Folder) Move ¶
Moves the pet of the name into another folder of pets under a new name, its pet.json saying the new one
type Manifest ¶
type Manifest struct {
// contains filtered or unexported fields
}
What pet.json says of a pet, every field it holds kept in the order it was written
func NewManifest ¶
Manifest of a new pet: its name, its title, what it is and its sheet's file
func ReadManifest ¶
Manifest the text of a pet.json holds, a byte order mark before it allowed
func Unpack ¶
The pet a zip holds, as petdex hands pets out and Export writes them: its pet.json, its sheet and the extension of the sheet's file. The sheet is the file pet.json names, else one of the usual names, else the only picture of the zip; files are read from the folder that holds pet.json, or from the top
func (Manifest) Description ¶
func (Manifest) DisplayName ¶
func (Manifest) JSON ¶
Text of pet.json, indented by two and every character past ASCII escaped, as petdex writes it
type Pet ¶
type Pet struct {
// Name of its folder, which names it everywhere
Name string
// What a person calls it, its name when pet.json gives none, and what it is
Title, About string
Dir string
// File of its sheet
Sheet string
Manifest Manifest
}
One pet of a folder
type Sheet ¶
type Sheet struct {
// contains filtered or unexported fields
}
A sheet of a pet decoded: its cells of FrameW by FrameH pixels, one row for each state
func Decode ¶
Sheet of the bytes of a WebP, PNG, GIF or JPEG file: an error for bytes that are no picture, or a picture smaller than one cell or larger than a sheet of a pet is
func (*Sheet) Bounds ¶
Smallest box holding every pixel that is not empty of every frame of every state the sheet draws, in the pixels of one cell; the whole cell for a sheet with none
func (*Sheet) Check ¶
Problem of a sheet a pet can't be drawn from: one whose idle row is blank; nil for a sheet that draws
func (*Sheet) Frames ¶
Frames the state is drawn with: those of its row, the first of idle alone for asleep, the ways it looks for Look; none for a sheet whose row is blank
type Signals ¶
type Signals struct {
// A reply is under way, it waits on the person for an approval or an answer, it runs a tool, it thinks before it writes
Busy, Waiting, Tool, Thinking bool
// When a reply last ended well, when one failed, when the person last wrote something fond to it and when anything last happened in
// it; zero for never
Ended, Failed, Cheered, Last time.Time
// The reply that ended last left every task of its list done
Finished bool
}
What moves a pet: what the session it watches is doing, and when things last happened in it
type State ¶
type State string
What a pet is shown doing
const ( Idle State = "idle" Wave State = "wave" Run State = "run" Failed State = "failed" Review State = "review" Jump State = "jump" Waiting State = "waiting" // Nothing happened for a while: the first frame of idle, held still Asleep State = "asleep" // The head turned toward something, one frame for each way it looks, the frame facing front last: what a pet of the second layout of // petdex does at rest while something is worth a look Look State = "look" )
Directories
¶
| Path | Synopsis |
|---|---|
|
Package hatch makes a pet from words: first looks drawn by an image model, the look picked drawn again as a strip of poses for each state, each strip cut into frames, the frames put on one scale and one baseline, and the sheet of petdex composed and checked
|
Package hatch makes a pet from words: first looks drawn by an image model, the look picked drawn again as a strip of poses for each state, each strip cut into frames, the frames put on one scale and one baseline, and the sheet of petdex composed and checked |