GitHub快速開始

API 參考取自原始碼中的 Go 文件註解,以英文撰寫。

package progression

import "github.com/nsgo-dev/game/pkg/progression"

概覽

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.

索引

常數

const FormatVersion = 1

FormatVersion is the current level-pack YAML schema version.

函式

func Encode(p Pack) ([]byte, error)

Encode validates p and writes its deterministic YAML representation.

型別

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) bool

Unlocked 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() error

Validate 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.