package progression
import "github.com/nsgo-dev/game/pkg/progression"Overview
Package progression is experimental: its API and documented formats may change in a minor release. See the API stability policy. provides deterministic level-pack unlock rules.
Index
Constants
Functions
func Encode(p Pack) ([]byte, error)Encode validates p and writes its deterministic YAML representation.
Types
type Level struct {
ID string `yaml:"id"`
Stars int `yaml:"stars"`
UnlockAt int `yaml:"unlockAt,omitempty"`
}Level describes a level's star target and unlock threshold.
type Pack struct {
Version int `yaml:"version"`
Levels []Level `yaml:"levels"`
}Pack is a versioned collection of level unlock records.
func Parse(data []byte) (Pack, error)Parse decodes and validates one level-pack YAML document. It refuses unknown fields and a second YAML document, and returns a *loaderr.Error.
func (p Pack) Unlocked(id string, stars int) boolUnlocked reports whether the level id is available to a player who has collected stars stars in total: whether stars reaches its unlockAt. An unknown id is never unlocked.
func (p Pack) Validate() errorValidate reports a version other than FormatVersion, an empty pack, an empty, padded or repeated level ID, stars outside 1 to 3 and a negative unlockAt, as a *loaderr.Error naming the field.