pet

package module
v0.0.0-...-d2fd653 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 24 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 pet plays desktop pets on NSGo: a pack's clips, chosen by its rules in Big Blue Fish's format, in a window of the pet's own or in a view of the host's. It ships no pets: the host loads its packs with Load or LoadDir, and owns the windows, menus and lifecycle around them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Season

func Season(t time.Time) string

Season is the northern season of t's month.

func WindowOptions

func WindowOptions(pack *Pack) desktop.WindowOptions

WindowOptions are those of a window for pack's pet, for desktop.OpenWindow to open with Options.Window: its size, transparent, without a shadow or a taskbar entry, on every workspace and taking the pointer only where it draws.

Types

type ClipView

type ClipView struct {
	Pack *Pack
	// Clip is the clip's ID, as Play takes, such as Pack.Clips.Idle.
	Clip   string
	Class  string
	Style  core.Style
	TestID string
}

ClipView plays one of a pack's clips over and over, muted and contained in its box, as a host's list of pets previews each: in a core.Video, or on Windows in the engine's own decoder, as the pet plays its clips there. A clip the pack lacks shows nothing.

func (ClipView) Render

func (v ClipView) Render(cx *core.Scope) core.Node

Render implements core.Node.

type Context

type Context struct {
	Now     time.Time
	Coding  bool
	Working bool
}

Context is what weights depend on besides the rules: the local time and what the user is doing.

type Options

type Options struct {
	// Window says the pet's scope is a window of its own, sized to the pet, as WindowOptions opens one: Start floats it above the other windows on every workspace and lets the pointer through outside the pet's body, walking clips and drags move it, and PlaceAtCorner puts it on the bottom right of the screen. Without it the pet is a view of its size in the host's layout, which plays every clip where it is.
	Window bool
	// Menu is what a right click on the pet shows; nil shows nothing.
	Menu func() []core.MenuItem
	// Context is what the clips' weights depend on besides the time, such as whether the user is coding or working; its Now is the clock's when zero. Nil reads whether an editor or a terminal is the app in front.
	Context func() Context
	// Rand chooses the clips; nil seeds one from the clock.
	Rand *rand.Rand
}

Options are how a host shows a pet.

type Pack

type Pack struct {
	// ID is the pet's directory.
	ID   string `json:"-"`
	Name string `json:"name"`
	// Group is the submenu the pet is listed in, empty for the top of the list.
	Group  string      `json:"group"`
	Width  core.Points `json:"width"`
	Height core.Points `json:"height"`
	// Body is where the pet's body is in its clips, in percent of the frame: only there does the pet take the pointer.
	Body struct {
		Left, Top, Width, Height float32
	} `json:"body"`
	EventSeconds int `json:"eventSeconds"`
	// Clips are the clips the pet plays by name.
	Clips struct {
		Greeting  string `json:"greeting"`
		Exit      string `json:"exit"`
		Drag      string `json:"drag"`
		Idle      string `json:"idle"`
		Daily     string `json:"daily"`
		DailyHour int    `json:"dailyHour"`
	} `json:"clips"`
	Source  string `json:"source"`
	License string `json:"license"`

	// Base is where the pet's mov and webm directories play from: an "asset:" path in the app's resources or a file path.
	Base   string  `json:"-"`
	Policy *Policy `json:"-"`
}

Pack is one pet: its manifest (pet.json) and its clip rules (animations.json, in Big Blue Fish's format).

func Load

func Load(fsys fs.FS, base string) ([]*Pack, error)

Load reads every pet in fsys, each a directory at its top holding pet.json and animations.json, in the order of their IDs; base is where fsys's directories play from, such as "asset:pets" for resources/pets. A pet that fails to load is left out, and the error names each one; the error is nil when every pet loads, and says so when none does.

func LoadDir

func LoadDir(dir string) ([]*Pack, error)

LoadDir reads every pet in the directory dir, as Load does, playing their clips from its files.

func (*Pack) Check

func (p *Pack) Check() error

Check reports a manifest the pet cannot run with.

type Pet

type Pet struct {
	// contains filtered or unexported fields
}

Pet is one pet playing in a scope.

func New

func New(cx *core.Scope, pack *Pack, opts Options) *Pet

New makes pack's pet in cx, which View shows and Start begins.

func (*Pet) Act

func (p *Pet) Act()

Act plays an event now, and the next one an event interval later.

func (*Pet) Leave

func (p *Pet) Leave(done func())

Leave plays the pet's exit clip and runs done as it ends, or eight seconds later should it never end; done runs once, and a second Leave does nothing. The host closes the pet's window or view in done.

func (*Pet) Pack

func (p *Pet) Pack() *Pack

Pack is the pet's pack.

func (*Pet) PlaceAtCorner

func (p *Pet) PlaceAtCorner()

PlaceAtCorner sizes the pet's window for the pet and puts it on the bottom right of the screen, above the Dock or the taskbar; without Options.Window it does nothing.

func (*Pet) Play

func (p *Pet) Play(id string) bool

Play plays the clip id names, which a host maps its own states to, such as a session running, waiting or done; the pet goes on by its rules once the clip ends. It reports false, playing nothing, for a clip the pack lacks or a pet leaving.

func (*Pet) Start

func (p *Pet) Start()

Start sets up the pet's window, with Options.Window, puts it in the corner and has the pet greet the user.

func (*Pet) View

func (p *Pet) View() core.Node

View is the pet: two players under a body that takes the pointer.

type Policy

type Policy struct {
	Rules []Rule
	// contains filtered or unexported fields
}

Policy chooses a pet's clips by pool and weight, a port of Big Blue Fish's CompanionAnimationPolicy.

func NewPolicy

func NewPolicy(data []byte) (*Policy, error)

NewPolicy reads a pet's animations.json.

func (*Policy) Choose

func (p *Policy) Choose(pool string, c Context, rnd *rand.Rand) (r Rule, ok bool)

Choose picks a clip of pool by weight; ok is false when none may play.

func (*Policy) Find

func (p *Policy) Find(id string) Rule

Find returns the rule named id, the zero Rule when there is none.

func (*Policy) Weight

func (p *Policy) Weight(r Rule, c Context) float64

Weight is how likely r is against the other clips of its pool at c, 0 when it may not play.

type Rule

type Rule struct {
	ID             string   `json:"Id"`
	File           string   `json:"File"`
	Pool           string   `json:"Pool"`
	Weight         float64  `json:"Weight"`
	NightOnly      bool     `json:"NightOnly"`
	SeasonOnly     string   `json:"SeasonOnly"`
	SummerWeight   *float64 `json:"SummerWeight"`
	WinterWeight   *float64 `json:"WinterWeight"`
	MorningWeight  *float64 `json:"MorningWeight"`
	Meal           string   `json:"Meal"`
	MealBoost      float64  `json:"MealBoost"`
	Festival       string   `json:"Festival"`
	RadiusDays     float64  `json:"RadiusDays"`
	FestivalMode   string   `json:"FestivalMode"`
	FestivalWeight float64  `json:"FestivalWeight"`
	WorkKind       string   `json:"WorkKind"`
	WorkWeight     float64  `json:"WorkWeight"`
	MoveKind       string   `json:"MoveKind"`
	HourParity     int      `json:"HourParity"`
}

Rule is one clip and when it plays, as Big Blue Fish's animations.json describes it.

Jump to

Keyboard shortcuts

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